es-toolkit 1.10.1 → 1.11.0-dev.261
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/CHANGELOG.md +33 -0
- package/compat.d.ts +1 -0
- package/dist/array/chunk.mjs +1 -1
- package/dist/array/compact.mjs +1 -1
- package/dist/array/countBy.mjs +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceBy.mjs +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/drop.js +1 -0
- package/dist/array/drop.js.map +1 -1
- package/dist/array/drop.mjs +2 -2
- package/dist/array/dropRight.js +5 -1
- package/dist/array/dropRight.js.map +1 -1
- package/dist/array/dropRight.mjs +2 -2
- package/dist/array/dropRightWhile.js +6 -14
- package/dist/array/dropRightWhile.js.map +1 -1
- package/dist/array/dropRightWhile.mjs +2 -3
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/fill.d.mts +10 -7
- package/dist/array/fill.d.ts +10 -7
- package/dist/array/fill.js +7 -6
- package/dist/array/fill.js.map +1 -1
- package/dist/array/fill.mjs +2 -2
- package/dist/array/flatMap.d.mts +23 -0
- package/dist/array/flatMap.d.ts +23 -0
- package/dist/array/flatMap.js +52 -0
- package/dist/array/flatMap.js.map +1 -0
- package/dist/array/flatMap.mjs +9 -0
- package/dist/array/flatten.mjs +1 -1
- package/dist/array/flattenDeep.mjs +1 -1
- package/dist/array/forEachRight.mjs +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/head.mjs +1 -1
- package/dist/array/index.d.mts +1 -0
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.js +30 -14
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +41 -37
- package/dist/array/initial.mjs +1 -1
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/intersectionBy.mjs +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/keyBy.mjs +1 -1
- package/dist/array/last.mjs +1 -1
- package/dist/array/maxBy.mjs +1 -1
- package/dist/array/minBy.mjs +1 -1
- package/dist/array/orderBy.mjs +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/sample.mjs +1 -1
- package/dist/array/sampleSize.mjs +1 -1
- package/dist/array/shuffle.mjs +1 -1
- package/dist/array/tail.mjs +1 -1
- package/dist/array/take.mjs +1 -1
- package/dist/array/takeRight.mjs +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/toFilled.mjs +1 -1
- package/dist/array/union.mjs +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.mjs +1 -1
- package/dist/array/uniq.mjs +1 -1
- package/dist/array/uniqBy.d.mts +1 -1
- package/dist/array/uniqBy.d.ts +1 -1
- package/dist/array/uniqBy.js.map +1 -1
- package/dist/array/uniqBy.mjs +2 -2
- package/dist/array/uniqWith.mjs +1 -1
- package/dist/array/unzip.mjs +1 -1
- package/dist/array/unzipWith.mjs +1 -1
- package/dist/array/without.mjs +1 -1
- package/dist/array/xor.mjs +1 -1
- package/dist/array/xorBy.mjs +1 -1
- package/dist/array/xorWith.mjs +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipObject.mjs +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/{chunk-S3CORED5.mjs → chunk-3EZAFZG3.mjs} +2 -1
- package/dist/{chunk-S3CORED5.mjs.map → chunk-3EZAFZG3.mjs.map} +1 -1
- package/dist/{chunk-2MM5EJJX.mjs → chunk-424M7IR7.mjs} +23 -2
- package/dist/chunk-4OIZM4HS.mjs +1 -0
- package/dist/{chunk-GDC64SYJ.mjs → chunk-5ASRKEB4.mjs} +1 -1
- package/dist/{chunk-GDC64SYJ.mjs.map → chunk-5ASRKEB4.mjs.map} +1 -1
- package/dist/{chunk-OXAZEEGP.mjs → chunk-B4COTK4K.mjs} +1 -1
- package/dist/{chunk-OXAZEEGP.mjs.map → chunk-B4COTK4K.mjs.map} +1 -1
- package/dist/chunk-DDH7K4QM.mjs +1 -0
- package/dist/chunk-F47GLYUU.mjs +1 -0
- package/dist/chunk-J3GE7DEU.mjs +22 -0
- package/dist/chunk-J3GE7DEU.mjs.map +1 -0
- package/dist/chunk-KIOYQRMQ.mjs +12 -0
- package/dist/chunk-KIOYQRMQ.mjs.map +1 -0
- package/dist/chunk-M7SBBYV2.mjs +14 -0
- package/dist/chunk-M7SBBYV2.mjs.map +1 -0
- package/dist/{chunk-IZAD2S7R.mjs → chunk-MY4G7R3I.mjs} +2 -2
- package/dist/{chunk-74WWMNZS.mjs → chunk-OLX53VEF.mjs} +4 -2
- package/dist/{chunk-74WWMNZS.mjs.map → chunk-OLX53VEF.mjs.map} +1 -1
- package/dist/chunk-OXZCMC5I.mjs +13 -0
- package/dist/{chunk-JEKUA56R.mjs.map → chunk-OXZCMC5I.mjs.map} +1 -1
- package/dist/chunk-QXTNZR7B.mjs +25 -0
- package/dist/chunk-QXTNZR7B.mjs.map +1 -0
- package/dist/{chunk-QZITBKWX.mjs → chunk-U7V3G7CR.mjs} +2 -2
- package/dist/chunk-UY76KTPE.mjs +13 -0
- package/dist/chunk-UY76KTPE.mjs.map +1 -0
- package/dist/chunk-XT74R35S.mjs +1 -0
- package/dist/chunk-XT74R35S.mjs.map +1 -0
- package/dist/chunk-XWPCDIFC.mjs +18 -0
- package/dist/chunk-XWPCDIFC.mjs.map +1 -0
- package/dist/chunk-YFN6KOC4.mjs +15 -0
- package/dist/chunk-YFN6KOC4.mjs.map +1 -0
- package/dist/compat/index.d.mts +360 -1
- package/dist/compat/index.d.ts +360 -1
- package/dist/compat/index.js +240 -15
- package/dist/compat/index.js.map +1 -1
- package/dist/compat/index.mjs +235 -82
- package/dist/compat/index.mjs.map +1 -1
- package/dist/error/AbortError.mjs +1 -1
- package/dist/error/TimeoutError.d.mts +9 -0
- package/dist/error/TimeoutError.d.ts +9 -0
- package/dist/error/TimeoutError.js +36 -0
- package/dist/error/TimeoutError.js.map +1 -0
- package/dist/error/TimeoutError.mjs +8 -0
- package/dist/error/TimeoutError.mjs.map +1 -0
- package/dist/error/index.d.mts +1 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +12 -2
- package/dist/error/index.js.map +1 -1
- package/dist/error/index.mjs +7 -3
- package/dist/function/debounce.mjs +1 -1
- package/dist/function/index.mjs +4 -4
- package/dist/function/negate.mjs +1 -1
- package/dist/function/noop.mjs +1 -1
- package/dist/function/once.mjs +1 -1
- package/dist/function/throttle.mjs +1 -1
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +99 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -82
- package/dist/math/clamp.mjs +1 -1
- package/dist/math/inRange.mjs +1 -1
- package/dist/math/index.js.map +1 -1
- package/dist/math/index.mjs +12 -12
- package/dist/math/mean.d.mts +1 -1
- package/dist/math/mean.d.ts +1 -1
- package/dist/math/mean.js.map +1 -1
- package/dist/math/mean.mjs +2 -2
- package/dist/math/meanBy.js.map +1 -1
- package/dist/math/meanBy.mjs +3 -3
- package/dist/math/random.mjs +1 -1
- package/dist/math/randomInt.mjs +1 -1
- package/dist/math/range.mjs +1 -1
- package/dist/math/round.mjs +1 -1
- package/dist/math/sum.mjs +1 -1
- package/dist/math/sumBy.mjs +1 -1
- package/dist/object/clone.mjs +1 -1
- package/dist/object/index.js +3 -1
- package/dist/object/index.js.map +1 -1
- package/dist/object/index.mjs +6 -6
- package/dist/object/invert.js +3 -1
- package/dist/object/invert.js.map +1 -1
- package/dist/object/invert.mjs +2 -2
- package/dist/object/omit.mjs +2 -2
- package/dist/object/omitBy.mjs +1 -1
- package/dist/object/pick.mjs +1 -1
- package/dist/object/pickBy.mjs +1 -1
- package/dist/predicate/index.mjs +1 -1
- package/dist/predicate/isEqual.mjs +1 -1
- package/dist/predicate/isNil.mjs +1 -1
- package/dist/predicate/isNotNil.mjs +1 -1
- package/dist/predicate/isNull.mjs +1 -1
- package/dist/predicate/isUndefined.mjs +1 -1
- package/dist/promise/delay.mjs +1 -1
- package/dist/promise/index.d.mts +1 -0
- package/dist/promise/index.d.ts +1 -0
- package/dist/promise/index.js +47 -2
- package/dist/promise/index.js.map +1 -1
- package/dist/promise/index.mjs +9 -3
- package/dist/promise/timeout.d.mts +10 -0
- package/dist/promise/timeout.d.ts +10 -0
- package/dist/promise/timeout.js +92 -0
- package/dist/promise/timeout.js.map +1 -0
- package/dist/promise/timeout.mjs +11 -0
- package/dist/promise/timeout.mjs.map +1 -0
- package/dist/promise/withTimeout.d.mts +22 -0
- package/dist/promise/withTimeout.d.ts +22 -0
- package/dist/promise/withTimeout.js +99 -0
- package/dist/promise/withTimeout.js.map +1 -0
- package/dist/promise/withTimeout.mjs +12 -0
- package/dist/promise/withTimeout.mjs.map +1 -0
- package/dist/string/camelCase.mjs +1 -1
- package/dist/string/capitalize.mjs +1 -1
- package/dist/string/index.d.mts +1 -0
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.js +21 -2
- package/dist/string/index.js.map +1 -1
- package/dist/string/index.mjs +13 -9
- package/dist/string/kebabCase.mjs +1 -1
- package/dist/string/lowerCase.mjs +1 -1
- package/dist/string/snakeCase.mjs +1 -1
- package/dist/string/startCase.d.mts +16 -0
- package/dist/string/startCase.d.ts +16 -0
- package/dist/string/startCase.js +54 -0
- package/dist/string/startCase.js.map +1 -0
- package/dist/string/startCase.mjs +9 -0
- package/dist/string/startCase.mjs.map +1 -0
- package/package.json +3 -5
- package/dist/chunk-2MRZANXZ.mjs +0 -1
- package/dist/chunk-ARZ5BDR6.mjs +0 -1
- package/dist/chunk-C4WE4GLC.mjs +0 -14
- package/dist/chunk-C4WE4GLC.mjs.map +0 -1
- package/dist/chunk-FZEZH22H.mjs +0 -1
- package/dist/chunk-JE6JKZU3.mjs +0 -15
- package/dist/chunk-JE6JKZU3.mjs.map +0 -1
- package/dist/chunk-JEKUA56R.mjs +0 -9
- package/dist/chunk-QKYYOLJ6.mjs +0 -1
- /package/dist/{chunk-2MM5EJJX.mjs.map → array/flatMap.mjs.map} +0 -0
- /package/dist/{chunk-2MRZANXZ.mjs.map → chunk-424M7IR7.mjs.map} +0 -0
- /package/dist/{chunk-ARZ5BDR6.mjs.map → chunk-4OIZM4HS.mjs.map} +0 -0
- /package/dist/{chunk-FZEZH22H.mjs.map → chunk-DDH7K4QM.mjs.map} +0 -0
- /package/dist/{chunk-QKYYOLJ6.mjs.map → chunk-F47GLYUU.mjs.map} +0 -0
- /package/dist/{chunk-IZAD2S7R.mjs.map → chunk-MY4G7R3I.mjs.map} +0 -0
- /package/dist/{chunk-QZITBKWX.mjs.map → chunk-U7V3G7CR.mjs.map} +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/array/fill.ts
|
|
2
|
+
function fill(array, value, start = 0, end = array.length) {
|
|
3
|
+
const length = array.length;
|
|
4
|
+
const finalStart = Math.max(start >= 0 ? start : length + start, 0);
|
|
5
|
+
const finalEnd = Math.min(end >= 0 ? end : length + end, length);
|
|
6
|
+
for (let i = finalStart; i < finalEnd; i++) {
|
|
7
|
+
array[i] = value;
|
|
8
|
+
}
|
|
9
|
+
return array;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
fill
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-YFN6KOC4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/array/fill.ts"],"sourcesContent":["/**\n * Fills elements of an array with a specified value from the start position up to, but not including, the end position.\n *\n * This function mutates the original array and replaces its elements with the provided value, starting from the specified\n * start index up to the end index (non-inclusive). If the start or end indices are not provided, it defaults to filling the\n * entire array.\n *\n * @param {Array<T | U>} array - The array to fill.\n * @param {U} value - The value to fill the array with.\n * @param {number} [start=0] - The start position. Defaults to 0.\n * @param {number} [end=arr.length] - The end position. Defaults to the array's length.\n * @returns {Array<T | U>} The array with the filled values.\n *\n * @example\n * const array = [1, 2, 3];\n * const result = fill(array, 'a');\n * // => ['a', 'a', 'a']\n *\n * const result = fill(Array(3), 2);\n * // => [2, 2, 2]\n *\n * const result = fill([4, 6, 8, 10], '*', 1, 3);\n * // => [4, '*', '*', 10]\n *\n * const result = fill(array, '*', -2, -1);\n * // => [1, '*', 3]\n */\nexport function fill<T>(array: unknown[], value: T): T[];\nexport function fill<T, U>(array: Array<T | U>, value: U, start: number): Array<T | U>;\nexport function fill<T, U>(array: Array<T | U>, value: U, start: number, end: number): Array<T | U>;\nexport function fill<T, U>(array: Array<T | U>, value: U, start = 0, end = array.length): Array<T | U> {\n const length = array.length;\n const finalStart = Math.max(start >= 0 ? start : length + start, 0);\n const finalEnd = Math.min(end >= 0 ? end : length + end, length);\n\n for (let i = finalStart; i < finalEnd; i++) {\n array[i] = value;\n }\n\n return array;\n}\n"],"mappings":";AA8BO,SAAS,KAAW,OAAqB,OAAU,QAAQ,GAAG,MAAM,MAAM,QAAsB;AACrG,QAAM,SAAS,MAAM;AACrB,QAAM,aAAa,KAAK,IAAI,SAAS,IAAI,QAAQ,SAAS,OAAO,CAAC;AAClE,QAAM,WAAW,KAAK,IAAI,OAAO,IAAI,MAAM,SAAS,KAAK,MAAM;AAE/D,WAAS,IAAI,YAAY,IAAI,UAAU,KAAK;AAC1C,UAAM,CAAC,IAAI;AAAA,EACb;AAEA,SAAO;AACT;","names":[]}
|
package/dist/compat/index.d.mts
CHANGED
|
@@ -8,6 +8,7 @@ export { dropRight } from '../array/dropRight.mjs';
|
|
|
8
8
|
export { dropRightWhile } from '../array/dropRightWhile.mjs';
|
|
9
9
|
export { dropWhile } from '../array/dropWhile.mjs';
|
|
10
10
|
export { fill } from '../array/fill.mjs';
|
|
11
|
+
export { flatMap } from '../array/flatMap.mjs';
|
|
11
12
|
export { flatten } from '../array/flatten.mjs';
|
|
12
13
|
export { flattenDeep } from '../array/flattenDeep.mjs';
|
|
13
14
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
@@ -48,6 +49,7 @@ export { toFilled } from '../array/toFilled.mjs';
|
|
|
48
49
|
export { last } from '../array/last.mjs';
|
|
49
50
|
export { initial } from '../array/initial.mjs';
|
|
50
51
|
export { AbortError } from '../error/AbortError.mjs';
|
|
52
|
+
export { TimeoutError } from '../error/TimeoutError.mjs';
|
|
51
53
|
export { debounce } from '../function/debounce.mjs';
|
|
52
54
|
export { noop } from '../function/noop.mjs';
|
|
53
55
|
export { once } from '../function/once.mjs';
|
|
@@ -75,10 +77,12 @@ export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
|
75
77
|
export { isNull } from '../predicate/isNull.mjs';
|
|
76
78
|
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
77
79
|
export { delay } from '../promise/delay.mjs';
|
|
80
|
+
export { withTimeout } from '../promise/withTimeout.mjs';
|
|
78
81
|
export { camelCase } from '../string/camelCase.mjs';
|
|
79
82
|
export { snakeCase } from '../string/snakeCase.mjs';
|
|
80
83
|
export { kebabCase } from '../string/kebabCase.mjs';
|
|
81
84
|
export { lowerCase } from '../string/lowerCase.mjs';
|
|
85
|
+
export { startCase } from '../string/startCase.mjs';
|
|
82
86
|
export { capitalize } from '../string/capitalize.mjs';
|
|
83
87
|
|
|
84
88
|
/**
|
|
@@ -106,4 +110,359 @@ export { capitalize } from '../string/capitalize.mjs';
|
|
|
106
110
|
*/
|
|
107
111
|
declare function chunk<T>(arr: readonly T[], size?: number): T[][];
|
|
108
112
|
|
|
109
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Creates a deeply nested object given arrays of paths and values.
|
|
115
|
+
*
|
|
116
|
+
* This function takes two arrays: one containing arrays of property paths, and the other containing corresponding values.
|
|
117
|
+
* It returns a new object where paths from the first array are used as key paths to set values, with corresponding elements from the second array as values.
|
|
118
|
+
* Paths can be dot-separated strings or arrays of property names.
|
|
119
|
+
*
|
|
120
|
+
* If the `keys` array is longer than the `values` array, the remaining keys will have `undefined` as their values.
|
|
121
|
+
*
|
|
122
|
+
* @template V - The type of elements in the array.
|
|
123
|
+
* @param {string[] | string[][]} keys - An array of property paths, each path can be a dot-separated string or an array of property names.
|
|
124
|
+
* @param {V[]} values - An array of values corresponding to the property paths.
|
|
125
|
+
* @returns {object} A new object composed of the given property paths and values.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* const paths = ['a.b.c', 'd.e.f'];
|
|
129
|
+
* const values = [1, 2];
|
|
130
|
+
* const result = zipObjectDeep(paths, values);
|
|
131
|
+
* // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* const paths = [['a', 'b', 'c'], ['d', 'e', 'f']];
|
|
135
|
+
* const values = [1, 2];
|
|
136
|
+
* const result = zipObjectDeep(paths, values);
|
|
137
|
+
* // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* const paths = ['a.b[0].c', 'a.b[1].d'];
|
|
141
|
+
* const values = [1, 2];
|
|
142
|
+
* const result = zipObjectDeep(paths, values);
|
|
143
|
+
* // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
|
|
144
|
+
*/
|
|
145
|
+
declare function zipObjectDeep<P extends string | number | symbol, V>(keys: P[], values: V[]): {
|
|
146
|
+
[K in P]: V;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* See the definition of `@types/lodash`.
|
|
151
|
+
*/
|
|
152
|
+
type GetIndexedField<T, K> = K extends keyof T ? T[K] : K extends `${number}` ? 'length' extends keyof T ? number extends T['length'] ? number extends keyof T ? T[number] : undefined : undefined : undefined : undefined;
|
|
153
|
+
type FieldWithPossiblyUndefined<T, Key> = Get<Exclude<T, undefined>, Key> | Extract<T, undefined>;
|
|
154
|
+
type IndexedFieldWithPossiblyUndefined<T, Key> = GetIndexedField<Exclude<T, undefined>, Key> | Extract<T, undefined>;
|
|
155
|
+
type Get<T, P> = P extends `${infer Left}.${infer Right}` ? Left extends keyof Exclude<T, undefined> ? FieldWithPossiblyUndefined<Exclude<T, undefined>[Left], Right> | Extract<T, undefined> : Left extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? FieldWithPossiblyUndefined<IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey>, Right> : undefined : undefined : P extends keyof T ? T[P] : P extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? IndexedFieldWithPossiblyUndefined<T[FieldKey], IndexKey> : undefined : IndexedFieldWithPossiblyUndefined<T, P>;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
159
|
+
*
|
|
160
|
+
* @template T - The type of the object.
|
|
161
|
+
* @template K - The type of the key in the object.
|
|
162
|
+
* @template D - The type of the default value.
|
|
163
|
+
*
|
|
164
|
+
* @param {T} object - The object to query.
|
|
165
|
+
* @param {K | [K]} path - The path of the property to get.
|
|
166
|
+
* @returns {T[K]} - Returns the resolved value.
|
|
167
|
+
*/
|
|
168
|
+
declare function get<T extends object, K extends keyof T>(object: T, path: K | [K]): T[K];
|
|
169
|
+
/**
|
|
170
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
171
|
+
*
|
|
172
|
+
* @template T - The type of the object.
|
|
173
|
+
* @template K - The type of the key in the object.
|
|
174
|
+
*
|
|
175
|
+
* @param {T | null | undefined} object - The object to query.
|
|
176
|
+
* @param {K | [K]} path - The path of the property to get.
|
|
177
|
+
* @returns {T[K] | undefined} - Returns the resolved value.
|
|
178
|
+
*/
|
|
179
|
+
declare function get<T extends object, K extends keyof T>(object: T | null | undefined, path: K | [K]): T[K] | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
182
|
+
*
|
|
183
|
+
* @template T - The type of the object.
|
|
184
|
+
* @template K - The type of the key in the object.
|
|
185
|
+
* @template D - The type of the default value.
|
|
186
|
+
*
|
|
187
|
+
* @param {T | null | undefined} object - The object to query.
|
|
188
|
+
* @param {K | [K]} path - The path of the property to get.
|
|
189
|
+
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
190
|
+
* @returns {Exclude<T[K], undefined> | D} - Returns the resolved value.
|
|
191
|
+
*/
|
|
192
|
+
declare function get<T extends object, K extends keyof T, D>(object: T | null | undefined, path: K | [K], defaultValue: D): Exclude<T[K], undefined> | D;
|
|
193
|
+
/**
|
|
194
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
195
|
+
*
|
|
196
|
+
* @template T - The type of the object.
|
|
197
|
+
* @template K1 - The type of the first key in the object.
|
|
198
|
+
* @template K2 - The type of the second key in the object.
|
|
199
|
+
*
|
|
200
|
+
* @param {T} object - The object to query.
|
|
201
|
+
* @param {[K1, K2]} path - The path of the property to get.
|
|
202
|
+
* @returns {T[K1][K2]} - Returns the resolved value.
|
|
203
|
+
*/
|
|
204
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T, path: [K1, K2]): T[K1][K2];
|
|
205
|
+
/**
|
|
206
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
207
|
+
*
|
|
208
|
+
* @template T - The type of the object.
|
|
209
|
+
* @template K1 - The type of the first key in the object.
|
|
210
|
+
* @template K2 - The type of the second key in the object.
|
|
211
|
+
*
|
|
212
|
+
* @param {T | null | undefined} object - The object to query.
|
|
213
|
+
* @param {[K1, K2]} path - The path of the property to get.
|
|
214
|
+
* @returns {T[K1][K2] | undefined} - Returns the resolved value.
|
|
215
|
+
*/
|
|
216
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(object: T | null | undefined, path: [K1, K2]): T[K1][K2] | undefined;
|
|
217
|
+
/**
|
|
218
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
219
|
+
*
|
|
220
|
+
* @template T - The type of the object.
|
|
221
|
+
* @template K1 - The type of the first key in the object.
|
|
222
|
+
* @template K2 - The type of the second key in the object.
|
|
223
|
+
* @template D - The type of the default value.
|
|
224
|
+
*
|
|
225
|
+
* @param {T | null | undefined} object - The object to query.
|
|
226
|
+
* @param {[K1, K2]} path - The path of the property to get.
|
|
227
|
+
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
228
|
+
* @returns {Exclude<T[K1][K2], undefined> | D} - Returns the resolved value.
|
|
229
|
+
*/
|
|
230
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], D>(object: T | null | undefined, path: [K1, K2], defaultValue: D): Exclude<T[K1][K2], undefined> | D;
|
|
231
|
+
/**
|
|
232
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
233
|
+
*
|
|
234
|
+
* @template T - The type of the object.
|
|
235
|
+
* @template K1 - The type of the first key in the object.
|
|
236
|
+
* @template K2 - The type of the second key in the object.
|
|
237
|
+
* @template K3 - The type of the third key in the object.
|
|
238
|
+
*
|
|
239
|
+
* @param {T} object - The object to query.
|
|
240
|
+
* @param {[K1, K2, K3]} path - The path of the property to get.
|
|
241
|
+
* @returns {T[K1][K2][K3]} - Returns the resolved value.
|
|
242
|
+
*/
|
|
243
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T, path: [K1, K2, K3]): T[K1][K2][K3];
|
|
244
|
+
/**
|
|
245
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
246
|
+
*
|
|
247
|
+
* @template T - The type of the object.
|
|
248
|
+
* @template K1 - The type of the first key in the object.
|
|
249
|
+
* @template K2 - The type of the second key in the object.
|
|
250
|
+
* @template K3 - The type of the third key in the object.
|
|
251
|
+
*
|
|
252
|
+
* @param {T | null | undefined} object - The object to query.
|
|
253
|
+
* @param {[K1, K2, K3]} path - The path of the property to get.
|
|
254
|
+
* @returns {T[K1][K2][K3] | undefined} - Returns the resolved value.
|
|
255
|
+
*/
|
|
256
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(object: T | null | undefined, path: [K1, K2, K3]): T[K1][K2][K3] | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
259
|
+
*
|
|
260
|
+
* @template T - The type of the object.
|
|
261
|
+
* @template K1 - The type of the first key in the object.
|
|
262
|
+
* @template K2 - The type of the second key in the object.
|
|
263
|
+
* @template K3 - The type of the third key in the object.
|
|
264
|
+
* @template D - The type of the default value.
|
|
265
|
+
*
|
|
266
|
+
* @param {T | null | undefined} object - The object to query.
|
|
267
|
+
* @param {[K1, K2, K3]} path - The path of the property to get.
|
|
268
|
+
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
269
|
+
* @returns {Exclude<T[K1][K2][K3], undefined> | D} - Returns the resolved value.
|
|
270
|
+
*/
|
|
271
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], D>(object: T | null | undefined, path: [K1, K2, K3], defaultValue: D): Exclude<T[K1][K2][K3], undefined> | D;
|
|
272
|
+
/**
|
|
273
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
274
|
+
*
|
|
275
|
+
* @template T - The type of the object.
|
|
276
|
+
* @template K1 - The type of the first key in the object.
|
|
277
|
+
* @template K2 - The type of the second key in the object.
|
|
278
|
+
* @template K3 - The type of the third key in the object.
|
|
279
|
+
* @template K4 - The type of the fourth key in the object.
|
|
280
|
+
*
|
|
281
|
+
* @param {T} object - The object to query.
|
|
282
|
+
* @param {[K1, K2, K3, K4]} path - The path of the property to get.
|
|
283
|
+
* @returns {T[K1][K2][K3][K4]} - Returns the resolved value.
|
|
284
|
+
*/
|
|
285
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4];
|
|
286
|
+
/**
|
|
287
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
288
|
+
*
|
|
289
|
+
* @template T - The type of the object.
|
|
290
|
+
* @template K1 - The type of the first key in the object.
|
|
291
|
+
* @template K2 - The type of the second key in the object.
|
|
292
|
+
* @template K3 - The type of the third key in the object.
|
|
293
|
+
* @template K4 - The type of the fourth key in the object.
|
|
294
|
+
*
|
|
295
|
+
* @param {T | null | undefined} object - The object to query.
|
|
296
|
+
* @param {[K1, K2, K3, K4]} path - The path of the property to get.
|
|
297
|
+
* @returns {T[K1][K2][K3][K4] | undefined} - Returns the resolved value.
|
|
298
|
+
*/
|
|
299
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3]>(object: T | null | undefined, path: [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined;
|
|
300
|
+
/**
|
|
301
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
302
|
+
*
|
|
303
|
+
* @template T - The type of the object.
|
|
304
|
+
* @template K1 - The type of the first key in the object.
|
|
305
|
+
* @template K2 - The type of the second key in the object.
|
|
306
|
+
* @template K3 - The type of the third key in the object.
|
|
307
|
+
* @template K4 - The type of the fourth key in the object.
|
|
308
|
+
* @template D - The type of the default value.
|
|
309
|
+
*
|
|
310
|
+
* @param {T | null | undefined} object - The object to query.
|
|
311
|
+
* @param {[K1, K2, K3, K4]} path - The path of the property to get.
|
|
312
|
+
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
313
|
+
* @returns {Exclude<T[K1][K2][K3][K4], undefined> | D} - Returns the resolved value.
|
|
314
|
+
*/
|
|
315
|
+
declare function get<T extends object, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2], K4 extends keyof T[K1][K2][K3], D>(object: T | null | undefined, path: [K1, K2, K3, K4], defaultValue: D): Exclude<T[K1][K2][K3][K4], undefined> | D;
|
|
316
|
+
/**
|
|
317
|
+
* Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
|
|
318
|
+
*
|
|
319
|
+
* @template T - The type of the value.
|
|
320
|
+
*
|
|
321
|
+
* @param {Record<number, T>} object - The object to query.
|
|
322
|
+
* @param {number} path - The path of the property to get.
|
|
323
|
+
* @returns {T} - Returns the resolved value.
|
|
324
|
+
*/
|
|
325
|
+
declare function get<T>(object: Record<number, T>, path: number): T;
|
|
326
|
+
/**
|
|
327
|
+
* Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
|
|
328
|
+
*
|
|
329
|
+
* @template T - The type of the value.
|
|
330
|
+
*
|
|
331
|
+
* @param {Record<number, T> | null | undefined} object - The object to query.
|
|
332
|
+
* @param {number} path - The path of the property to get.
|
|
333
|
+
* @returns {T | undefined} - Returns the resolved value.
|
|
334
|
+
*/
|
|
335
|
+
declare function get<T>(object: Record<number, T> | null | undefined, path: number): T | undefined;
|
|
336
|
+
/**
|
|
337
|
+
* Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead.
|
|
338
|
+
*
|
|
339
|
+
* @template T - The type of the value.
|
|
340
|
+
* @template D - The type of the default value.
|
|
341
|
+
*
|
|
342
|
+
* @param {Record<number, T> | null | undefined} object - The object to query.
|
|
343
|
+
* @param {number} path - The path of the property to get.
|
|
344
|
+
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
345
|
+
* @returns {T | D} - Returns the resolved value.
|
|
346
|
+
*/
|
|
347
|
+
declare function get<T, D>(object: Record<number, T> | null | undefined, path: number, defaultValue: D): T | D;
|
|
348
|
+
/**
|
|
349
|
+
* Retrieves the value at a given path from a null or undefined object, returning the default value.
|
|
350
|
+
*
|
|
351
|
+
* @template D - The type of the default value.
|
|
352
|
+
*
|
|
353
|
+
* @param {null | undefined} object - The object to query.
|
|
354
|
+
* @param {PropertyKey} path - The path of the property to get.
|
|
355
|
+
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
356
|
+
* @returns {D} - Returns the default value.
|
|
357
|
+
*/
|
|
358
|
+
declare function get<D>(object: null | undefined, path: PropertyKey, defaultValue: D): D;
|
|
359
|
+
/**
|
|
360
|
+
* Retrieves the value at a given path from a null or undefined object, returning undefined.
|
|
361
|
+
*
|
|
362
|
+
* @param {null | undefined} object - The object to query.
|
|
363
|
+
* @param {PropertyKey} path - The path of the property to get.
|
|
364
|
+
* @returns {undefined} - Returns undefined.
|
|
365
|
+
*/
|
|
366
|
+
declare function get(object: null | undefined, path: PropertyKey): undefined;
|
|
367
|
+
/**
|
|
368
|
+
* Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
369
|
+
*
|
|
370
|
+
* @template T - The type of the object.
|
|
371
|
+
* @template P - The type of the path.
|
|
372
|
+
*
|
|
373
|
+
* @param {T} data - The object to query.
|
|
374
|
+
* @param {P} path - The path of the property to get.
|
|
375
|
+
* @returns {string extends P ? any : Get<T, P>} - Returns the resolved value.
|
|
376
|
+
*/
|
|
377
|
+
declare function get<T, P extends string>(data: T, path: P): string extends P ? any : Get<T, P>;
|
|
378
|
+
/**
|
|
379
|
+
* Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
380
|
+
*
|
|
381
|
+
* @template T - The type of the object.
|
|
382
|
+
* @template P - The type of the path.
|
|
383
|
+
* @template D - The type of the default value.
|
|
384
|
+
*
|
|
385
|
+
* @param {T} data - The object to query.
|
|
386
|
+
* @param {P} path - The path of the property to get.
|
|
387
|
+
* @param {D} defaultValue - The value returned if the resolved value is undefined.
|
|
388
|
+
* @returns {Exclude<Get<T, P>, null | undefined> | D} - Returns the resolved value.
|
|
389
|
+
*/
|
|
390
|
+
declare function get<T, P extends string, D = Get<T, P>>(data: T, path: P, defaultValue: D): Exclude<Get<T, P>, null | undefined> | D;
|
|
391
|
+
/**
|
|
392
|
+
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
393
|
+
*
|
|
394
|
+
* @param {unknown} object - The object to query.
|
|
395
|
+
* @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to get.
|
|
396
|
+
* @param {unknown} [defaultValue] - The value returned if the resolved value is undefined.
|
|
397
|
+
* @returns {any} - Returns the resolved value.
|
|
398
|
+
*/
|
|
399
|
+
declare function get(object: unknown, path: PropertyKey | readonly PropertyKey[], defaultValue?: unknown): any;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.
|
|
403
|
+
*
|
|
404
|
+
* @template T - The type of the object.
|
|
405
|
+
* @param {Settable} obj - The object to modify.
|
|
406
|
+
* @param {Path} path - The path of the property to set.
|
|
407
|
+
* @param {any} value - The value to set.
|
|
408
|
+
* @returns {T} - The modified object.
|
|
409
|
+
*
|
|
410
|
+
* @example
|
|
411
|
+
* // Set a value in a nested object
|
|
412
|
+
* const obj = { a: { b: { c: 3 } } };
|
|
413
|
+
* set(obj, 'a.b.c', 4);
|
|
414
|
+
* console.log(obj.a.b.c); // 4
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* // Set a value in an array
|
|
418
|
+
* const arr = [1, 2, 3];
|
|
419
|
+
* set(arr, 1, 4);
|
|
420
|
+
* console.log(arr[1]); // 4
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* // Create non-existent path and set value
|
|
424
|
+
* const obj = {};
|
|
425
|
+
* set(obj, 'a.b.c', 4);
|
|
426
|
+
* console.log(obj); // { a: { b: { c: 4 } } }
|
|
427
|
+
*/
|
|
428
|
+
declare function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Checks if a string contains another string at the beginning of the string.
|
|
432
|
+
*
|
|
433
|
+
* Checks if one string startsWith another string. Optional position parameter to start searching from a certain index.
|
|
434
|
+
*
|
|
435
|
+
* @param {string} str - The string that might contain the target string.
|
|
436
|
+
* @param {string} target - The string to search for.
|
|
437
|
+
* @param {number} position - An optional offset to start searching in the str string
|
|
438
|
+
* @returns {boolean} - True if the str string starts with the target string.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* const isPrefix = startsWith('fooBar', 'foo') // returns true
|
|
442
|
+
* const isPrefix = startsWith('fooBar', 'bar') // returns false
|
|
443
|
+
* const isPrefix = startsWith('fooBar', 'abc') // returns false
|
|
444
|
+
* const isPrefix = startsWith('fooBar', 'Bar', 2) // returns true
|
|
445
|
+
* const isPrefix = startsWith('fooBar', 'Bar', 5) // returns false
|
|
446
|
+
*/
|
|
447
|
+
declare const startsWith: (str: string, target: string, position?: number) => boolean;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Checks if a string contains another string at the end of the string.
|
|
451
|
+
*
|
|
452
|
+
* Checks if one string endsWith another string. Optional position parameter to offset searching before a certain index.
|
|
453
|
+
*
|
|
454
|
+
* @param {string} str - The string that might contain the target string.
|
|
455
|
+
* @param {string} target - The string to search for.
|
|
456
|
+
* @param {number} position - An optional position from the start to search up to this index
|
|
457
|
+
* @returns {boolean} - True if the str string ends with the target string.
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* const isPrefix = endsWith('fooBar', 'foo') // returns true
|
|
461
|
+
* const isPrefix = endsWith('fooBar', 'bar') // returns false
|
|
462
|
+
* const isPrefix = endsWith('fooBar', 'abc') // returns false
|
|
463
|
+
* const isPrefix = endsWith('fooBar', 'foo', 3) // returns true
|
|
464
|
+
* const isPrefix = endsWith('fooBar', 'abc', 5) // returns false
|
|
465
|
+
*/
|
|
466
|
+
declare const endsWith: (str: string, target: string, position?: number) => boolean;
|
|
467
|
+
|
|
468
|
+
export { chunk, endsWith, get, set, startsWith, zipObjectDeep };
|