@jsnw/common-utils 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +13 -1
- package/dist/index.d.mts +13 -1
- package/dist/index.mjs +18 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,23 @@ function chunkStr(str, chunkSize) {
|
|
|
46
46
|
return Array.from({ length: Math.ceil(str.length / chunkSize) }, (_, i) => str.slice(i * chunkSize, i * chunkSize + chunkSize));
|
|
47
47
|
}
|
|
48
48
|
//#endregion
|
|
49
|
+
//#region src/defer.ts
|
|
50
|
+
/**
|
|
51
|
+
* @template T
|
|
52
|
+
* @returns {DeferredPromise<T>}
|
|
53
|
+
*/
|
|
54
|
+
const defer = () => {
|
|
55
|
+
let resolve, reject;
|
|
56
|
+
return {
|
|
57
|
+
promise: new Promise((res, rej) => {
|
|
58
|
+
resolve = res;
|
|
59
|
+
reject = rej;
|
|
60
|
+
}),
|
|
61
|
+
resolve,
|
|
62
|
+
reject
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
49
66
|
//#region src/wait.ts
|
|
50
67
|
/**
|
|
51
68
|
* Waits asynchronously for the specified amount of milliseconds before resolving.
|
|
@@ -279,6 +296,7 @@ exports.PerfmonError = PerfmonError;
|
|
|
279
296
|
exports.chunk = chunk;
|
|
280
297
|
exports.chunkStr = chunkStr;
|
|
281
298
|
exports.createInFlightDeduper = createInFlightDeduper;
|
|
299
|
+
exports.defer = defer;
|
|
282
300
|
exports.ignorePromise = ignorePromise;
|
|
283
301
|
exports.isAbortError = isAbortError;
|
|
284
302
|
exports.isObjectEmpty = isObjectEmpty;
|
package/dist/index.d.cts
CHANGED
|
@@ -37,6 +37,18 @@ declare const chunk: <T extends any>(arr: T[], chunk_size: number) => T[][];
|
|
|
37
37
|
*/
|
|
38
38
|
declare function chunkStr(str: string, chunkSize: number): string[];
|
|
39
39
|
//#endregion
|
|
40
|
+
//#region src/defer.d.ts
|
|
41
|
+
type DeferredPromise<T> = {
|
|
42
|
+
promise: Promise<T>;
|
|
43
|
+
resolve: (value: T) => void;
|
|
44
|
+
reject: (reason?: any) => void;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* @template T
|
|
48
|
+
* @returns {DeferredPromise<T>}
|
|
49
|
+
*/
|
|
50
|
+
declare const defer: <T>() => DeferredPromise<T>;
|
|
51
|
+
//#endregion
|
|
40
52
|
//#region src/wait.d.ts
|
|
41
53
|
/**
|
|
42
54
|
* Waits asynchronously for the specified amount of milliseconds before resolving.
|
|
@@ -169,4 +181,4 @@ declare const withPerfmon: <F extends AnyFn>(fn: F, ...args: Parameters<F>) => W
|
|
|
169
181
|
*/
|
|
170
182
|
declare const promisify: <F extends (...args: any[]) => any>(fn: F, ...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>;
|
|
171
183
|
//#endregion
|
|
172
|
-
export { ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, createInFlightDeduper, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
|
184
|
+
export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
package/dist/index.d.mts
CHANGED
|
@@ -37,6 +37,18 @@ declare const chunk: <T extends any>(arr: T[], chunk_size: number) => T[][];
|
|
|
37
37
|
*/
|
|
38
38
|
declare function chunkStr(str: string, chunkSize: number): string[];
|
|
39
39
|
//#endregion
|
|
40
|
+
//#region src/defer.d.ts
|
|
41
|
+
type DeferredPromise<T> = {
|
|
42
|
+
promise: Promise<T>;
|
|
43
|
+
resolve: (value: T) => void;
|
|
44
|
+
reject: (reason?: any) => void;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* @template T
|
|
48
|
+
* @returns {DeferredPromise<T>}
|
|
49
|
+
*/
|
|
50
|
+
declare const defer: <T>() => DeferredPromise<T>;
|
|
51
|
+
//#endregion
|
|
40
52
|
//#region src/wait.d.ts
|
|
41
53
|
/**
|
|
42
54
|
* Waits asynchronously for the specified amount of milliseconds before resolving.
|
|
@@ -169,4 +181,4 @@ declare const withPerfmon: <F extends AnyFn>(fn: F, ...args: Parameters<F>) => W
|
|
|
169
181
|
*/
|
|
170
182
|
declare const promisify: <F extends (...args: any[]) => any>(fn: F, ...args: Parameters<F>) => Promise<Awaited<ReturnType<F>>>;
|
|
171
183
|
//#endregion
|
|
172
|
-
export { ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, createInFlightDeduper, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
|
184
|
+
export { DeferredPromise, ErrorResult, InFlightDeduper, Monitor, MonitorMark, MonitorResult, PerfmonError, PerfmonResult, WithPerfmonReturn, chunk, chunkStr, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
package/dist/index.mjs
CHANGED
|
@@ -45,6 +45,23 @@ function chunkStr(str, chunkSize) {
|
|
|
45
45
|
return Array.from({ length: Math.ceil(str.length / chunkSize) }, (_, i) => str.slice(i * chunkSize, i * chunkSize + chunkSize));
|
|
46
46
|
}
|
|
47
47
|
//#endregion
|
|
48
|
+
//#region src/defer.ts
|
|
49
|
+
/**
|
|
50
|
+
* @template T
|
|
51
|
+
* @returns {DeferredPromise<T>}
|
|
52
|
+
*/
|
|
53
|
+
const defer = () => {
|
|
54
|
+
let resolve, reject;
|
|
55
|
+
return {
|
|
56
|
+
promise: new Promise((res, rej) => {
|
|
57
|
+
resolve = res;
|
|
58
|
+
reject = rej;
|
|
59
|
+
}),
|
|
60
|
+
resolve,
|
|
61
|
+
reject
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
48
65
|
//#region src/wait.ts
|
|
49
66
|
/**
|
|
50
67
|
* Waits asynchronously for the specified amount of milliseconds before resolving.
|
|
@@ -273,4 +290,4 @@ const promisify = (fn, ...args) => {
|
|
|
273
290
|
});
|
|
274
291
|
};
|
|
275
292
|
//#endregion
|
|
276
|
-
export { Monitor, PerfmonError, chunk, chunkStr, createInFlightDeduper, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|
|
293
|
+
export { Monitor, PerfmonError, chunk, chunkStr, createInFlightDeduper, defer, ignorePromise, isAbortError, isObjectEmpty, noop, promisify, resultify, trySettlePromises, wait, withPerfmon };
|