Skip to main content
Search...

Utilities

Shared helpers for async operations, guards, fingerprinting, and event emission.

Shared helpers used across core and strategies. Keeping them centralized reduces duplication and ensures consistent behavior.

Contents

ModuleExportDescription
async.tssleep(ms)Promise-based delay
guards.tsisRecordRuntime type guard for plain objects
id.tsgenerateId()Generate unique local IDs
constants.tsVariousDefault limits and timeouts
fingerprint.tscomputeFingerprint, compareFingerprintCompute and compare file fingerprints for deduplication
emitter/createEmitterTyped event emitter implementation

Usage

Use these helpers instead of rolling custom versions inside strategies or UI code:

import { sleep, generateId, isRecord } from '@gentleduck/upload/core'
 
// Delay execution
await sleep(1000)
 
// Generate a unique ID
const id = generateId()
 
// Type-safe object check
if (isRecord(value)) {
  // value is Record<string, unknown>
}
import { sleep, generateId, isRecord } from '@gentleduck/upload/core'
 
// Delay execution
await sleep(1000)
 
// Generate a unique ID
const id = generateId()
 
// Type-safe object check
if (isRecord(value)) {
  // value is Record<string, unknown>
}