@antfu/utils
Advanced tools
Comparing version 0.0.9 to 0.1.0
@@ -167,2 +167,28 @@ /** | ||
export { ArgumentsType, Arrayable, Awaitable, DeepMerge, ElementOf, Fn, MergeInsertions, Nullable, UnionToIntersection, assert, at, batchInvoke, clamp, deepMerge, flattenArrayable, invoke, isBoolean, isBrowser, isDef, isFunction, isKeyOf, isNumber, isObject, isString, isTruthy, isWindow, last, mergeArrayable, noNull, noop, notNullish, notUndefined, objectEntries, objectKeys, objectMap, partition, remove, slash, sum, timestamp, toArray, toString, uniq }; | ||
interface SingletonPromiseReturn<T> { | ||
(): Promise<T>; | ||
/** | ||
* Reset current staled promise. | ||
* await it to have proper shutdown. | ||
*/ | ||
reset: () => Promise<void>; | ||
} | ||
/** | ||
* Create singleton promise function | ||
* | ||
* @example | ||
* ``` | ||
* const promise = createSingletonPromise(async () => { ... }) | ||
* | ||
* await promise() | ||
* await promise() // all of them will be bind to a single promise instance | ||
* await promise() // and be resolved together | ||
* ``` | ||
*/ | ||
declare function createSingletonPromise<T>(fn: () => Promise<T>): SingletonPromiseReturn<T>; | ||
/** | ||
* Promised `setTimeout` | ||
*/ | ||
declare function sleep(ms: number, callback?: Fn<any>): Promise<void>; | ||
export { ArgumentsType, Arrayable, Awaitable, DeepMerge, ElementOf, Fn, MergeInsertions, Nullable, SingletonPromiseReturn, UnionToIntersection, assert, at, batchInvoke, clamp, createSingletonPromise, deepMerge, flattenArrayable, invoke, isBoolean, isBrowser, isDef, isFunction, isKeyOf, isNumber, isObject, isString, isTruthy, isWindow, last, mergeArrayable, noNull, noop, notNullish, notUndefined, objectEntries, objectKeys, objectMap, partition, remove, slash, sleep, sum, timestamp, toArray, toString, uniq }; |
@@ -137,2 +137,24 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/array.ts | ||
// src/promise.ts | ||
function createSingletonPromise(fn) { | ||
let _promise; | ||
function wrapper() { | ||
if (!_promise) | ||
_promise = fn(); | ||
return _promise; | ||
} | ||
wrapper.reset = async () => { | ||
const _prev = _promise; | ||
_promise = void 0; | ||
if (_prev) | ||
await _prev; | ||
}; | ||
return wrapper; | ||
} | ||
function sleep(ms, callback) { | ||
return new Promise((resolve) => setTimeout(async () => { | ||
await (callback == null ? void 0 : callback()); | ||
resolve(); | ||
}, ms)); | ||
} | ||
@@ -172,2 +194,5 @@ | ||
exports.assert = assert; exports.at = at; exports.batchInvoke = batchInvoke; exports.clamp = clamp; exports.deepMerge = deepMerge; exports.flattenArrayable = flattenArrayable; exports.invoke = invoke; exports.isBoolean = isBoolean; exports.isBrowser = isBrowser; exports.isDef = isDef; exports.isFunction = isFunction; exports.isKeyOf = isKeyOf; exports.isNumber = isNumber; exports.isObject = isObject; exports.isString = isString; exports.isTruthy = isTruthy; exports.isWindow = isWindow; exports.last = last; exports.mergeArrayable = mergeArrayable; exports.noNull = noNull; exports.noop = noop; exports.notNullish = notNullish; exports.notUndefined = notUndefined; exports.objectEntries = objectEntries; exports.objectKeys = objectKeys; exports.objectMap = objectMap; exports.partition = partition; exports.remove = remove; exports.slash = slash; exports.sum = sum; exports.timestamp = timestamp; exports.toArray = toArray; exports.toString = toString2; exports.uniq = uniq; | ||
exports.assert = assert; exports.at = at; exports.batchInvoke = batchInvoke; exports.clamp = clamp; exports.createSingletonPromise = createSingletonPromise; exports.deepMerge = deepMerge; exports.flattenArrayable = flattenArrayable; exports.invoke = invoke; exports.isBoolean = isBoolean; exports.isBrowser = isBrowser; exports.isDef = isDef; exports.isFunction = isFunction; exports.isKeyOf = isKeyOf; exports.isNumber = isNumber; exports.isObject = isObject; exports.isString = isString; exports.isTruthy = isTruthy; exports.isWindow = isWindow; exports.last = last; exports.mergeArrayable = mergeArrayable; exports.noNull = noNull; exports.noop = noop; exports.notNullish = notNullish; exports.notUndefined = notUndefined; exports.objectEntries = objectEntries; exports.objectKeys = objectKeys; exports.objectMap = objectMap; exports.partition = partition; exports.remove = remove; exports.slash = slash; exports.sleep = sleep; exports.sum = sum; exports.timestamp = timestamp; exports.toArray = toArray; exports.toString = toString2; exports.uniq = uniq; |
{ | ||
"name": "@antfu/utils", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"description": "Opinionated collection of common JavaScript / TypeScript utils by @antfu", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18201
523