massaman 0.0.1-rc.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/LICENSE +21 -0
- package/README.md +139 -0
- package/dist/array/index.d.mts +2 -0
- package/dist/array/index.mjs +2 -0
- package/dist/array-C8MqjyiP.mjs +191 -0
- package/dist/array-C8MqjyiP.mjs.map +1 -0
- package/dist/control/index.d.mts +2 -0
- package/dist/control/index.mjs +2 -0
- package/dist/control-B4mDPBn6.mjs +164 -0
- package/dist/control-B4mDPBn6.mjs.map +1 -0
- package/dist/conversion/index.d.mts +2 -0
- package/dist/conversion/index.mjs +2 -0
- package/dist/conversion-ByBXBR5i.mjs +189 -0
- package/dist/conversion-ByBXBR5i.mjs.map +1 -0
- package/dist/error/index.d.mts +2 -0
- package/dist/error/index.mjs +2 -0
- package/dist/function/index.d.mts +2 -0
- package/dist/function/index.mjs +2 -0
- package/dist/function-2-6QB4m7.mjs +122 -0
- package/dist/function-2-6QB4m7.mjs.map +1 -0
- package/dist/index-BkyNt8th.d.mts +20 -0
- package/dist/index-BkyNt8th.d.mts.map +1 -0
- package/dist/index-Br9PO6mU.d.mts +155 -0
- package/dist/index-Br9PO6mU.d.mts.map +1 -0
- package/dist/index-BuBpCB73.d.mts +197 -0
- package/dist/index-BuBpCB73.d.mts.map +1 -0
- package/dist/index-COFf0Pih.d.mts +128 -0
- package/dist/index-COFf0Pih.d.mts.map +1 -0
- package/dist/index-DqsBQ7Pp.d.mts +120 -0
- package/dist/index-DqsBQ7Pp.d.mts.map +1 -0
- package/dist/index-Dw_tuZdb.d.mts +134 -0
- package/dist/index-Dw_tuZdb.d.mts.map +1 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +12 -0
- package/dist/math/index.d.mts +2 -0
- package/dist/math/index.mjs +2 -0
- package/dist/object/index.d.mts +2 -0
- package/dist/object/index.mjs +2 -0
- package/dist/object-BHnp9Sr9.mjs +27 -0
- package/dist/object-BHnp9Sr9.mjs.map +1 -0
- package/dist/pattern/index.d.mts +2 -0
- package/dist/pattern/index.mjs +2 -0
- package/dist/predicate/index.d.mts +2 -0
- package/dist/predicate/index.mjs +2 -0
- package/dist/predicate-CYzSOMLW.mjs +108 -0
- package/dist/predicate-CYzSOMLW.mjs.map +1 -0
- package/dist/promise/index.d.mts +2 -0
- package/dist/promise/index.mjs +2 -0
- package/dist/string/index.d.mts +2 -0
- package/dist/string/index.mjs +2 -0
- package/package.json +108 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError as isError$1, isFile, isFunction, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap as isMap$1, isNil as isNil$1, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive as isPrimitive$1, isPromise, isRegExp, isSet as isSet$1, isString as isString$1, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet } from "es-toolkit/predicate";
|
|
2
|
+
|
|
3
|
+
//#region src/types/internal.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Explicit alias for `any` that makes dangerous intent visible at the call site.
|
|
6
|
+
*
|
|
7
|
+
* The `typescript/no-explicit-any` lint rule is configured as an error, so raw
|
|
8
|
+
* `any` is banned. Use this alias only when `unknown` genuinely will not work —
|
|
9
|
+
* almost always in conditional types that need to match function signatures with
|
|
10
|
+
* arbitrary parameter types, where contravariance makes `unknown` reject narrow
|
|
11
|
+
* predicates like `(n: number) => boolean`.
|
|
12
|
+
*
|
|
13
|
+
* Reach for this last. If you can use `unknown`, use `unknown`.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Generic over a tuple of predicates with arbitrary input types:
|
|
18
|
+
* type Guarded<P> = P extends (value: DangerouslyAllowAny) => value is infer X ? X : never
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
type DangerouslyAllowAny = any;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/predicate/combinators.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* Extracts the narrowed target type from a type-guard predicate.
|
|
26
|
+
* Returns `never` for plain `boolean` predicates so they don't pollute
|
|
27
|
+
* the union/intersection downstream.
|
|
28
|
+
*
|
|
29
|
+
* `DangerouslyAllowAny` is required here: this conditional needs to match
|
|
30
|
+
* predicate signatures with arbitrary input types (`(n: number) => …`,
|
|
31
|
+
* `(s: string) => …`, etc.). `unknown` would reject those by contravariance.
|
|
32
|
+
*/
|
|
33
|
+
type Guarded<P> = P extends ((value: DangerouslyAllowAny) => value is infer X) ? X : never;
|
|
34
|
+
/**
|
|
35
|
+
* Extracts the input type from a tuple of predicates. Uses `infer V` in
|
|
36
|
+
* contravariant position so multiple predicates with the same input type
|
|
37
|
+
* collapse to that type. Return-position is `unknown` (covariant, accepts
|
|
38
|
+
* any return value).
|
|
39
|
+
*/
|
|
40
|
+
type InferInput<Ps> = Ps extends ReadonlyArray<(value: infer V) => unknown> ? V : never;
|
|
41
|
+
/**
|
|
42
|
+
* Converts a union `A | B | C` to an intersection `A & B & C`.
|
|
43
|
+
* Standard contravariant-position trick.
|
|
44
|
+
*/
|
|
45
|
+
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
46
|
+
/**
|
|
47
|
+
* Returns a predicate that checks if a value satisfies ALL predicates.
|
|
48
|
+
*
|
|
49
|
+
* When every input is a type guard, the result narrows to the intersection
|
|
50
|
+
* of every guard's target type. Plain `boolean` predicates contribute nothing
|
|
51
|
+
* to the narrowing (they fall back to no-op).
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* const isPositiveEven = allPass([(n: number) => n > 0, (n: number) => n % 2 === 0])
|
|
56
|
+
* isPositiveEven(4) // true
|
|
57
|
+
*
|
|
58
|
+
* const isNonEmptyString = allPass([isString, isNotEmpty])
|
|
59
|
+
* if (isNonEmptyString(x)) {
|
|
60
|
+
* // x is narrowed to string here
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function allPass<T>(predicates: readonly []): (value: T) => true;
|
|
65
|
+
declare function allPass<Ps extends ReadonlyArray<(value: DangerouslyAllowAny) => boolean>>(predicates: Ps): (value: InferInput<Ps>) => value is InferInput<Ps> & UnionToIntersection<Guarded<Ps[number]>>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns a predicate that checks if a value satisfies ANY predicate.
|
|
68
|
+
*
|
|
69
|
+
* When every input is a type guard, the result narrows to the union of every
|
|
70
|
+
* guard's target type (since only one needs to match).
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const isAdminOrOwner = anyPass([isAdmin, isOwner])
|
|
75
|
+
* isAdminOrOwner(user)
|
|
76
|
+
*
|
|
77
|
+
* const isStringOrNumber = anyPass([isString, isNumber])
|
|
78
|
+
* if (isStringOrNumber(x)) {
|
|
79
|
+
* // x is narrowed to string | number here
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
declare function anyPass<T>(predicates: readonly []): (value: T) => false;
|
|
84
|
+
declare function anyPass<Ps extends ReadonlyArray<(value: DangerouslyAllowAny) => boolean>>(predicates: Ps): (value: InferInput<Ps>) => value is InferInput<Ps> & Guarded<Ps[number]>;
|
|
85
|
+
/**
|
|
86
|
+
* Returns a predicate that checks if a value satisfies both predicates.
|
|
87
|
+
*
|
|
88
|
+
* Binary AND combinator — shorthand for `allPass([f, g])`. When both inputs
|
|
89
|
+
* are type guards, the result narrows to the intersection of their target types.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* const isPositiveEven = both((n: number) => n > 0, (n: number) => n % 2 === 0)
|
|
94
|
+
* isPositiveEven(4)
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function both<T, A extends T, B extends T>(f: (value: T) => value is A, g: (value: T) => value is B): (value: T) => value is A & B;
|
|
98
|
+
declare function both<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a predicate that checks if a value satisfies either predicate.
|
|
101
|
+
*
|
|
102
|
+
* Binary OR combinator — shorthand for `anyPass([f, g])`. When both inputs
|
|
103
|
+
* are type guards, the result narrows to the union of their target types.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* const isNilOrEmpty = either(isNil, (s: string) => s === '')
|
|
108
|
+
* isNilOrEmpty(null)
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function either<T, A extends T, B extends T>(f: (value: T) => value is A, g: (value: T) => value is B): (value: T) => value is A | B;
|
|
112
|
+
declare function either<T>(f: (value: T) => boolean, g: (value: T) => boolean): (value: T) => boolean;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/predicate/guards.d.ts
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a value is an array.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* isArray([1, 2]) // true
|
|
121
|
+
* isArray('hello') // false
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare const isArray: (arg: any) => arg is any[];
|
|
125
|
+
/**
|
|
126
|
+
* Checks if a value is a non-null object.
|
|
127
|
+
*
|
|
128
|
+
* Returns `true` for plain objects, arrays, class instances, etc.
|
|
129
|
+
* Returns `false` for `null`, primitives, and functions.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* isObject({}) // true
|
|
134
|
+
* isObject(null) // false
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
declare function isObject(value: unknown): value is object;
|
|
138
|
+
/**
|
|
139
|
+
* Checks if a value is empty.
|
|
140
|
+
*
|
|
141
|
+
* - Strings: `''`
|
|
142
|
+
* - Arrays: `length === 0`
|
|
143
|
+
* - Maps/Sets: `size === 0`
|
|
144
|
+
* - Objects: no own enumerable keys
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* isEmpty('') // true
|
|
149
|
+
* isEmpty([]) // true
|
|
150
|
+
* isEmpty({}) // true
|
|
151
|
+
* isEmpty(new Map()) // true
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
declare function isEmpty(value: string | object): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Checks if a value is not empty. Complement of {@link isEmpty}.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* isNotEmpty('hello') // true
|
|
161
|
+
* isNotEmpty([]) // false
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
declare function isNotEmpty(value: string | object): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Checks if a value is a finite number.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* isFiniteNumber(42) // true
|
|
171
|
+
* isFiniteNumber(Infinity) // false
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
declare const isFiniteNumber: (value: unknown) => boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Checks if a value is an integer.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* isInteger(42) // true
|
|
181
|
+
* isInteger(4.2) // false
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
declare const isInteger: (value: unknown) => boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Checks if a value is NaN.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* isNaN(NaN) // true
|
|
191
|
+
* isNaN(42) // false
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
declare const isNaN: (value: unknown) => boolean;
|
|
195
|
+
//#endregion
|
|
196
|
+
export { isSymbol as A, isNotEmpty as B, isNumber as C, isRegExp as D, isPromise as E, isArray as F, either as G, allPass as H, isEmpty as I, isFiniteNumber as L, isUndefined as M, isWeakMap as N, isSet$1 as O, isWeakSet as P, isInteger as R, isNull as S, isPrimitive$1 as T, anyPass as U, isObject as V, both as W, isLength as _, isBuffer as a, isNode as b, isEqual as c, isFile as d, isFunction as f, isJSONValue as g, isJSONObject as h, isBrowser as i, isTypedArray as j, isString$1 as k, isEqualWith as l, isJSONArray as m, isBlob as n, isDate as o, isJSON as p, isBoolean as r, isEmptyObject as s, isArrayBuffer as t, isError$1 as u, isMap$1 as v, isPlainObject as w, isNotNil as x, isNil$1 as y, isNaN as z };
|
|
197
|
+
//# sourceMappingURL=index-BuBpCB73.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-BuBpCB73.d.mts","names":[],"sources":["../src/types/internal.ts","../src/predicate/combinators.ts","../src/predicate/guards.ts"],"mappings":";;;;;;AAmBA;;;;;;;;ACnB+D;;;;;;KDmBnD,mBAAA;;;;;AAAZ;;;;;;;KCRK,OAAA,MAAa,CAAA,WAAY,KAAA,EAAO,mBAAA,KAAwB,KAAA,eAAoB,CAAA;AAXlB;;;;;;AAAA,KAmB1D,UAAA,OAAiB,EAAA,SAAW,aAAA,EAAe,KAAA,yBAA8B,CAAA;;;;;KAMzE,mBAAA,OAA0B,CAAA,oBAAqB,CAAA,EAAG,CAAA,6BACrD,CAAA,sBAEE,CAAA;;AAjB8E;;;;;;;;;;;;AAQH;;;;;iBA8B/D,OAAA,GAAA,CAAW,UAAA,iBAA2B,KAAA,EAAO,CAAA;AAAA,iBAC7C,OAAA,YAAmB,aAAA,EAAe,KAAA,EAAO,mBAAA,cAAA,CACvD,UAAA,EAAY,EAAA,IACV,KAAA,EAAO,UAAA,CAAW,EAAA,MAAQ,KAAA,IAAS,UAAA,CAAW,EAAA,IAAM,mBAAA,CAAoB,OAAA,CAAQ,EAAA;;;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;;cAad,cAAA,GAAiB,KAAA;;;;;;;;;;cAWjB,SAAA,GAAY,KAAA;;;;;;;;;;cAWZ,KAAA,GAAQ,KAAA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
//#region src/conversion/convert.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Coerces an unknown thrown value into a proper `Error` instance.
|
|
4
|
+
*
|
|
5
|
+
* Handles the common cases where libraries throw non-`Error` values
|
|
6
|
+
* (e.g. plain API response bodies, arrays, Maps) that would otherwise
|
|
7
|
+
* serialize as `[object Object]` in error messages.
|
|
8
|
+
*
|
|
9
|
+
* @param thrown - The caught value from a `catch` block.
|
|
10
|
+
* @returns An `Error` with a meaningful `.message`. If `thrown` is
|
|
11
|
+
* already an `Error`, it is returned as-is. The original value is
|
|
12
|
+
* preserved as `.cause` for debugging.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* try {
|
|
17
|
+
* await riskyCall()
|
|
18
|
+
* } catch (thrown) {
|
|
19
|
+
* const error = toError(thrown)
|
|
20
|
+
* console.error(error.message)
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function toError(thrown: unknown): Error;
|
|
25
|
+
/**
|
|
26
|
+
* Produces a human-readable string from any unknown value.
|
|
27
|
+
*
|
|
28
|
+
* Uses `JSON.stringify` for structured types (plain objects, arrays)
|
|
29
|
+
* so the message contains actual content instead of `[object Object]`.
|
|
30
|
+
* Maps and Sets are converted to their array representation first.
|
|
31
|
+
* Falls back to `String()` for primitives or when serialization fails
|
|
32
|
+
* (e.g. circular references).
|
|
33
|
+
*
|
|
34
|
+
* @param value - The value to stringify.
|
|
35
|
+
* @returns A meaningful string representation.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* stringify({ status: 400 }) // '{"status":400}'
|
|
40
|
+
* stringify(new Map([['k', 'v']])) // '[["k","v"]]'
|
|
41
|
+
* stringify(null) // 'null'
|
|
42
|
+
* stringify(42) // '42'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
declare function stringify(value: unknown): string;
|
|
46
|
+
/**
|
|
47
|
+
* Converts a value to a number.
|
|
48
|
+
*
|
|
49
|
+
* Thin wrapper over `Number(value)` — kept as a stable surface so callers
|
|
50
|
+
* don't depend directly on the global constructor's semantics (which have
|
|
51
|
+
* shifted in the past, e.g. `Number(BigInt)`, and may again).
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* toNumber('42') // 42
|
|
56
|
+
* toNumber(null) // 0
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function toNumber(value: unknown): number;
|
|
60
|
+
/**
|
|
61
|
+
* Converts a value to a string.
|
|
62
|
+
*
|
|
63
|
+
* Thin wrapper over `String(value)` — kept as a stable surface against
|
|
64
|
+
* future global-constructor changes.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* toString(42) // '42'
|
|
69
|
+
* toString(null) // 'null'
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
declare function toString(value: unknown): string;
|
|
73
|
+
/**
|
|
74
|
+
* Converts a value to an integer by calling {@link toNumber} and truncating.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* toInteger('4.9') // 4
|
|
79
|
+
* toInteger(null) // 0
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function toInteger(value: unknown): number;
|
|
83
|
+
/**
|
|
84
|
+
* Converts a value to a finite number.
|
|
85
|
+
*
|
|
86
|
+
* Returns `0` for non-finite results (`NaN`, `Infinity`, `-Infinity`).
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* toFinite('3.14') // 3.14
|
|
91
|
+
* toFinite(Infinity) // 0
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function toFinite(value: unknown): number;
|
|
95
|
+
/**
|
|
96
|
+
* Converts a value to an array.
|
|
97
|
+
*
|
|
98
|
+
* - Arrays are returned as-is.
|
|
99
|
+
* - Iterables (strings, Sets, Maps) are spread into an array.
|
|
100
|
+
* - `null` / `undefined` return `[]`.
|
|
101
|
+
* - All other values are wrapped in a single-element array.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* toArray(new Set([1, 2])) // [1, 2]
|
|
106
|
+
* toArray('abc') // ['a', 'b', 'c']
|
|
107
|
+
* toArray(null) // []
|
|
108
|
+
* toArray(42) // [42]
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function toArray<T>(value: Iterable<T> | T | null | undefined): T[];
|
|
112
|
+
/**
|
|
113
|
+
* Converts a value to a boolean.
|
|
114
|
+
*
|
|
115
|
+
* Thin wrapper over `Boolean(value)` — kept as a stable surface against
|
|
116
|
+
* future global-constructor changes.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* toBoolean(1) // true
|
|
121
|
+
* toBoolean(0) // false
|
|
122
|
+
* toBoolean('') // false
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function toBoolean(value: unknown): boolean;
|
|
126
|
+
//#endregion
|
|
127
|
+
export { toFinite as a, toString as c, toError as i, toArray as n, toInteger as o, toBoolean as r, toNumber as s, stringify as t };
|
|
128
|
+
//# sourceMappingURL=index-COFf0Pih.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-COFf0Pih.d.mts","names":[],"sources":["../src/conversion/convert.ts"],"mappings":";;AAwBA;;;;;AA8BA;;;;;AAqFA;;;;;AAgBA;;;;;AAaA;iBAhJgB,OAAA,CAAQ,MAAA,YAAkB,KAAA;;;;AA+J1C;;;;;AAwBA;;;;;;;;;;;;iBAzJgB,SAAA,CAAU,KAAA;;;;;AAmL1B;;;;;;;;;iBA9FgB,QAAA,CAAS,KAAA;;;;;;;;;;;;;iBAgBT,QAAA,CAAS,KAAA;;;;;;;;;;iBAaT,SAAA,CAAU,KAAA;;;;;;;;;;;;iBAeV,QAAA,CAAS,KAAA;;;;;;;;;;;;;;;;;iBAwBT,OAAA,GAAA,CAAW,KAAA,EAAO,QAAA,CAAS,CAAA,IAAK,CAAA,sBAAuB,CAAA;;;;;;;;;;;;;;iBA0BvD,SAAA,CAAU,KAAA"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { DebounceOptions, DebouncedFunction, MemoizeCache, ThrottleOptions, ThrottledFunction, after, ary, asyncNoop, before, curry, curryRight, debounce, flow, flowRight, identity, memoize, negate, noop, once, partial, partialRight, rest, retry, spread, throttle, unary } from "es-toolkit/function";
|
|
2
|
+
|
|
3
|
+
//#region src/function/call.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Invokes a function with the provided arguments and returns the result.
|
|
6
|
+
*
|
|
7
|
+
* Equivalent to `fn(...args)` — exists as a stable, named surface for the
|
|
8
|
+
* "apply function to args" operation. Use inside `.map(call)` over arrays
|
|
9
|
+
* of thunks, or anywhere a value-position function-call is clearer than an
|
|
10
|
+
* inline arrow.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* call(Math.max, 1, 2, 3) // 3
|
|
15
|
+
* [getUser, getAccount, getPrefs].map((fn) => call(fn))
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function call<A extends readonly unknown[], R>(fn: (...args: A) => R, ...args: A): R;
|
|
19
|
+
/**
|
|
20
|
+
* Invokes a function returning a Promise with the provided arguments.
|
|
21
|
+
*
|
|
22
|
+
* Async-typed sibling of {@link call} — equivalent to `fn(...args)` for
|
|
23
|
+
* promise-returning functions, but the signature constrains the return to
|
|
24
|
+
* `Promise<R>` so it composes cleanly inside async pipelines.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const user = await callAsync(fetchUser, 'user-123')
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function callAsync<A extends readonly unknown[], R>(fn: (...args: A) => Promise<R>, ...args: A): Promise<R>;
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/function/branching.d.ts
|
|
34
|
+
/**
|
|
35
|
+
* Returns a function that applies a transform only when a predicate passes,
|
|
36
|
+
* otherwise returns the value unchanged.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const trimIfString = when(isString, (s: string) => s.trim())
|
|
41
|
+
* trimIfString(' hello ') // 'hello'
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function when<T>(predicate: (value: T) => boolean, fn: (value: T) => T): (value: T) => T;
|
|
45
|
+
/**
|
|
46
|
+
* Returns a function that applies a transform only when a predicate fails,
|
|
47
|
+
* otherwise returns the value unchanged.
|
|
48
|
+
*
|
|
49
|
+
* Complement of {@link when}.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const ensureArray = unless(Array.isArray, (v) => [v])
|
|
54
|
+
* ensureArray(42) // [42]
|
|
55
|
+
* ensureArray([1]) // [1]
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
declare function unless<T>(predicate: (value: T) => boolean, fn: (value: T) => T): (value: T) => T;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a function that branches between two functions based on a predicate.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const format = ifElse(
|
|
65
|
+
* (n: number) => n > 0,
|
|
66
|
+
* (n) => `+${n}`,
|
|
67
|
+
* (n) => `${n}`,
|
|
68
|
+
* )
|
|
69
|
+
* format(5) // '+5'
|
|
70
|
+
* format(-3) // '-3'
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare function ifElse<T, R>(predicate: (value: T) => boolean, onTrue: (value: T) => R, onFalse: (value: T) => R): (value: T) => R;
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/function/tap.d.ts
|
|
76
|
+
/**
|
|
77
|
+
* Returns a function that runs a side-effect and returns the value unchanged.
|
|
78
|
+
*
|
|
79
|
+
* Useful for debugging inside `flow` pipelines without breaking the chain.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const process = flow(
|
|
84
|
+
* fetchUsers,
|
|
85
|
+
* tap(users => console.log('count:', users.length)),
|
|
86
|
+
* filterActive,
|
|
87
|
+
* )
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function tap<T>(fn: (value: T) => unknown): (value: T) => T;
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/function/flowAsync.d.ts
|
|
93
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Creates an async pipeline that awaits each step before passing the result
|
|
96
|
+
* to the next function. Like {@link flow} from es-toolkit but async-aware.
|
|
97
|
+
*
|
|
98
|
+
* Each function can return a value or a Promise — `flowAsync` always returns
|
|
99
|
+
* a Promise that resolves to the final step's awaited result.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* const getUsername = flowAsync(
|
|
104
|
+
* (id: string) => fetchUser(id), // Promise<User>
|
|
105
|
+
* (user) => user.name, // string
|
|
106
|
+
* (name) => name.toUpperCase(),
|
|
107
|
+
* )
|
|
108
|
+
* await getUsername('123') // 'ALICE'
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function flowAsync<A extends readonly unknown[], R1>(f1: (...args: A) => MaybePromise<R1>): (...args: A) => Promise<Awaited<R1>>;
|
|
112
|
+
declare function flowAsync<A extends readonly unknown[], R1, R2>(f1: (...args: A) => MaybePromise<R1>, f2: (a: Awaited<R1>) => MaybePromise<R2>): (...args: A) => Promise<Awaited<R2>>;
|
|
113
|
+
declare function flowAsync<A extends readonly unknown[], R1, R2, R3>(f1: (...args: A) => MaybePromise<R1>, f2: (a: Awaited<R1>) => MaybePromise<R2>, f3: (a: Awaited<R2>) => MaybePromise<R3>): (...args: A) => Promise<Awaited<R3>>;
|
|
114
|
+
declare function flowAsync<A extends readonly unknown[], R1, R2, R3, R4>(f1: (...args: A) => MaybePromise<R1>, f2: (a: Awaited<R1>) => MaybePromise<R2>, f3: (a: Awaited<R2>) => MaybePromise<R3>, f4: (a: Awaited<R3>) => MaybePromise<R4>): (...args: A) => Promise<Awaited<R4>>;
|
|
115
|
+
declare function flowAsync<A extends readonly unknown[], R1, R2, R3, R4, R5>(f1: (...args: A) => MaybePromise<R1>, f2: (a: Awaited<R1>) => MaybePromise<R2>, f3: (a: Awaited<R2>) => MaybePromise<R3>, f4: (a: Awaited<R3>) => MaybePromise<R4>, f5: (a: Awaited<R4>) => MaybePromise<R5>): (...args: A) => Promise<Awaited<R5>>;
|
|
116
|
+
declare function flowAsync<A extends readonly unknown[], R1, R2, R3, R4, R5, R6>(f1: (...args: A) => MaybePromise<R1>, f2: (a: Awaited<R1>) => MaybePromise<R2>, f3: (a: Awaited<R2>) => MaybePromise<R3>, f4: (a: Awaited<R3>) => MaybePromise<R4>, f5: (a: Awaited<R4>) => MaybePromise<R5>, f6: (a: Awaited<R5>) => MaybePromise<R6>): (...args: A) => Promise<Awaited<R6>>;
|
|
117
|
+
declare function flowAsync<A extends readonly unknown[], R1, R2, R3, R4, R5, R6, R7>(f1: (...args: A) => MaybePromise<R1>, f2: (a: Awaited<R1>) => MaybePromise<R2>, f3: (a: Awaited<R2>) => MaybePromise<R3>, f4: (a: Awaited<R3>) => MaybePromise<R4>, f5: (a: Awaited<R4>) => MaybePromise<R5>, f6: (a: Awaited<R5>) => MaybePromise<R6>, f7: (a: Awaited<R6>) => MaybePromise<R7>): (...args: A) => Promise<Awaited<R7>>;
|
|
118
|
+
//#endregion
|
|
119
|
+
export { unless as A, retry as C, flowAsync as D, unary as E, call as M, callAsync as N, tap as O, rest as S, throttle as T, negate as _, ThrottledFunction as a, partial as b, asyncNoop as c, curryRight as d, debounce as f, memoize as g, identity as h, ThrottleOptions as i, when as j, ifElse as k, before as l, flowRight as m, DebouncedFunction as n, after as o, flow as p, MemoizeCache as r, ary as s, DebounceOptions as t, curry as u, noop as v, spread as w, partialRight as x, once as y };
|
|
120
|
+
//# sourceMappingURL=index-DqsBQ7Pp.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-DqsBQ7Pp.d.mts","names":[],"sources":["../src/function/call.ts","../src/function/branching.ts","../src/function/tap.ts","../src/function/flowAsync.ts"],"mappings":";;;;;;AAcA;;;;;;;;;;;iBAAgB,IAAA,iCAAA,CAAsC,EAAA,MAAQ,IAAA,EAAM,CAAA,KAAM,CAAA,KAAM,IAAA,EAAM,CAAA,GAAI,CAAA;;;;;;;;;AAgB1F;;;;iBAAsB,SAAA,iCAAA,CACpB,EAAA,MAAQ,IAAA,EAAM,CAAA,KAAM,OAAA,CAAQ,CAAA,MACzB,IAAA,EAAM,CAAA,GACR,OAAA,CAAQ,CAAA;;;;;;AAnBX;;;;;;;iBCJgB,IAAA,GAAA,CAAQ,SAAA,GAAY,KAAA,EAAO,CAAA,cAAe,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA,IAAK,KAAA,EAAO,CAAA,KAAM,CAAA;;;;;;;;;;;;;ADoB9F;iBCEgB,MAAA,GAAA,CAAU,SAAA,GAAY,KAAA,EAAO,CAAA,cAAe,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA,IAAK,KAAA,EAAO,CAAA,KAAM,CAAA;;;;;;;;;;;;;;;iBAuBhF,MAAA,MAAA,CACd,SAAA,GAAY,KAAA,EAAO,CAAA,cACnB,MAAA,GAAS,KAAA,EAAO,CAAA,KAAM,CAAA,EACtB,OAAA,GAAU,KAAA,EAAO,CAAA,KAAM,CAAA,IACrB,KAAA,EAAO,CA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,GACrC,EAAA,GAAK,CAAA,EAAG,OAAA,CAAQ,EAAA,MAAQ,YAAA,CAAa,EAAA,GACrC,EAAA,GAAK,CAAA,EAAG,OAAA,CAAQ,EAAA,MAAQ,YAAA,CAAa,EAAA,GACrC,EAAA,GAAK,CAAA,EAAG,OAAA,CAAQ,EAAA,MAAQ,YAAA,CAAa,EAAA,GACrC,EAAA,GAAK,CAAA,EAAG,OAAA,CAAQ,EAAA,MAAQ,YAAA,CAAa,EAAA,QAChC,IAAA,EAAM,CAAA,KAAM,OAAA,CAAQ,OAAA,CAAQ,EAAA"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { at, chunk, compact, countBy, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, fill, filterAsync, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, forEachAsync, forEachRight, groupBy, head, initial, intersection, intersectionBy, intersectionWith, isSubset, isSubsetWith, keyBy, last, limitAsync, mapAsync, maxBy, minBy, orderBy, partition, pull, pullAt, reduceAsync, remove, sample, sampleSize, shuffle, sortBy, tail, take, takeRight, takeRightWhile, takeWhile, toFilled, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, windowed, without, xor, xorBy, xorWith, zip, zipObject, zipWith } from "es-toolkit/array";
|
|
2
|
+
|
|
3
|
+
//#region src/array/adjust.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Applies a function to the element at the given index, returning a new array.
|
|
6
|
+
*
|
|
7
|
+
* The original array is not modified. If the index is out of bounds, the
|
|
8
|
+
* array is returned unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* adjust([1, 2, 3], 1, (n) => n * 10)
|
|
13
|
+
* // [1, 20, 3]
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function adjust<T>(array: readonly T[], index: number, fn: (value: T) => T): T[];
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/array/dropRepeats.d.ts
|
|
19
|
+
/**
|
|
20
|
+
* Removes consecutively repeated elements from an array using strict
|
|
21
|
+
* equality (`===`).
|
|
22
|
+
*
|
|
23
|
+
* Only adjacent duplicates are removed — non-adjacent duplicates are kept.
|
|
24
|
+
* Use {@link uniq} from es-toolkit to remove all duplicates regardless of position.
|
|
25
|
+
*
|
|
26
|
+
* Quirks (inherent to `===`):
|
|
27
|
+
* - `NaN !== NaN`, so adjacent `NaN`s are *not* collapsed.
|
|
28
|
+
* - `-0 === 0`, so adjacent `-0` and `0` *are* collapsed.
|
|
29
|
+
* - Object/array elements compare by reference, not structure.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* dropRepeats([1, 1, 2, 3, 3, 2, 1])
|
|
34
|
+
* // [1, 2, 3, 2, 1]
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare function dropRepeats<T>(array: readonly T[]): T[];
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/array/reduceWhile.d.ts
|
|
40
|
+
/**
|
|
41
|
+
* Like `reduce` but stops early when the predicate returns `false`.
|
|
42
|
+
*
|
|
43
|
+
* The predicate receives the current accumulator and element. When it
|
|
44
|
+
* returns `false`, the current accumulator is returned without processing
|
|
45
|
+
* the remaining elements.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* // Sum until we hit a negative number
|
|
50
|
+
* reduceWhile(
|
|
51
|
+
* [1, 2, 3, -1, 5],
|
|
52
|
+
* (acc, n) => n >= 0,
|
|
53
|
+
* (acc, n) => acc + n,
|
|
54
|
+
* 0,
|
|
55
|
+
* )
|
|
56
|
+
* // 6
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function reduceWhile<T, R>(array: readonly T[], predicate: (accumulator: R, value: T) => boolean, fn: (accumulator: R, value: T, index: number) => R, initial: R): R;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/array/scan.d.ts
|
|
62
|
+
/**
|
|
63
|
+
* Like `reduce` but returns an array of all intermediate accumulator values.
|
|
64
|
+
*
|
|
65
|
+
* The result array starts with the initial value and ends with the final
|
|
66
|
+
* accumulator, so its length is `array.length + 1`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* scan([1, 2, 3, 4], (acc, n) => acc + n, 0)
|
|
71
|
+
* // [0, 1, 3, 6, 10]
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
declare function scan<T, R>(array: readonly T[], fn: (accumulator: R, value: T, index: number) => R, initial: R): R[];
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/array/sorting.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Creates an ascending comparator from an accessor function.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* users.sort(ascend(u => u.name))
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function ascend<T>(fn: (value: T) => number | string): (a: T, b: T) => number;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a descending comparator from an accessor function.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* users.sort(descend(u => u.age))
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
declare function descend<T>(fn: (value: T) => number | string): (a: T, b: T) => number;
|
|
95
|
+
/**
|
|
96
|
+
* Sorts an array using multiple comparators in priority order.
|
|
97
|
+
*
|
|
98
|
+
* The first comparator has highest priority. When it returns 0 (tie),
|
|
99
|
+
* the next comparator is used, and so on.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* sortWith(users, [
|
|
104
|
+
* ascend(u => u.department),
|
|
105
|
+
* descend(u => u.age),
|
|
106
|
+
* ])
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
declare function sortWith<T>(array: readonly T[], comparators: ReadonlyArray<(a: T, b: T) => number>): T[];
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/array/unfold.d.ts
|
|
112
|
+
/**
|
|
113
|
+
* Builds an array from a seed value using an iterator function.
|
|
114
|
+
*
|
|
115
|
+
* The iterator receives the current seed and returns either a `[value, nextSeed]`
|
|
116
|
+
* tuple to continue, or `false` to stop.
|
|
117
|
+
*
|
|
118
|
+
* Dual of `reduce` — reduce collapses a list into a value, unfold expands
|
|
119
|
+
* a value into a list.
|
|
120
|
+
*
|
|
121
|
+
* **Termination is the caller's responsibility.** If `fn` never returns
|
|
122
|
+
* `false`, `unfold` will run until memory is exhausted. For bounded
|
|
123
|
+
* generation, encode a counter or limit into the seed.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* unfold((n) => (n > 0 ? [n, n - 1] : false), 5)
|
|
128
|
+
* // [5, 4, 3, 2, 1]
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function unfold<T, R>(fn: (seed: T) => [R, T] | false, seed: T): R[];
|
|
132
|
+
//#endregion
|
|
133
|
+
export { unionWith as $, last as A, remove as B, initial as C, isSubset as D, intersectionWith as E, orderBy as F, tail as G, sampleSize as H, partition as I, takeRightWhile as J, take as K, pull as L, mapAsync as M, maxBy as N, isSubsetWith as O, minBy as P, unionBy as Q, pullAt as R, head as S, intersectionBy as T, shuffle as U, sample as V, sortBy as W, toFilled as X, takeWhile as Y, union as Z, flatten as _, scan as _t, difference as a, windowed as at, forEachRight as b, adjust as bt, drop as c, xorBy as ct, dropWhile as d, zipObject as dt, uniq as et, fill as f, zipWith as ft, flatMapDeep as g, sortWith as gt, flatMapAsync as h, descend as ht, countBy as i, unzipWith as it, limitAsync as j, keyBy as k, dropRight as l, xorWith as lt, flatMap as m, ascend as mt, chunk as n, uniqWith as nt, differenceBy as o, without as ot, filterAsync as p, unfold as pt, takeRight as q, compact as r, unzip as rt, differenceWith as s, xor as st, at as t, uniqBy as tt, dropRightWhile as u, zip as ut, flattenDeep as v, reduceWhile as vt, intersection as w, groupBy as x, forEachAsync as y, dropRepeats as yt, reduceAsync as z };
|
|
134
|
+
//# sourceMappingURL=index-Dw_tuZdb.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-Dw_tuZdb.d.mts","names":[],"sources":["../src/array/adjust.ts","../src/array/dropRepeats.ts","../src/array/reduceWhile.ts","../src/array/scan.ts","../src/array/sorting.ts","../src/array/unfold.ts"],"mappings":";;;;;;AAYA;;;;;;;;;iBAAgB,MAAA,GAAA,CAAU,KAAA,WAAgB,CAAA,IAAK,KAAA,UAAe,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,CAAA;;;;;;AAApF;;;;;;;;;;;;;;;iBCMgB,WAAA,GAAA,CAAe,KAAA,WAAgB,CAAA,KAAM,CAAA;;;;;;ADNrD;;;;;;;;;;;;;;;;iBESgB,WAAA,MAAA,CACd,KAAA,WAAgB,CAAA,IAChB,SAAA,GAAY,WAAA,EAAa,CAAA,EAAG,KAAA,EAAO,CAAA,cACnC,EAAA,GAAK,WAAA,EAAa,CAAA,EAAG,KAAA,EAAO,CAAA,EAAG,KAAA,aAAkB,CAAA,EACjD,OAAA,EAAS,CAAA,GACR,CAAA;;;;;;AFdH;;;;;;;;;iBGAgB,IAAA,MAAA,CACd,KAAA,WAAgB,CAAA,IAChB,EAAA,GAAK,WAAA,EAAa,CAAA,EAAG,KAAA,EAAO,CAAA,EAAG,KAAA,aAAkB,CAAA,EACjD,OAAA,EAAS,CAAA,GACR,CAAA;;;;;;AHJH;;;;;iBIJgB,MAAA,GAAA,CAAU,EAAA,GAAK,KAAA,EAAO,CAAA,wBAAyB,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA;;;;;;;;;iBAsBxD,OAAA,GAAA,CAAW,EAAA,GAAK,KAAA,EAAO,CAAA,wBAAyB,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA;;;;;;;;;AHZzE;;;;;;iBGwCgB,QAAA,GAAA,CACd,KAAA,WAAgB,CAAA,IAChB,WAAA,EAAa,aAAA,EAAe,CAAA,EAAG,CAAA,EAAG,CAAA,EAAG,CAAA,eACpC,CAAA;;;;;;AJjDH;;;;;;;;;;;;;;;;iBKSgB,MAAA,MAAA,CAAa,EAAA,GAAK,IAAA,EAAM,CAAA,MAAO,CAAA,EAAG,CAAA,WAAY,IAAA,EAAM,CAAA,GAAI,CAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $ as unionWith, A as last, B as remove, C as initial, D as isSubset, E as intersectionWith, F as orderBy, G as tail, H as sampleSize, I as partition, J as takeRightWhile, K as take, L as pull, M as mapAsync, N as maxBy, O as isSubsetWith, P as minBy, Q as unionBy, R as pullAt, S as head, T as intersectionBy, U as shuffle, V as sample, W as sortBy, X as toFilled, Y as takeWhile, Z as union, _ as flatten, _t as scan, a as difference, at as windowed, b as forEachRight, bt as adjust, c as drop, ct as xorBy, d as dropWhile, dt as zipObject, et as uniq, f as fill, ft as zipWith, g as flatMapDeep, gt as sortWith, h as flatMapAsync, ht as descend, i as countBy, it as unzipWith, j as limitAsync, k as keyBy, l as dropRight, lt as xorWith, m as flatMap, mt as ascend, n as chunk, nt as uniqWith, o as differenceBy, ot as without, p as filterAsync, pt as unfold, q as takeRight, r as compact, rt as unzip, s as differenceWith, st as xor, t as at, tt as uniqBy, u as dropRightWhile, ut as zip, v as flattenDeep, vt as reduceWhile, w as intersection, x as groupBy, y as forEachAsync, yt as dropRepeats, z as reduceAsync } from "./index-Dw_tuZdb.mjs";
|
|
2
|
+
import { a as isOk, c as attempt, d as Ok, f as Result, i as isErr, l as attemptAsync, n as invariant, o as ok, r as err, s as unwrap, t as assert, u as Err } from "./index-Br9PO6mU.mjs";
|
|
3
|
+
import { a as toFinite, c as toString, i as toError, n as toArray, o as toInteger, r as toBoolean, s as toNumber, t as stringify } from "./index-COFf0Pih.mjs";
|
|
4
|
+
import { AbortError, TimeoutError } from "./error/index.mjs";
|
|
5
|
+
import { A as unless, C as retry, D as flowAsync, E as unary, M as call, N as callAsync, O as tap, S as rest, T as throttle, _ as negate, a as ThrottledFunction, b as partial, c as asyncNoop, d as curryRight, f as debounce, g as memoize, h as identity, i as ThrottleOptions, j as when, k as ifElse, l as before, m as flowRight, n as DebouncedFunction, o as after, p as flow, r as MemoizeCache, s as ary, t as DebounceOptions, u as curry, v as noop, w as spread, x as partialRight, y as once } from "./index-DqsBQ7Pp.mjs";
|
|
6
|
+
import { clamp, inRange, mean, meanBy, median, medianBy, random, randomInt, range, rangeRight, round, sum, sumBy } from "./math/index.mjs";
|
|
7
|
+
import { _ as toSnakeCaseKeys, a as flattenObject, c as mapValues, d as omit, f as omitBy, g as toMerged, h as toCamelCaseKeys, i as findKey, l as merge, m as pickBy, n as cloneDeep, o as invert, p as pick, r as cloneDeepWith, s as mapKeys, t as clone, u as mergeWith, v as evolve } from "./index-BkyNt8th.mjs";
|
|
8
|
+
import { A as isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPromise, F as isArray, G as either, H as allPass, I as isEmpty, L as isFiniteNumber, M as isUndefined, N as isWeakMap, O as isSet, P as isWeakSet, R as isInteger, S as isNull, T as isPrimitive, U as anyPass, V as isObject, W as both, _ as isLength, a as isBuffer, b as isNode, c as isEqual, d as isFile, f as isFunction, g as isJSONValue, h as isJSONObject, i as isBrowser, j as isTypedArray, k as isString, l as isEqualWith, m as isJSONArray, n as isBlob, o as isDate, p as isJSON, r as isBoolean, s as isEmptyObject, t as isArrayBuffer, u as isError, v as isMap, w as isPlainObject, x as isNotNil, y as isNil, z as isNaN } from "./index-BuBpCB73.mjs";
|
|
9
|
+
import { Mutex, Semaphore, delay, timeout, withTimeout } from "./promise/index.mjs";
|
|
10
|
+
import { camelCase, capitalize, constantCase, deburr, escape, escapeRegExp, kebabCase, lowerCase, lowerFirst, pad, pascalCase, reverseString, snakeCase, startCase, trim, trimEnd, trimStart, unescape, upperCase, upperFirst, words } from "./string/index.mjs";
|
|
11
|
+
import { NonExhaustiveError, P, Pattern, isMatching, match } from "./pattern/index.mjs";
|
|
12
|
+
export { AbortError, type DebounceOptions, type DebouncedFunction, type Err, type MemoizeCache, Mutex, NonExhaustiveError, type Ok, P, Pattern, type Result, Semaphore, type ThrottleOptions, type ThrottledFunction, TimeoutError, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, either, err, escape, escapeRegExp, evolve, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowAsync, flowRight, forEachAsync, forEachRight, groupBy, head, identity, ifElse, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isErr, isError, isFile, isFiniteNumber, isFunction, isInteger, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isMatching, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isOk, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, toSnakeCaseKeys, toString, trim, trimEnd, trimStart, unary, unescape, unfold, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $ as unionWith, A as last, B as remove, C as initial, D as isSubset, E as intersectionWith, F as orderBy, G as tail, H as sampleSize, I as partition, J as takeRightWhile, K as take, L as pull, M as mapAsync, N as maxBy, O as isSubsetWith, P as minBy, Q as unionBy, R as pullAt, S as head, T as intersectionBy, U as shuffle, V as sample, W as sortBy, X as toFilled, Y as takeWhile, Z as union, _ as flatten, _t as scan, a as difference, at as windowed, b as forEachRight, bt as adjust, c as drop, ct as xorBy, d as dropWhile, dt as zipObject, et as uniq, f as fill, ft as zipWith, g as flatMapDeep, gt as sortWith, h as flatMapAsync, ht as descend, i as countBy, it as unzipWith, j as limitAsync, k as keyBy, l as dropRight, lt as xorWith, m as flatMap, mt as ascend, n as chunk, nt as uniqWith, o as differenceBy, ot as without, p as filterAsync, pt as unfold, q as takeRight, r as compact, rt as unzip, s as differenceWith, st as xor, t as at, tt as uniqBy, u as dropRightWhile, ut as zip, v as flattenDeep, vt as reduceWhile, w as intersection, x as groupBy, y as forEachAsync, yt as dropRepeats, z as reduceAsync } from "./array-C8MqjyiP.mjs";
|
|
2
|
+
import { AbortError, TimeoutError } from "./error/index.mjs";
|
|
3
|
+
import { C as tap, D as call, E as when, O as callAsync, S as flowAsync, T as unless, _ as rest, a as curry, b as throttle, c as flow, d as memoize, f as negate, g as partialRight, h as partial, i as before, l as flowRight, m as once, n as ary, o as curryRight, p as noop, r as asyncNoop, s as debounce, t as after, u as identity, v as retry, w as ifElse, x as unary, y as spread } from "./function-2-6QB4m7.mjs";
|
|
4
|
+
import { clamp, inRange, mean, meanBy, median, medianBy, random, randomInt, range, rangeRight, round, sum, sumBy } from "./math/index.mjs";
|
|
5
|
+
import { _ as toSnakeCaseKeys, a as flattenObject, c as mapValues, d as omit, f as omitBy, g as toMerged, h as toCamelCaseKeys, i as findKey, l as merge, m as pickBy, n as cloneDeep, o as invert, p as pick, r as cloneDeepWith, s as mapKeys, t as clone, u as mergeWith, v as evolve } from "./object-BHnp9Sr9.mjs";
|
|
6
|
+
import { A as isSymbol, B as isNotEmpty, C as isNumber, D as isRegExp, E as isPromise, F as isArray, G as either, H as allPass, I as isEmpty, L as isFiniteNumber, M as isUndefined, N as isWeakMap, O as isSet, P as isWeakSet, R as isInteger, S as isNull, T as isPrimitive, U as anyPass, V as isObject, W as both, _ as isLength, a as isBuffer, b as isNode, c as isEqual, d as isFile, f as isFunction, g as isJSONValue, h as isJSONObject, i as isBrowser, j as isTypedArray, k as isString, l as isEqualWith, m as isJSONArray, n as isBlob, o as isDate, p as isJSON, r as isBoolean, s as isEmptyObject, t as isArrayBuffer, u as isError, v as isMap, w as isPlainObject, x as isNotNil, y as isNil, z as isNaN } from "./predicate-CYzSOMLW.mjs";
|
|
7
|
+
import { a as toFinite, c as toString, i as toError, n as toArray, o as toInteger, r as toBoolean, s as toNumber, t as stringify } from "./conversion-ByBXBR5i.mjs";
|
|
8
|
+
import { Mutex, Semaphore, delay, timeout, withTimeout } from "./promise/index.mjs";
|
|
9
|
+
import { camelCase, capitalize, constantCase, deburr, escape, escapeRegExp, kebabCase, lowerCase, lowerFirst, pad, pascalCase, reverseString, snakeCase, startCase, trim, trimEnd, trimStart, unescape, upperCase, upperFirst, words } from "./string/index.mjs";
|
|
10
|
+
import { a as err, c as ok, i as attemptAsync, l as unwrap, n as invariant, o as isErr, r as attempt, s as isOk, t as assert } from "./control-B4mDPBn6.mjs";
|
|
11
|
+
import { NonExhaustiveError, P, Pattern, isMatching, match } from "./pattern/index.mjs";
|
|
12
|
+
export { AbortError, Mutex, NonExhaustiveError, P, Pattern, Semaphore, TimeoutError, adjust, after, allPass, anyPass, ary, ascend, assert, asyncNoop, at, attempt, attemptAsync, before, both, call, callAsync, camelCase, capitalize, chunk, clamp, clone, cloneDeep, cloneDeepWith, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, descend, difference, differenceBy, differenceWith, drop, dropRepeats, dropRight, dropRightWhile, dropWhile, either, err, escape, escapeRegExp, evolve, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowAsync, flowRight, forEachAsync, forEachRight, groupBy, head, identity, ifElse, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArray, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmpty, isEmptyObject, isEqual, isEqualWith, isErr, isError, isFile, isFiniteNumber, isFunction, isInteger, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isMatching, isNaN, isNil, isNode, isNotEmpty, isNotNil, isNull, isNumber, isObject, isOk, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, match, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, ok, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, reduceWhile, remove, rest, retry, reverseString, round, sample, sampleSize, scan, shuffle, snakeCase, sortBy, sortWith, spread, startCase, stringify, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, tap, throttle, timeout, toArray, toBoolean, toCamelCaseKeys, toError, toFilled, toFinite, toInteger, toMerged, toNumber, toSnakeCaseKeys, toString, trim, trimEnd, trimStart, unary, unescape, unfold, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unless, unwrap, unzip, unzipWith, upperCase, upperFirst, when, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as toSnakeCaseKeys, a as flattenObject, c as mapValues, d as omit, f as omitBy, g as toMerged, h as toCamelCaseKeys, i as findKey, l as merge, m as pickBy, n as cloneDeep, o as invert, p as pick, r as cloneDeepWith, s as mapKeys, t as clone, u as mergeWith, v as evolve } from "../index-BkyNt8th.mjs";
|
|
2
|
+
export { clone, cloneDeep, cloneDeepWith, evolve, findKey, flattenObject, invert, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, toCamelCaseKeys, toMerged, toSnakeCaseKeys };
|