jsn-utils
v3.8.0
Published
Lightweight JavaScript/TypeScript utilities with async helpers, array and string operations
Maintainers
Readme
jsn-utils
3.8.0
List of utility functions
noop(): void- A no-operation function that does nothingignorePromise(promise: Promise<any>): void- Helps to suppress unhandled promise rejectionschunk<T>(array: T[], size: number): T[][]- Splits array into chunks of the specified sizechunkStr(str: string, chunkSize: number): string[]- Splits a string into chunks of a specified sizeisObjectEmpty(obj: object): boolean- Checks if the given object is empty (contains no own properties)wait(ms: number, signal?: AbortSignal): Promise<void>- Returns a promise that resolves after the specified amount of time in milliseconds or when signal is abortedcreatePromisesCache- deprecated; use createInFlightDeduper insteadcreateInFlightDeduper- Creates a deduplicator for in-flight promises or sync functions. Prevents duplicate executions for the same key while a promise is pending. Clears the entry after settlementresultify- Executes a function and returns its result as a tuple[value, error]. Works with both sync and async functions. Never throws.
List of utility classes
Monitorclass - provides simple methods to monitor execution time of functions:- static
measureFunctionTime(fn: Function): number | Promise<number> - static
autoStart(label: string): Monitor- Creates a newMonitorinstance and calls.start(label)on it start(label: string)mark(label: string, description?: string)stop(label: string): MonitorResult
- static
Types
MonitorMark
- ts:
number- mark timestamp - diff:
number- difference in milliseconds between start timestamp and mark timestamp - description?:
string- an optional description of a mark
MonitorResult
- startTs:
number- start timestamp - stopTs:
number- stop timestamp - totalTime:
number- difference betweenstopTsandstartTs - marks:
MonitorMark[]- array of marks (if any)
