@hairy/utils 1.23.0 → 1.25.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 +31 -11
- package/dist/index.d.ts +142 -20
- package/dist/index.global.js +29 -9
- package/dist/index.js +30 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -86,6 +86,7 @@ __export(index_exports, {
|
|
|
86
86
|
isPhantomJS: () => isPhantomJS,
|
|
87
87
|
isPlainObject: () => isPlainObject_default,
|
|
88
88
|
isString: () => isString_default,
|
|
89
|
+
isTruthy: () => isTruthy,
|
|
89
90
|
isTypeof: () => isTypeof,
|
|
90
91
|
isUndefined: () => isUndefined_default,
|
|
91
92
|
isWeex: () => isWeex,
|
|
@@ -103,7 +104,6 @@ __export(index_exports, {
|
|
|
103
104
|
noop: () => noop2,
|
|
104
105
|
numerfix: () => numerfix,
|
|
105
106
|
objectToForm: () => objectToForm,
|
|
106
|
-
pPipe: () => pPipe,
|
|
107
107
|
parseNumeric: () => parseNumeric,
|
|
108
108
|
pascalCase: () => pascalCase,
|
|
109
109
|
pascalSnakeCase: () => pascalSnakeCase,
|
|
@@ -3147,8 +3147,24 @@ function isTypeof(target, type) {
|
|
|
3147
3147
|
return getTypeof(target) === type;
|
|
3148
3148
|
}
|
|
3149
3149
|
|
|
3150
|
+
// src/util/compose-promise.ts
|
|
3151
|
+
function pCompose(...fns) {
|
|
3152
|
+
if (fns.length === 0)
|
|
3153
|
+
throw new Error("Expected at least one argument");
|
|
3154
|
+
return async (input) => {
|
|
3155
|
+
let value = input;
|
|
3156
|
+
for (const fn of fns.reverse())
|
|
3157
|
+
value = await fn(value);
|
|
3158
|
+
return value;
|
|
3159
|
+
};
|
|
3160
|
+
}
|
|
3161
|
+
|
|
3150
3162
|
// src/util/compose.ts
|
|
3151
|
-
|
|
3163
|
+
function compose(...fns) {
|
|
3164
|
+
const fn = fns.pop();
|
|
3165
|
+
return fns.reduceRight((v, f) => f(v), fn);
|
|
3166
|
+
}
|
|
3167
|
+
compose.promise = pCompose;
|
|
3152
3168
|
|
|
3153
3169
|
// src/util/converts.ts
|
|
3154
3170
|
function formToObject(formData) {
|
|
@@ -3208,6 +3224,7 @@ var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
|
3208
3224
|
var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
|
|
3209
3225
|
var isFormData = (value) => isObject_default(value) && isBrowser() && value instanceof FormData;
|
|
3210
3226
|
var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
3227
|
+
var isTruthy = (value) => Boolean(value);
|
|
3211
3228
|
|
|
3212
3229
|
// src/util/json.ts
|
|
3213
3230
|
function jsonTryParse(text) {
|
|
@@ -3218,20 +3235,23 @@ function jsonTryParse(text) {
|
|
|
3218
3235
|
}
|
|
3219
3236
|
}
|
|
3220
3237
|
|
|
3221
|
-
// src/util/
|
|
3222
|
-
function pPipe(...
|
|
3223
|
-
if (
|
|
3238
|
+
// src/util/pipe-promise.ts
|
|
3239
|
+
function pPipe(...fns) {
|
|
3240
|
+
if (fns.length === 0)
|
|
3224
3241
|
throw new Error("Expected at least one argument");
|
|
3225
3242
|
return async (input) => {
|
|
3226
|
-
let
|
|
3227
|
-
for (const
|
|
3228
|
-
|
|
3229
|
-
return
|
|
3243
|
+
let value = input;
|
|
3244
|
+
for (const fn of fns)
|
|
3245
|
+
value = await fn(value);
|
|
3246
|
+
return value;
|
|
3230
3247
|
};
|
|
3231
3248
|
}
|
|
3232
3249
|
|
|
3233
3250
|
// src/util/pipe.ts
|
|
3234
|
-
|
|
3251
|
+
function pipe(...fns) {
|
|
3252
|
+
return fns.reduce((v, f) => f(v));
|
|
3253
|
+
}
|
|
3254
|
+
pipe.promise = pPipe;
|
|
3235
3255
|
|
|
3236
3256
|
// src/util/random.ts
|
|
3237
3257
|
function randomNumer(min, max) {
|
|
@@ -3327,6 +3347,7 @@ function whenever(value, callback) {
|
|
|
3327
3347
|
isPhantomJS,
|
|
3328
3348
|
isPlainObject,
|
|
3329
3349
|
isString,
|
|
3350
|
+
isTruthy,
|
|
3330
3351
|
isTypeof,
|
|
3331
3352
|
isUndefined,
|
|
3332
3353
|
isWeex,
|
|
@@ -3344,7 +3365,6 @@ function whenever(value, callback) {
|
|
|
3344
3365
|
noop,
|
|
3345
3366
|
numerfix,
|
|
3346
3367
|
objectToForm,
|
|
3347
|
-
pPipe,
|
|
3348
3368
|
parseNumeric,
|
|
3349
3369
|
pascalCase,
|
|
3350
3370
|
pascalSnakeCase,
|
package/dist/index.d.ts
CHANGED
|
@@ -118,7 +118,7 @@ type Awaitable<T> = T | PromiseLike<T>;
|
|
|
118
118
|
type Arrayable<T> = T | T[];
|
|
119
119
|
type Nullable<T> = T | null | undefined;
|
|
120
120
|
type ElementOf<T> = T extends (infer E)[] ? E : never;
|
|
121
|
-
type Fn<T = void> = () => T;
|
|
121
|
+
type Fn$1<T = void> = () => T;
|
|
122
122
|
type AnyFn = (...args: any[]) => any;
|
|
123
123
|
type PromiseFn = (...args: any[]) => Promise<any>;
|
|
124
124
|
type Constructor<T = void> = new (...args: any[]) => T;
|
|
@@ -253,7 +253,84 @@ declare function getTypeof(target: any): Typeof;
|
|
|
253
253
|
*/
|
|
254
254
|
declare function isTypeof(target: any, type: Typeof): boolean;
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
type UF$1<VT, RT> = (value: VT) => RT | PromiseLike<RT>;
|
|
257
|
+
type Composed<VT, RT> = (value?: VT) => Promise<RT>;
|
|
258
|
+
/**
|
|
259
|
+
* Compose promise-returning & async fns into a reusable pipeline.
|
|
260
|
+
*
|
|
261
|
+
* @param ...fns - Iterated over sequentially when returned `function` is called.
|
|
262
|
+
* @returns The `fns` are applied from right to left.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```
|
|
266
|
+
* const addUnicorn = async string => `${string} Unicorn`;
|
|
267
|
+
* const addRainbow = async string => `${string} Rainbow`;
|
|
268
|
+
*
|
|
269
|
+
* const pipeline = pCompose(addRainbow, addUnicorn);
|
|
270
|
+
*
|
|
271
|
+
* console.log(await pipeline('❤️'));
|
|
272
|
+
* //=> '❤️ Unicorn Rainbow'
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
declare function pCompose<VT, RT>(f1: UF$1<VT, RT>): Composed<VT, RT>;
|
|
276
|
+
declare function pCompose<VT, R1, RT>(f1: UF$1<R1, RT>, f2: UF$1<VT, R1>): Composed<VT, RT>;
|
|
277
|
+
declare function pCompose<VT, R1, R2, RT>(f1: UF$1<R2, RT>, f2: UF$1<R1, R2>, f3: UF$1<VT, R1>): Composed<VT, RT>;
|
|
278
|
+
declare function pCompose<VT, R1, R2, R3, RT>(f1: UF$1<R3, RT>, f2: UF$1<R2, R3>, f3: UF$1<R1, R2>, f4: UF$1<VT, R1>): Composed<VT, RT>;
|
|
279
|
+
declare function pCompose<VT, R1, R2, R3, R4, RT>(f1: UF$1<R4, RT>, f2: UF$1<R3, R4>, f3: UF$1<R2, R3>, f4: UF$1<R1, R2>, f5: UF$1<VT, R1>): Composed<VT, RT>;
|
|
280
|
+
declare function pCompose<VT, R1, R2, R3, R4, R5, RT>(f1: UF$1<R5, RT>, f2: UF$1<R4, R5>, f3: UF$1<R3, R4>, f4: UF$1<R2, R3>, f5: UF$1<R1, R2>, f6: UF$1<VT, R1>): Composed<VT, RT>;
|
|
281
|
+
declare function pCompose<VT, R1, R2, R3, R4, R5, R6, RT>(f1: UF$1<R6, RT>, f2: UF$1<R5, R6>, f3: UF$1<R4, R5>, f4: UF$1<R3, R4>, f5: UF$1<R2, R3>, f6: UF$1<R1, R2>, f7: UF$1<VT, R1>): Composed<VT, RT>;
|
|
282
|
+
declare function pCompose<VT, R1, R2, R3, R4, R5, R6, R7, RT>(f1: UF$1<R7, RT>, f2: UF$1<R6, R7>, f3: UF$1<R5, R6>, f4: UF$1<R4, R5>, f5: UF$1<R3, R4>, f6: UF$1<R2, R3>, f7: UF$1<R1, R2>, f8: UF$1<VT, R1>): Composed<VT, RT>;
|
|
283
|
+
declare function pCompose<VT, R1, R2, R3, R4, R5, R6, R7, R8, RT>(f1: UF$1<R8, RT>, f2: UF$1<R7, R8>, f3: UF$1<R6, R7>, f4: UF$1<R5, R6>, f5: UF$1<R4, R5>, f6: UF$1<R3, R4>, f7: UF$1<R2, R3>, f8: UF$1<R1, R2>, f9: UF$1<VT, R1>): Composed<VT, RT>;
|
|
284
|
+
|
|
285
|
+
type Fn<V, R> = (x: V) => R;
|
|
286
|
+
type Q<T, V> = (...args: T) => V;
|
|
287
|
+
/**
|
|
288
|
+
* Performs function composition in RTL (Right To Left) direction.
|
|
289
|
+
*
|
|
290
|
+
* Our `compose` and `compose.promise` implementation supports N arguments. But you can use only 10 in
|
|
291
|
+
* TypeScript, because it doesn't support **Variadic Kinds** and we explicitly
|
|
292
|
+
* have to define the type of all the possible usages as method overloads.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* const normalizeWhiteSpaces = text => name.replace(/\s+/g, ' ').trim();
|
|
296
|
+
*
|
|
297
|
+
* const getInitials = compose(
|
|
298
|
+
* initials => initials.join('').toLocaleUpperCase(),
|
|
299
|
+
* name => name.split(' ').map(name => name.charAt(0)),
|
|
300
|
+
* normalizeWhiteSpaces
|
|
301
|
+
* );
|
|
302
|
+
*
|
|
303
|
+
* getInitials('Vitor Luiz Cavalcanti');
|
|
304
|
+
* //=> "VLC"
|
|
305
|
+
*
|
|
306
|
+
* @param fn - An arity 1 function, except the last one which can have arity N.
|
|
307
|
+
* @param fns - Functions of arity 1. Each one's result is next's argument.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
*
|
|
311
|
+
* const addUnicorn = async string => `${string} Unicorn`;
|
|
312
|
+
* const addRainbow = async string => `${string} Rainbow`;
|
|
313
|
+
*
|
|
314
|
+
* const pipeline = compose.promise(addRainbow, addUnicorn);
|
|
315
|
+
*
|
|
316
|
+
* console.log(await pipeline('❤️'));
|
|
317
|
+
* //=> '❤️ Unicorn Rainbow'
|
|
318
|
+
* @param ...fns - Iterated over sequentially when returned `function` is called.
|
|
319
|
+
* @returns The `fns` functions are applied from right to left.
|
|
320
|
+
*/
|
|
321
|
+
declare function compose<T, V0, V1>(fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V1>;
|
|
322
|
+
declare function compose<T, V0, V1, V2>(fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V2>;
|
|
323
|
+
declare function compose<T, V0, V1, V2, V3>(fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V3>;
|
|
324
|
+
declare function compose<T, V0, V1, V2, V3, V4>(fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V4>;
|
|
325
|
+
declare function compose<T, V0, V1, V2, V3, V4, V5>(fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V5>;
|
|
326
|
+
declare function compose<T, V0, V1, V2, V3, V4, V5, V6>(fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V6>;
|
|
327
|
+
declare function compose<T, V0, V1, V2, V3, V4, V5, V6, V7>(fn7: Fn<V6, V7>, fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V7>;
|
|
328
|
+
declare function compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8>(fn8: Fn<V7, V8>, fn7: Fn<V6, V7>, fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V8>;
|
|
329
|
+
declare function compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9>(fn9: Fn<V8, V9>, fn8: Fn<V7, V8>, fn7: Fn<V6, V7>, fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V9>;
|
|
330
|
+
declare function compose<T, V0, V1, V2, V3, V4, V5, V6, V7, V8, V9, V10>(fn10: Fn<V9, V10>, fn9: Fn<V8, V9>, fn8: Fn<V7, V8>, fn7: Fn<V6, V7>, fn6: Fn<V5, V6>, fn5: Fn<V4, V5>, fn4: Fn<V3, V4>, fn3: Fn<V2, V3>, fn2: Fn<V1, V2>, fn1: Fn<V0, V1>, fn0: Q<T, V0>): Q<T, V10>;
|
|
331
|
+
declare namespace compose {
|
|
332
|
+
var promise: typeof pCompose;
|
|
333
|
+
}
|
|
257
334
|
|
|
258
335
|
/**
|
|
259
336
|
* formData to object
|
|
@@ -288,43 +365,88 @@ declare const isFF: () => false | RegExpMatchArray | null;
|
|
|
288
365
|
declare const isMobile: () => boolean;
|
|
289
366
|
declare const isFormData: (value: any) => value is FormData;
|
|
290
367
|
declare const isWindow: (value: any) => value is Window;
|
|
368
|
+
declare const isTruthy: <T>(value: T) => value is NonNullable<T>;
|
|
291
369
|
|
|
292
370
|
declare function jsonTryParse(text: string | undefined | null): any;
|
|
293
371
|
|
|
294
372
|
declare const noop: (...args: any) => any;
|
|
295
373
|
|
|
296
|
-
type
|
|
297
|
-
type Pipeline<
|
|
374
|
+
type UF<VT, RT> = (value: VT) => RT | PromiseLike<RT>;
|
|
375
|
+
type Pipeline<VT, RT> = (value?: VT) => Promise<RT>;
|
|
298
376
|
/**
|
|
299
|
-
Compose promise-returning & async
|
|
377
|
+
Compose promise-returning & async fns into a reusable pipeline.
|
|
300
378
|
|
|
301
379
|
@param ...input - Iterated over sequentially when returned `function` is called.
|
|
302
|
-
@returns The `input`
|
|
380
|
+
@returns The `input` fns are applied from left to right.
|
|
303
381
|
|
|
304
382
|
@example
|
|
305
383
|
```
|
|
306
|
-
import { pPipe } from '@hairy/utils';
|
|
307
|
-
|
|
308
384
|
const addUnicorn = async string => `${string} Unicorn`;
|
|
309
385
|
const addRainbow = async string => `${string} Rainbow`;
|
|
310
386
|
|
|
311
|
-
const pipeline =
|
|
387
|
+
const pipeline = pipe.promise(addUnicorn, addRainbow);
|
|
312
388
|
|
|
313
389
|
console.log(await pipeline('❤️'));
|
|
314
390
|
//=> '❤️ Unicorn Rainbow'
|
|
315
391
|
```
|
|
316
392
|
*/
|
|
317
|
-
declare function pPipe<
|
|
318
|
-
declare function pPipe<
|
|
319
|
-
declare function pPipe<
|
|
320
|
-
declare function pPipe<
|
|
321
|
-
declare function pPipe<
|
|
322
|
-
declare function pPipe<
|
|
323
|
-
declare function pPipe<
|
|
324
|
-
declare function pPipe<
|
|
325
|
-
declare function pPipe<
|
|
393
|
+
declare function pPipe<VT, RT>(f1: UF<VT, RT>): Pipeline<VT, RT>;
|
|
394
|
+
declare function pPipe<VT, R1, RT>(f1: UF<VT, R1>, f2: UF<R1, RT>): Pipeline<VT, RT>;
|
|
395
|
+
declare function pPipe<VT, R1, R2, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, RT>): Pipeline<VT, RT>;
|
|
396
|
+
declare function pPipe<VT, R1, R2, R3, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, RT>): Pipeline<VT, RT>;
|
|
397
|
+
declare function pPipe<VT, R1, R2, R3, R4, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, RT>): Pipeline<VT, RT>;
|
|
398
|
+
declare function pPipe<VT, R1, R2, R3, R4, R5, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, R5>, f6: UF<R5, RT>): Pipeline<VT, RT>;
|
|
399
|
+
declare function pPipe<VT, R1, R2, R3, R4, R5, R6, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, R5>, f6: UF<R5, R6>, f7: UF<R6, RT>): Pipeline<VT, RT>;
|
|
400
|
+
declare function pPipe<VT, R1, R2, R3, R4, R5, R6, R7, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, R5>, f6: UF<R5, R6>, f7: UF<R6, R7>, f8: UF<R7, RT>): Pipeline<VT, RT>;
|
|
401
|
+
declare function pPipe<VT, R1, R2, R3, R4, R5, R6, R7, R8, RT>(f1: UF<VT, R1>, f2: UF<R1, R2>, f3: UF<R2, R3>, f4: UF<R3, R4>, f5: UF<R4, R5>, f6: UF<R5, R6>, f7: UF<R6, R7>, f8: UF<R7, R8>, f9: UF<R8, RT>): Pipeline<VT, RT>;
|
|
326
402
|
|
|
327
|
-
|
|
403
|
+
/**
|
|
404
|
+
* Performs function composition in LTR (Left To Right) direction.
|
|
405
|
+
*
|
|
406
|
+
* Our `pipe` and `pipe.promise` implementation supports N arguments. But you can use only 10 in
|
|
407
|
+
* TypeScript, because it doesn't support **Variadic Kinds** and we explicitly
|
|
408
|
+
* have to define the type of all the possible usages as method overloads.
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* const normalizeWhiteSpaces = text => name.replace(/\s+/g, ' ').trim();
|
|
412
|
+
*
|
|
413
|
+
* const getInitials = pipe(
|
|
414
|
+
* normalizeWhiteSpaces,
|
|
415
|
+
* name => name.split(' ').map(name => name.charAt(0)),
|
|
416
|
+
* initials => initials.join('').toLocaleUpperCase()
|
|
417
|
+
* );
|
|
418
|
+
*
|
|
419
|
+
* getInitials('Vitor Luiz Cavalcanti');
|
|
420
|
+
* //=> "VLC"
|
|
421
|
+
*
|
|
422
|
+
* @param fn - An arity N function. Its result is the argument of next one.
|
|
423
|
+
* @param fns - Functions of arity 1. Each one's result is next's argument.
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
*
|
|
427
|
+
* const addUnicorn = async string => `${string} Unicorn`;
|
|
428
|
+
* const addRainbow = async string => `${string} Rainbow`;
|
|
429
|
+
*
|
|
430
|
+
* const pipeline = pipe.promise(addUnicorn, addRainbow);
|
|
431
|
+
*
|
|
432
|
+
* console.log(await pipeline('❤️'));
|
|
433
|
+
* //=> '❤️ Unicorn Rainbow'
|
|
434
|
+
* @param ...input - Iterated over sequentially when returned `function` is called.
|
|
435
|
+
* @returns The `input` functions are applied from left to right.
|
|
436
|
+
*/
|
|
437
|
+
declare function pipe<Args extends unknown[], T0>(...fns: [(...xs: Args) => T0]): (...xs: Args) => T0;
|
|
438
|
+
declare function pipe<Args extends unknown[], T0, T1>(...fns: [(...xs: Args) => T0, (x: T0) => T1]): (...xs: Args) => T1;
|
|
439
|
+
declare function pipe<Args extends unknown[], T0, T1, T2>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2]): (...xs: Args) => T2;
|
|
440
|
+
declare function pipe<Args extends unknown[], T0, T1, T2, T3>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3]): (...xs: Args) => T3;
|
|
441
|
+
declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4]): (...xs: Args) => T4;
|
|
442
|
+
declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5]): (...xs: Args) => T5;
|
|
443
|
+
declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5, T6>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5, (x: T5) => T6]): (...xs: Args) => T6;
|
|
444
|
+
declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5, T6, T7>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5, (x: T5) => T6, (x: T6) => T7]): (...xs: Args) => T7;
|
|
445
|
+
declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5, T6, T7, T8>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5, (x: T5) => T6, (x: T6) => T7, (x: T7) => T8]): (...xs: Args) => T8;
|
|
446
|
+
declare function pipe<Args extends unknown[], T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(...fns: [(...xs: Args) => T0, (x: T0) => T1, (x: T1) => T2, (x: T2) => T3, (x: T3) => T4, (x: T4) => T5, (x: T5) => T6, (x: T6) => T7, (x: T7) => T8, (x: T8) => T9]): (...xs: Args) => T9;
|
|
447
|
+
declare namespace pipe {
|
|
448
|
+
var promise: typeof pPipe;
|
|
449
|
+
}
|
|
328
450
|
|
|
329
451
|
declare function randomNumer(min: number, max: number): number;
|
|
330
452
|
declare function randomArray<T>(array: T[]): T;
|
|
@@ -335,4 +457,4 @@ declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
|
|
|
335
457
|
declare function unwrap<T extends object>(value: T | (() => T)): T;
|
|
336
458
|
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
337
459
|
|
|
338
|
-
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, type FormatGroupOptions, type FormatNumericOptions, type Key, type MergeInsertions, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type Option, type
|
|
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 };
|
package/dist/index.global.js
CHANGED
|
@@ -4361,8 +4361,24 @@
|
|
|
4361
4361
|
return getTypeof(target) === type;
|
|
4362
4362
|
}
|
|
4363
4363
|
|
|
4364
|
+
// src/util/compose-promise.ts
|
|
4365
|
+
function pCompose(...fns) {
|
|
4366
|
+
if (fns.length === 0)
|
|
4367
|
+
throw new Error("Expected at least one argument");
|
|
4368
|
+
return async (input) => {
|
|
4369
|
+
let value = input;
|
|
4370
|
+
for (const fn of fns.reverse())
|
|
4371
|
+
value = await fn(value);
|
|
4372
|
+
return value;
|
|
4373
|
+
};
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4364
4376
|
// src/util/compose.ts
|
|
4365
|
-
|
|
4377
|
+
function compose(...fns) {
|
|
4378
|
+
const fn = fns.pop();
|
|
4379
|
+
return fns.reduceRight((v, f) => f(v), fn);
|
|
4380
|
+
}
|
|
4381
|
+
compose.promise = pCompose;
|
|
4366
4382
|
|
|
4367
4383
|
// src/util/converts.ts
|
|
4368
4384
|
function formToObject(formData) {
|
|
@@ -4422,6 +4438,7 @@
|
|
|
4422
4438
|
var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
|
|
4423
4439
|
var isFormData = (value) => isObject_default(value) && isBrowser() && value instanceof FormData;
|
|
4424
4440
|
var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
4441
|
+
var isTruthy = (value) => Boolean(value);
|
|
4425
4442
|
|
|
4426
4443
|
// src/util/json.ts
|
|
4427
4444
|
function jsonTryParse(text) {
|
|
@@ -4432,20 +4449,23 @@
|
|
|
4432
4449
|
}
|
|
4433
4450
|
}
|
|
4434
4451
|
|
|
4435
|
-
// src/util/
|
|
4436
|
-
function pPipe(...
|
|
4437
|
-
if (
|
|
4452
|
+
// src/util/pipe-promise.ts
|
|
4453
|
+
function pPipe(...fns) {
|
|
4454
|
+
if (fns.length === 0)
|
|
4438
4455
|
throw new Error("Expected at least one argument");
|
|
4439
4456
|
return async (input) => {
|
|
4440
|
-
let
|
|
4441
|
-
for (const
|
|
4442
|
-
|
|
4443
|
-
return
|
|
4457
|
+
let value = input;
|
|
4458
|
+
for (const fn of fns)
|
|
4459
|
+
value = await fn(value);
|
|
4460
|
+
return value;
|
|
4444
4461
|
};
|
|
4445
4462
|
}
|
|
4446
4463
|
|
|
4447
4464
|
// src/util/pipe.ts
|
|
4448
|
-
|
|
4465
|
+
function pipe(...fns) {
|
|
4466
|
+
return fns.reduce((v, f) => f(v));
|
|
4467
|
+
}
|
|
4468
|
+
pipe.promise = pPipe;
|
|
4449
4469
|
|
|
4450
4470
|
// src/util/random.ts
|
|
4451
4471
|
function randomNumer(min, max) {
|
package/dist/index.js
CHANGED
|
@@ -3016,8 +3016,24 @@ function isTypeof(target, type) {
|
|
|
3016
3016
|
return getTypeof(target) === type;
|
|
3017
3017
|
}
|
|
3018
3018
|
|
|
3019
|
+
// src/util/compose-promise.ts
|
|
3020
|
+
function pCompose(...fns) {
|
|
3021
|
+
if (fns.length === 0)
|
|
3022
|
+
throw new Error("Expected at least one argument");
|
|
3023
|
+
return async (input) => {
|
|
3024
|
+
let value = input;
|
|
3025
|
+
for (const fn of fns.reverse())
|
|
3026
|
+
value = await fn(value);
|
|
3027
|
+
return value;
|
|
3028
|
+
};
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3019
3031
|
// src/util/compose.ts
|
|
3020
|
-
|
|
3032
|
+
function compose(...fns) {
|
|
3033
|
+
const fn = fns.pop();
|
|
3034
|
+
return fns.reduceRight((v, f) => f(v), fn);
|
|
3035
|
+
}
|
|
3036
|
+
compose.promise = pCompose;
|
|
3021
3037
|
|
|
3022
3038
|
// src/util/converts.ts
|
|
3023
3039
|
function formToObject(formData) {
|
|
@@ -3077,6 +3093,7 @@ var isFF = () => typeof UA() === "string" && UA().match(/firefox\/(\d+)/);
|
|
|
3077
3093
|
var isMobile = () => isBrowser() && navigator.userAgent.toLowerCase().includes("mobile");
|
|
3078
3094
|
var isFormData = (value) => isObject_default(value) && isBrowser() && value instanceof FormData;
|
|
3079
3095
|
var isWindow = (value) => typeof window !== "undefined" && toString.call(value) === "[object Window]";
|
|
3096
|
+
var isTruthy = (value) => Boolean(value);
|
|
3080
3097
|
|
|
3081
3098
|
// src/util/json.ts
|
|
3082
3099
|
function jsonTryParse(text) {
|
|
@@ -3087,20 +3104,23 @@ function jsonTryParse(text) {
|
|
|
3087
3104
|
}
|
|
3088
3105
|
}
|
|
3089
3106
|
|
|
3090
|
-
// src/util/
|
|
3091
|
-
function pPipe(...
|
|
3092
|
-
if (
|
|
3107
|
+
// src/util/pipe-promise.ts
|
|
3108
|
+
function pPipe(...fns) {
|
|
3109
|
+
if (fns.length === 0)
|
|
3093
3110
|
throw new Error("Expected at least one argument");
|
|
3094
3111
|
return async (input) => {
|
|
3095
|
-
let
|
|
3096
|
-
for (const
|
|
3097
|
-
|
|
3098
|
-
return
|
|
3112
|
+
let value = input;
|
|
3113
|
+
for (const fn of fns)
|
|
3114
|
+
value = await fn(value);
|
|
3115
|
+
return value;
|
|
3099
3116
|
};
|
|
3100
3117
|
}
|
|
3101
3118
|
|
|
3102
3119
|
// src/util/pipe.ts
|
|
3103
|
-
|
|
3120
|
+
function pipe(...fns) {
|
|
3121
|
+
return fns.reduce((v, f) => f(v));
|
|
3122
|
+
}
|
|
3123
|
+
pipe.promise = pPipe;
|
|
3104
3124
|
|
|
3105
3125
|
// src/util/random.ts
|
|
3106
3126
|
function randomNumer(min, max) {
|
|
@@ -3195,6 +3215,7 @@ export {
|
|
|
3195
3215
|
isPhantomJS,
|
|
3196
3216
|
isPlainObject_default as isPlainObject,
|
|
3197
3217
|
isString_default as isString,
|
|
3218
|
+
isTruthy,
|
|
3198
3219
|
isTypeof,
|
|
3199
3220
|
isUndefined_default as isUndefined,
|
|
3200
3221
|
isWeex,
|
|
@@ -3212,7 +3233,6 @@ export {
|
|
|
3212
3233
|
noop2 as noop,
|
|
3213
3234
|
numerfix,
|
|
3214
3235
|
objectToForm,
|
|
3215
|
-
pPipe,
|
|
3216
3236
|
parseNumeric,
|
|
3217
3237
|
pascalCase,
|
|
3218
3238
|
pascalSnakeCase,
|