@hairy/utils 1.26.0 → 1.27.0
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 +24 -7
- package/dist/index.d.ts +9 -2
- package/dist/index.global.js +24 -7
- package/dist/index.js +24 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3235,6 +3235,30 @@ function jsonTryParse(text) {
|
|
|
3235
3235
|
}
|
|
3236
3236
|
}
|
|
3237
3237
|
|
|
3238
|
+
// src/util/loop.ts
|
|
3239
|
+
function loop_return(fn) {
|
|
3240
|
+
async function next(ms) {
|
|
3241
|
+
await delay(ms);
|
|
3242
|
+
return fn(next);
|
|
3243
|
+
}
|
|
3244
|
+
return fn(next);
|
|
3245
|
+
}
|
|
3246
|
+
function loop(fn) {
|
|
3247
|
+
let looping = true;
|
|
3248
|
+
async function next(ms) {
|
|
3249
|
+
if (!looping)
|
|
3250
|
+
return;
|
|
3251
|
+
await delay(ms);
|
|
3252
|
+
return fn(next);
|
|
3253
|
+
}
|
|
3254
|
+
function cancel() {
|
|
3255
|
+
looping = false;
|
|
3256
|
+
}
|
|
3257
|
+
fn(next);
|
|
3258
|
+
return cancel;
|
|
3259
|
+
}
|
|
3260
|
+
loop.return = loop_return;
|
|
3261
|
+
|
|
3238
3262
|
// src/util/pipe-promise.ts
|
|
3239
3263
|
function pPipe(...fns) {
|
|
3240
3264
|
if (fns.length === 0)
|
|
@@ -3269,13 +3293,6 @@ function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
|
3269
3293
|
z[z0++] = x1;
|
|
3270
3294
|
return z;
|
|
3271
3295
|
}
|
|
3272
|
-
function loop(fn) {
|
|
3273
|
-
async function next(ms) {
|
|
3274
|
-
await delay(ms);
|
|
3275
|
-
return fn(next);
|
|
3276
|
-
}
|
|
3277
|
-
return fn(next);
|
|
3278
|
-
}
|
|
3279
3296
|
function riposte(...args) {
|
|
3280
3297
|
for (const [cond, value] of args) {
|
|
3281
3298
|
if (cond)
|
package/dist/index.d.ts
CHANGED
|
@@ -369,6 +369,14 @@ declare const isTruthy: <T>(value: T) => value is NonNullable<T>;
|
|
|
369
369
|
|
|
370
370
|
declare function jsonTryParse(text: string | undefined | null): any;
|
|
371
371
|
|
|
372
|
+
type Looper<T = void> = (next: (ms: number) => Promise<T>) => Promise<T>;
|
|
373
|
+
declare function loop_return<T = void>(fn: Looper<T>): Promise<T>;
|
|
374
|
+
declare function loop(fn: Looper<void>): Fn$1;
|
|
375
|
+
declare namespace loop {
|
|
376
|
+
var _a: typeof loop_return;
|
|
377
|
+
export { _a as return };
|
|
378
|
+
}
|
|
379
|
+
|
|
372
380
|
declare const noop: (...args: any) => any;
|
|
373
381
|
|
|
374
382
|
type UF<VT, RT> = (value: VT) => RT | PromiseLike<RT>;
|
|
@@ -452,9 +460,8 @@ declare function randomNumer(min: number, max: number): number;
|
|
|
452
460
|
declare function randomArray<T>(array: T[]): T;
|
|
453
461
|
|
|
454
462
|
declare function arange(x1: number, x2?: number, stp?: number, z?: number[], z0?: number): number[];
|
|
455
|
-
declare function loop<T = void>(fn: (next: (ms: number) => Promise<T>) => Promise<T>): Promise<T>;
|
|
456
463
|
declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
|
|
457
464
|
declare function unwrap<T extends object>(value: T | (() => T)): T;
|
|
458
465
|
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
459
466
|
|
|
460
|
-
export { type AnyFn, type ArgumentsType, type Arrayable, type Awaitable, BIG_INTS, BigNum, type BooleanLike, type Constructor, type DecimalOptions, type DeepKeyof, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type Key, type MergeInsertions, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type Option, type PromiseFn, type PromiseType, type StringObject, type SymbolObject, type Typeof, arange, average, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dotCase, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, noop, numerfix, objectToForm, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, randomArray, randomNumer, riposte, sentenceCase, snakeCase, trainCase, unwrap, whenever, zerofill, zeromove };
|
|
467
|
+
export { type AnyFn, type ArgumentsType, type Arrayable, type Awaitable, BIG_INTS, BigNum, type BooleanLike, type Constructor, type DecimalOptions, type DeepKeyof, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type Key, type Looper, type MergeInsertions, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type Option, type PromiseFn, type PromiseType, type StringObject, type SymbolObject, type Typeof, arange, average, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dotCase, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, noop, numerfix, objectToForm, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, randomArray, randomNumer, riposte, sentenceCase, snakeCase, trainCase, unwrap, whenever, zerofill, zeromove };
|
package/dist/index.global.js
CHANGED
|
@@ -4449,6 +4449,30 @@
|
|
|
4449
4449
|
}
|
|
4450
4450
|
}
|
|
4451
4451
|
|
|
4452
|
+
// src/util/loop.ts
|
|
4453
|
+
function loop_return(fn) {
|
|
4454
|
+
async function next(ms) {
|
|
4455
|
+
await delay(ms);
|
|
4456
|
+
return fn(next);
|
|
4457
|
+
}
|
|
4458
|
+
return fn(next);
|
|
4459
|
+
}
|
|
4460
|
+
function loop(fn) {
|
|
4461
|
+
let looping = true;
|
|
4462
|
+
async function next(ms) {
|
|
4463
|
+
if (!looping)
|
|
4464
|
+
return;
|
|
4465
|
+
await delay(ms);
|
|
4466
|
+
return fn(next);
|
|
4467
|
+
}
|
|
4468
|
+
function cancel() {
|
|
4469
|
+
looping = false;
|
|
4470
|
+
}
|
|
4471
|
+
fn(next);
|
|
4472
|
+
return cancel;
|
|
4473
|
+
}
|
|
4474
|
+
loop.return = loop_return;
|
|
4475
|
+
|
|
4452
4476
|
// src/util/pipe-promise.ts
|
|
4453
4477
|
function pPipe(...fns) {
|
|
4454
4478
|
if (fns.length === 0)
|
|
@@ -4483,13 +4507,6 @@
|
|
|
4483
4507
|
z[z0++] = x1;
|
|
4484
4508
|
return z;
|
|
4485
4509
|
}
|
|
4486
|
-
function loop(fn) {
|
|
4487
|
-
async function next(ms) {
|
|
4488
|
-
await delay(ms);
|
|
4489
|
-
return fn(next);
|
|
4490
|
-
}
|
|
4491
|
-
return fn(next);
|
|
4492
|
-
}
|
|
4493
4510
|
function riposte(...args) {
|
|
4494
4511
|
for (const [cond, value] of args) {
|
|
4495
4512
|
if (cond)
|
package/dist/index.js
CHANGED
|
@@ -3104,6 +3104,30 @@ function jsonTryParse(text) {
|
|
|
3104
3104
|
}
|
|
3105
3105
|
}
|
|
3106
3106
|
|
|
3107
|
+
// src/util/loop.ts
|
|
3108
|
+
function loop_return(fn) {
|
|
3109
|
+
async function next(ms) {
|
|
3110
|
+
await delay(ms);
|
|
3111
|
+
return fn(next);
|
|
3112
|
+
}
|
|
3113
|
+
return fn(next);
|
|
3114
|
+
}
|
|
3115
|
+
function loop(fn) {
|
|
3116
|
+
let looping = true;
|
|
3117
|
+
async function next(ms) {
|
|
3118
|
+
if (!looping)
|
|
3119
|
+
return;
|
|
3120
|
+
await delay(ms);
|
|
3121
|
+
return fn(next);
|
|
3122
|
+
}
|
|
3123
|
+
function cancel() {
|
|
3124
|
+
looping = false;
|
|
3125
|
+
}
|
|
3126
|
+
fn(next);
|
|
3127
|
+
return cancel;
|
|
3128
|
+
}
|
|
3129
|
+
loop.return = loop_return;
|
|
3130
|
+
|
|
3107
3131
|
// src/util/pipe-promise.ts
|
|
3108
3132
|
function pPipe(...fns) {
|
|
3109
3133
|
if (fns.length === 0)
|
|
@@ -3138,13 +3162,6 @@ function arange(x1, x2, stp = 1, z = [], z0 = z.length) {
|
|
|
3138
3162
|
z[z0++] = x1;
|
|
3139
3163
|
return z;
|
|
3140
3164
|
}
|
|
3141
|
-
function loop(fn) {
|
|
3142
|
-
async function next(ms) {
|
|
3143
|
-
await delay(ms);
|
|
3144
|
-
return fn(next);
|
|
3145
|
-
}
|
|
3146
|
-
return fn(next);
|
|
3147
|
-
}
|
|
3148
3165
|
function riposte(...args) {
|
|
3149
3166
|
for (const [cond, value] of args) {
|
|
3150
3167
|
if (cond)
|