es-toolkit 1.2.1 → 1.2.2-dev.69
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 +8 -0
- package/README.md +1 -1
- package/dist/array/chunk.d.mts +1 -1
- package/dist/array/chunk.d.ts +1 -1
- package/dist/array/chunk.js.map +1 -1
- package/dist/array/chunk.mjs +1 -1
- package/dist/array/difference.d.mts +1 -1
- package/dist/array/difference.d.ts +1 -1
- package/dist/array/difference.js.map +1 -1
- package/dist/array/difference.mjs +1 -1
- package/dist/array/differenceBy.d.mts +1 -1
- package/dist/array/differenceBy.d.ts +1 -1
- package/dist/array/differenceBy.js.map +1 -1
- package/dist/array/differenceBy.mjs +1 -1
- package/dist/array/differenceWith.d.mts +1 -1
- package/dist/array/differenceWith.d.ts +1 -1
- package/dist/array/differenceWith.js.map +1 -1
- package/dist/array/differenceWith.mjs +1 -1
- package/dist/array/drop.d.mts +1 -1
- package/dist/array/drop.d.ts +1 -1
- package/dist/array/drop.js.map +1 -1
- package/dist/array/drop.mjs +1 -1
- package/dist/array/dropRight.d.mts +1 -1
- package/dist/array/dropRight.d.ts +1 -1
- package/dist/array/dropRight.js.map +1 -1
- package/dist/array/dropRight.mjs +1 -1
- package/dist/array/dropRightWhile.d.mts +1 -1
- package/dist/array/dropRightWhile.d.ts +1 -1
- package/dist/array/dropRightWhile.js.map +1 -1
- package/dist/array/dropRightWhile.mjs +2 -2
- package/dist/array/dropWhile.d.mts +1 -1
- package/dist/array/dropWhile.d.ts +1 -1
- package/dist/array/dropWhile.js.map +1 -1
- package/dist/array/dropWhile.mjs +1 -1
- package/dist/array/groupBy.d.mts +1 -1
- package/dist/array/groupBy.d.ts +1 -1
- package/dist/array/groupBy.js.map +1 -1
- package/dist/array/groupBy.mjs +1 -1
- package/dist/array/index.js +5 -14
- package/dist/array/index.js.map +1 -1
- package/dist/array/index.mjs +44 -44
- package/dist/array/intersection.d.mts +1 -1
- package/dist/array/intersection.d.ts +1 -1
- package/dist/array/intersection.js.map +1 -1
- package/dist/array/intersection.mjs +1 -1
- package/dist/array/intersectionBy.d.mts +1 -1
- package/dist/array/intersectionBy.d.ts +1 -1
- package/dist/array/intersectionBy.js +2 -4
- package/dist/array/intersectionBy.js.map +1 -1
- package/dist/array/intersectionBy.mjs +1 -1
- package/dist/array/intersectionWith.d.mts +1 -1
- package/dist/array/intersectionWith.d.ts +1 -1
- package/dist/array/intersectionWith.js.map +1 -1
- package/dist/array/intersectionWith.mjs +1 -1
- package/dist/array/partition.d.mts +1 -1
- package/dist/array/partition.d.ts +1 -1
- package/dist/array/partition.js.map +1 -1
- package/dist/array/partition.mjs +1 -1
- package/dist/array/sample.d.mts +1 -1
- package/dist/array/sample.d.ts +1 -1
- package/dist/array/sample.js.map +1 -1
- package/dist/array/sample.mjs +1 -1
- package/dist/array/shuffle.d.mts +1 -1
- package/dist/array/shuffle.d.ts +1 -1
- package/dist/array/shuffle.js.map +1 -1
- package/dist/array/shuffle.mjs +1 -1
- package/dist/array/take.d.mts +1 -1
- package/dist/array/take.d.ts +1 -1
- package/dist/array/take.js.map +1 -1
- package/dist/array/take.mjs +1 -1
- package/dist/array/takeRight.d.mts +1 -1
- package/dist/array/takeRight.d.ts +1 -1
- package/dist/array/takeRight.js.map +1 -1
- package/dist/array/takeRight.mjs +1 -1
- package/dist/array/takeRightWhile.d.mts +1 -1
- package/dist/array/takeRightWhile.d.ts +1 -1
- package/dist/array/takeRightWhile.js.map +1 -1
- package/dist/array/takeRightWhile.mjs +1 -1
- package/dist/array/takeWhile.d.mts +1 -1
- package/dist/array/takeWhile.d.ts +1 -1
- package/dist/array/takeWhile.js.map +1 -1
- package/dist/array/takeWhile.mjs +1 -1
- package/dist/array/union.d.mts +1 -1
- package/dist/array/union.d.ts +1 -1
- package/dist/array/union.js +1 -8
- package/dist/array/union.js.map +1 -1
- package/dist/array/union.mjs +2 -2
- package/dist/array/unionBy.d.mts +1 -1
- package/dist/array/unionBy.d.ts +1 -1
- package/dist/array/unionBy.js.map +1 -1
- package/dist/array/unionBy.mjs +1 -1
- package/dist/array/unionWith.d.mts +1 -1
- package/dist/array/unionWith.d.ts +1 -1
- package/dist/array/unionWith.js.map +1 -1
- package/dist/array/unionWith.mjs +2 -2
- package/dist/array/uniq.d.mts +1 -1
- package/dist/array/uniq.d.ts +1 -1
- package/dist/array/uniq.js +1 -8
- package/dist/array/uniq.js.map +1 -1
- package/dist/array/uniq.mjs +1 -1
- package/dist/array/uniqBy.d.mts +5 -6
- package/dist/array/uniqBy.d.ts +5 -6
- package/dist/array/uniqBy.js +2 -2
- package/dist/array/uniqBy.js.map +1 -1
- package/dist/array/uniqBy.mjs +2 -2
- package/dist/array/uniqWith.d.mts +3 -4
- package/dist/array/uniqWith.d.ts +3 -4
- package/dist/array/uniqWith.js.map +1 -1
- package/dist/array/uniqWith.mjs +1 -1
- package/dist/array/xor.d.mts +1 -1
- package/dist/array/xor.d.ts +1 -1
- package/dist/array/xor.js +1 -8
- package/dist/array/xor.js.map +1 -1
- package/dist/array/xor.mjs +5 -5
- package/dist/array/xorBy.d.mts +1 -1
- package/dist/array/xorBy.d.ts +1 -1
- package/dist/array/xorBy.js +2 -4
- package/dist/array/xorBy.js.map +1 -1
- package/dist/array/xorBy.mjs +4 -4
- package/dist/array/xorWith.d.mts +1 -1
- package/dist/array/xorWith.d.ts +1 -1
- package/dist/array/xorWith.js.map +1 -1
- package/dist/array/xorWith.mjs +5 -5
- package/dist/array/zip.d.mts +4 -4
- package/dist/array/zip.d.ts +4 -4
- package/dist/array/zip.js.map +1 -1
- package/dist/array/zip.mjs +1 -1
- package/dist/array/zipWith.d.mts +4 -4
- package/dist/array/zipWith.d.ts +4 -4
- package/dist/array/zipWith.js.map +1 -1
- package/dist/array/zipWith.mjs +1 -1
- package/dist/{chunk-LLOAPSQ6.mjs → chunk-2IXFGSUA.mjs} +1 -1
- package/dist/{chunk-LLOAPSQ6.mjs.map → chunk-2IXFGSUA.mjs.map} +1 -1
- package/dist/{chunk-DVRGUUQG.mjs → chunk-2PFDLYQC.mjs} +1 -1
- package/dist/chunk-2PFDLYQC.mjs.map +1 -0
- package/dist/{chunk-AB3DGGY3.mjs → chunk-3KHI4I2X.mjs} +2 -2
- package/dist/{chunk-AB3DGGY3.mjs.map → chunk-3KHI4I2X.mjs.map} +1 -1
- package/dist/{chunk-TF6N37OE.mjs → chunk-5L2V7WD3.mjs} +1 -1
- package/dist/{chunk-TF6N37OE.mjs.map → chunk-5L2V7WD3.mjs.map} +1 -1
- package/dist/{chunk-3GMXDQQQ.mjs → chunk-62EFHAYX.mjs} +4 -4
- package/dist/{chunk-3GMXDQQQ.mjs.map → chunk-62EFHAYX.mjs.map} +1 -1
- package/dist/{chunk-YNRYG5OB.mjs → chunk-7XTQCUMW.mjs} +1 -1
- package/dist/{chunk-YNRYG5OB.mjs.map → chunk-7XTQCUMW.mjs.map} +1 -1
- package/dist/{chunk-25R2U4KM.mjs → chunk-ACFP3XMB.mjs} +1 -1
- package/dist/{chunk-25R2U4KM.mjs.map → chunk-ACFP3XMB.mjs.map} +1 -1
- package/dist/chunk-ASFOKYTY.mjs +13 -0
- package/dist/chunk-ASFOKYTY.mjs.map +1 -0
- package/dist/{chunk-I2NAKQIE.mjs → chunk-DAJZ3JCI.mjs} +2 -2
- package/dist/{chunk-I2NAKQIE.mjs.map → chunk-DAJZ3JCI.mjs.map} +1 -1
- package/dist/{chunk-L25VRQ54.mjs → chunk-DD73BULA.mjs} +1 -1
- package/dist/chunk-DD73BULA.mjs.map +1 -0
- package/dist/{chunk-PHG5JCSW.mjs → chunk-DOOIIHT3.mjs} +1 -1
- package/dist/{chunk-PHG5JCSW.mjs.map → chunk-DOOIIHT3.mjs.map} +1 -1
- package/dist/{chunk-KPG3XQEN.mjs → chunk-DPLJQQFX.mjs} +1 -1
- package/dist/chunk-DPLJQQFX.mjs.map +1 -0
- package/dist/{chunk-OS5PZ4B4.mjs → chunk-E6C5EZQA.mjs} +1 -1
- package/dist/{chunk-OS5PZ4B4.mjs.map → chunk-E6C5EZQA.mjs.map} +1 -1
- package/dist/{chunk-VOAKEOIM.mjs → chunk-E7BJSLIX.mjs} +2 -2
- package/dist/{chunk-VOAKEOIM.mjs.map → chunk-E7BJSLIX.mjs.map} +1 -1
- package/dist/{chunk-MTT7OPUK.mjs → chunk-EW3RT4QW.mjs} +4 -4
- package/dist/{chunk-MTT7OPUK.mjs.map → chunk-EW3RT4QW.mjs.map} +1 -1
- package/dist/{chunk-S3ZF7ZPG.mjs → chunk-FCF2RHPW.mjs} +4 -4
- package/dist/{chunk-S3ZF7ZPG.mjs.map → chunk-FCF2RHPW.mjs.map} +1 -1
- package/dist/{chunk-5NSVMWDQ.mjs → chunk-FQ4K36VD.mjs} +1 -1
- package/dist/{chunk-5NSVMWDQ.mjs.map → chunk-FQ4K36VD.mjs.map} +1 -1
- package/dist/chunk-GNSJP2AB.mjs +10 -0
- package/dist/{chunk-ANJSX6WH.mjs.map → chunk-GNSJP2AB.mjs.map} +1 -1
- package/dist/{chunk-LIXL7PEP.mjs → chunk-JBDGK6X4.mjs} +1 -1
- package/dist/{chunk-LIXL7PEP.mjs.map → chunk-JBDGK6X4.mjs.map} +1 -1
- package/dist/{chunk-6Z2YFKXQ.mjs → chunk-KLJRZJOR.mjs} +1 -1
- package/dist/{chunk-6Z2YFKXQ.mjs.map → chunk-KLJRZJOR.mjs.map} +1 -1
- package/dist/{chunk-HK5OJANS.mjs → chunk-LVWX5B43.mjs} +1 -1
- package/dist/{chunk-HK5OJANS.mjs.map → chunk-LVWX5B43.mjs.map} +1 -1
- package/dist/{chunk-V6LXSPMF.mjs → chunk-LWXZFXY5.mjs} +1 -1
- package/dist/{chunk-V6LXSPMF.mjs.map → chunk-LWXZFXY5.mjs.map} +1 -1
- package/dist/{chunk-SORNYLIU.mjs → chunk-M7UI5ETO.mjs} +1 -1
- package/dist/{chunk-SORNYLIU.mjs.map → chunk-M7UI5ETO.mjs.map} +1 -1
- package/dist/{chunk-4RRRH7OY.mjs → chunk-ME352XO7.mjs} +1 -1
- package/dist/{chunk-4RRRH7OY.mjs.map → chunk-ME352XO7.mjs.map} +1 -1
- package/dist/{chunk-IFCX35BI.mjs → chunk-NTLX2MPV.mjs} +1 -1
- package/dist/{chunk-IFCX35BI.mjs.map → chunk-NTLX2MPV.mjs.map} +1 -1
- package/dist/{chunk-EXU45QAF.mjs → chunk-Q75KEFW5.mjs} +1 -1
- package/dist/{chunk-EXU45QAF.mjs.map → chunk-Q75KEFW5.mjs.map} +1 -1
- package/dist/{chunk-C4IZ7TGA.mjs → chunk-T5FDOBCA.mjs} +1 -1
- package/dist/chunk-T5FDOBCA.mjs.map +1 -0
- package/dist/{chunk-3PFYAKOD.mjs → chunk-VNMVP3DL.mjs} +1 -1
- package/dist/{chunk-3PFYAKOD.mjs.map → chunk-VNMVP3DL.mjs.map} +1 -1
- package/dist/{chunk-L3C6TG2V.mjs → chunk-XDKEPIUV.mjs} +1 -1
- package/dist/{chunk-L3C6TG2V.mjs.map → chunk-XDKEPIUV.mjs.map} +1 -1
- package/dist/chunk-XFCW7XJ4.mjs +9 -0
- package/dist/{chunk-SWPLMJR7.mjs.map → chunk-XFCW7XJ4.mjs.map} +1 -1
- package/dist/function/index.mjs +3 -3
- package/dist/index.js +5 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -73
- package/dist/object/index.mjs +6 -6
- package/package.json +1 -1
- package/dist/chunk-ANJSX6WH.mjs +0 -12
- package/dist/chunk-C4IZ7TGA.mjs.map +0 -1
- package/dist/chunk-DVRGUUQG.mjs.map +0 -1
- package/dist/chunk-JD42XAYW.mjs +0 -13
- package/dist/chunk-JD42XAYW.mjs.map +0 -1
- package/dist/chunk-KPG3XQEN.mjs.map +0 -1
- package/dist/chunk-L25VRQ54.mjs.map +0 -1
- package/dist/chunk-SWPLMJR7.mjs +0 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# es-toolkit Changelog
|
|
2
2
|
|
|
3
|
+
## Version v1.2.2
|
|
4
|
+
|
|
5
|
+
Released on June 13th, 2024.
|
|
6
|
+
|
|
7
|
+
- Add support for `readonly` arrays in array utilities. (https://github.com/toss/es-toolkit/pull/32, [e595e5e](https://github.com/toss/es-toolkit/commit/e595e5e017e1f2cb138b1ad3d708635efc5e289e))
|
|
8
|
+
- Optimize the time complexity of `uniq`. (https://github.com/toss/es-toolkit/pull/40)
|
|
9
|
+
- Optimize the time complexity of `intersectionBy`. (https://github.com/toss/es-toolkit/pull/44)
|
|
10
|
+
|
|
3
11
|
## Version v1.2.1
|
|
4
12
|
|
|
5
13
|
Released on June 13th, 2024.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
# es-toolkit · [](https://github.com/toss/slash/blob/main/LICENSE)
|
|
3
|
+
# es-toolkit · [](https://github.com/toss/slash/blob/main/LICENSE) [](https://codecov.io/gh/toss/es-toolkit)
|
|
4
4
|
|
|
5
5
|
English | [한국어](https://github.com/toss/es-toolkit/blob/main/README-ko_kr.md)
|
|
6
6
|
|
package/dist/array/chunk.d.mts
CHANGED
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
* chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
|
|
22
22
|
* // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
|
|
23
23
|
*/
|
|
24
|
-
declare function chunk<T>(arr: T[], size: number): T[][];
|
|
24
|
+
declare function chunk<T>(arr: readonly T[], size: number): T[][];
|
|
25
25
|
|
|
26
26
|
export { chunk };
|
package/dist/array/chunk.d.ts
CHANGED
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
* chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
|
|
22
22
|
* // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
|
|
23
23
|
*/
|
|
24
|
-
declare function chunk<T>(arr: T[], size: number): T[][];
|
|
24
|
+
declare function chunk<T>(arr: readonly T[], size: number): T[][];
|
|
25
25
|
|
|
26
26
|
export { chunk };
|
package/dist/array/chunk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/chunk.ts"],"sourcesContent":["/**\n * Splits an array into smaller arrays of a specified length.\n *\n * This function takes an input array and divides it into multiple smaller arrays,\n * each of a specified length. If the input array cannot be evenly divided,\n * the final sub-array will contain the remaining elements.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The array to be chunked into smaller arrays.\n * @param {number} size - The size of each smaller array. Must be a positive integer.\n * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.\n * @throws {Error} Throws an error if `size` is not a positive integer.\n *\n * @example\n * // Splits an array of numbers into sub-arrays of length 2\n * chunk([1, 2, 3, 4, 5], 2);\n * // Returns: [[1, 2], [3, 4], [5]]\n *\n * @example\n * // Splits an array of strings into sub-arrays of length 3\n * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);\n * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]\n */\nexport function chunk<T>(arr: T[], size: number): T[][] {\n if (!Number.isInteger(size) || size <= 0) {\n throw new Error('Size must be an integer greater than zero.');\n }\n\n const chunkLength = Math.ceil(arr.length / size);\n const result: T[][] = Array(chunkLength);\n\n for (let index = 0; index < chunkLength; index++) {\n const start = index * size;\n const end = start + size;\n\n result[index] = arr.slice(start, end);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBO,SAAS,MAAS,
|
|
1
|
+
{"version":3,"sources":["../../src/array/chunk.ts"],"sourcesContent":["/**\n * Splits an array into smaller arrays of a specified length.\n *\n * This function takes an input array and divides it into multiple smaller arrays,\n * each of a specified length. If the input array cannot be evenly divided,\n * the final sub-array will contain the remaining elements.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The array to be chunked into smaller arrays.\n * @param {number} size - The size of each smaller array. Must be a positive integer.\n * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.\n * @throws {Error} Throws an error if `size` is not a positive integer.\n *\n * @example\n * // Splits an array of numbers into sub-arrays of length 2\n * chunk([1, 2, 3, 4, 5], 2);\n * // Returns: [[1, 2], [3, 4], [5]]\n *\n * @example\n * // Splits an array of strings into sub-arrays of length 3\n * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);\n * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]\n */\nexport function chunk<T>(arr: readonly T[], size: number): T[][] {\n if (!Number.isInteger(size) || size <= 0) {\n throw new Error('Size must be an integer greater than zero.');\n }\n\n const chunkLength = Math.ceil(arr.length / size);\n const result: T[][] = Array(chunkLength);\n\n for (let index = 0; index < chunkLength; index++) {\n const start = index * size;\n const end = start + size;\n\n result[index] = arr.slice(start, end);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBO,SAAS,MAAS,KAAmB,MAAqB;AAC/D,MAAI,CAAC,OAAO,UAAU,IAAI,KAAK,QAAQ,GAAG;AACxC,UAAM,IAAI,MAAM,4CAA4C;AAAA,EAC9D;AAEA,QAAM,cAAc,KAAK,KAAK,IAAI,SAAS,IAAI;AAC/C,QAAM,SAAgB,MAAM,WAAW;AAEvC,WAAS,QAAQ,GAAG,QAAQ,aAAa,SAAS;AAChD,UAAM,QAAQ,QAAQ;AACtB,UAAM,MAAM,QAAQ;AAEpB,WAAO,KAAK,IAAI,IAAI,MAAM,OAAO,GAAG;AAAA,EACtC;AAEA,SAAO;AACT;","names":[]}
|
package/dist/array/chunk.mjs
CHANGED
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
* const result = difference(array1, array2);
|
|
21
21
|
* // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.
|
|
22
22
|
*/
|
|
23
|
-
declare function difference<T>(firstArr: T[], secondArr: T[]): T[];
|
|
23
|
+
declare function difference<T>(firstArr: readonly T[], secondArr: T[]): T[];
|
|
24
24
|
|
|
25
25
|
export { difference };
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
* const result = difference(array1, array2);
|
|
21
21
|
* // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.
|
|
22
22
|
*/
|
|
23
|
-
declare function difference<T>(firstArr: T[], secondArr: T[]): T[];
|
|
23
|
+
declare function difference<T>(firstArr: readonly T[], secondArr: T[]): T[];
|
|
24
24
|
|
|
25
25
|
export { difference };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/difference.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays.\n *\n * This function takes two arrays and returns a new array containing the elements\n * that are present in the first array but not in the second array. It effectively\n * filters out any elements from the first array that also appear in the second array.\n *\n * @template T\n * @param {T[]} firstArr - The array from which to derive the difference. This is the primary array\n * from which elements will be compared and filtered.\n * @param {T[]} secondArr - The array containing elements to be excluded from the first array.\n * Each element in this array will be checked against the first array, and if a match is found,\n * that element will be excluded from the result.\n * @returns {T[]} A new array containing the elements that are present in the first array but not\n * in the second array.\n *\n * @example\n * const array1 = [1, 2, 3, 4, 5];\n * const array2 = [2, 4];\n * const result = difference(array1, array2);\n * // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.\n */\nexport function difference<T>(firstArr: T[], secondArr: T[]): T[] {\n const secondSet = new Set(secondArr);\n\n return firstArr.filter(item => !secondSet.has(item));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBO,SAAS,WAAc,
|
|
1
|
+
{"version":3,"sources":["../../src/array/difference.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays.\n *\n * This function takes two arrays and returns a new array containing the elements\n * that are present in the first array but not in the second array. It effectively\n * filters out any elements from the first array that also appear in the second array.\n *\n * @template T\n * @param {T[]} firstArr - The array from which to derive the difference. This is the primary array\n * from which elements will be compared and filtered.\n * @param {T[]} secondArr - The array containing elements to be excluded from the first array.\n * Each element in this array will be checked against the first array, and if a match is found,\n * that element will be excluded from the result.\n * @returns {T[]} A new array containing the elements that are present in the first array but not\n * in the second array.\n *\n * @example\n * const array1 = [1, 2, 3, 4, 5];\n * const array2 = [2, 4];\n * const result = difference(array1, array2);\n * // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.\n */\nexport function difference<T>(firstArr: readonly T[], secondArr: T[]): T[] {\n const secondSet = new Set(secondArr);\n\n return firstArr.filter(item => !secondSet.has(item));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBO,SAAS,WAAc,UAAwB,WAAqB;AACzE,QAAM,YAAY,IAAI,IAAI,SAAS;AAEnC,SAAO,SAAS,OAAO,UAAQ,CAAC,UAAU,IAAI,IAAI,CAAC;AACrD;","names":[]}
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
* const result = differenceBy(array1, array2, mapper);
|
|
24
24
|
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
|
|
25
25
|
*/
|
|
26
|
-
declare function differenceBy<T, U>(firstArr: T[], secondArr: T[], mapper: (value: T) => U): T[];
|
|
26
|
+
declare function differenceBy<T, U>(firstArr: readonly T[], secondArr: readonly T[], mapper: (value: T) => U): T[];
|
|
27
27
|
|
|
28
28
|
export { differenceBy };
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
* const result = differenceBy(array1, array2, mapper);
|
|
24
24
|
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
|
|
25
25
|
*/
|
|
26
|
-
declare function differenceBy<T, U>(firstArr: T[], secondArr: T[], mapper: (value: T) => U): T[];
|
|
26
|
+
declare function differenceBy<T, U>(firstArr: readonly T[], secondArr: readonly T[], mapper: (value: T) => U): T[];
|
|
27
27
|
|
|
28
28
|
export { differenceBy };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/differenceBy.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays after mapping their elements through a provided function.\n *\n * This function takes two arrays and a mapper function. It returns a new array containing the elements\n * that are present in the first array but not in the second array, based on the identity calculated\n * by the mapper function.\n *\n * Essentially, it filters out any elements from the first array that, when\n * mapped, match an element in the mapped version of the second array.\n *\n * @template T, U\n * @param {T[]} firstArr - The primary array from which to derive the difference.\n * @param {T[]} secondArr - The array containing elements to be excluded from the first array.\n * @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function\n * is applied to each element in both arrays, and the comparison is made based on the mapped values.\n * @returns {T[]} A new array containing the elements from the first array that do not have a corresponding\n * mapped identity in the second array.\n *\n * @example\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];\n * const array2 = [{ id: 2 }, { id: 4 }];\n * const mapper = item => item.id;\n * const result = differenceBy(array1, array2, mapper);\n * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.\n */\nexport function differenceBy<T, U>(firstArr: T[], secondArr: T[], mapper: (value: T) => U): T[] {\n const mappedSecondSet = new Set(secondArr.map(item => mapper(item)));\n\n return firstArr.filter(item => {\n return !mappedSecondSet.has(mapper(item));\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBO,SAAS,aAAmB,
|
|
1
|
+
{"version":3,"sources":["../../src/array/differenceBy.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays after mapping their elements through a provided function.\n *\n * This function takes two arrays and a mapper function. It returns a new array containing the elements\n * that are present in the first array but not in the second array, based on the identity calculated\n * by the mapper function.\n *\n * Essentially, it filters out any elements from the first array that, when\n * mapped, match an element in the mapped version of the second array.\n *\n * @template T, U\n * @param {T[]} firstArr - The primary array from which to derive the difference.\n * @param {T[]} secondArr - The array containing elements to be excluded from the first array.\n * @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function\n * is applied to each element in both arrays, and the comparison is made based on the mapped values.\n * @returns {T[]} A new array containing the elements from the first array that do not have a corresponding\n * mapped identity in the second array.\n *\n * @example\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];\n * const array2 = [{ id: 2 }, { id: 4 }];\n * const mapper = item => item.id;\n * const result = differenceBy(array1, array2, mapper);\n * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.\n */\nexport function differenceBy<T, U>(firstArr: readonly T[], secondArr: readonly T[], mapper: (value: T) => U): T[] {\n const mappedSecondSet = new Set(secondArr.map(item => mapper(item)));\n\n return firstArr.filter(item => {\n return !mappedSecondSet.has(mapper(item));\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBO,SAAS,aAAmB,UAAwB,WAAyB,QAA8B;AAChH,QAAM,kBAAkB,IAAI,IAAI,UAAU,IAAI,UAAQ,OAAO,IAAI,CAAC,CAAC;AAEnE,SAAO,SAAS,OAAO,UAAQ;AAC7B,WAAO,CAAC,gBAAgB,IAAI,OAAO,IAAI,CAAC;AAAA,EAC1C,CAAC;AACH;","names":[]}
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
20
20
|
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
|
|
21
21
|
*/
|
|
22
|
-
declare function differenceWith<T>(firstArr: T[], secondArr: T[], areItemsEqual: (x: T, y: T) => boolean): T[];
|
|
22
|
+
declare function differenceWith<T>(firstArr: readonly T[], secondArr: readonly T[], areItemsEqual: (x: T, y: T) => boolean): T[];
|
|
23
23
|
|
|
24
24
|
export { differenceWith };
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
20
20
|
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
|
|
21
21
|
*/
|
|
22
|
-
declare function differenceWith<T>(firstArr: T[], secondArr: T[], areItemsEqual: (x: T, y: T) => boolean): T[];
|
|
22
|
+
declare function differenceWith<T>(firstArr: readonly T[], secondArr: readonly T[], areItemsEqual: (x: T, y: T) => boolean): T[];
|
|
23
23
|
|
|
24
24
|
export { differenceWith };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/differenceWith.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays based on a custom equality function.\n *\n * This function takes two arrays and a custom comparison function. It returns a new array containing\n * the elements that are present in the first array but not in the second array. The comparison to determine\n * if elements are equal is made using the provided custom function.\n *\n * @template T\n * @param {T[]} firstArr - The array from which to get the difference.\n * @param {T[]} secondArr - The array containing elements to exclude from the first array.\n * @param {(x: T, y: T) => boolean} areItemsEqual - A function to determine if two items are equal.\n * @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array\n * according to the custom equality function.\n *\n * @example\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];\n * const array2 = [{ id: 2 }, { id: 4 }];\n * const areItemsEqual = (a, b) => a.id === b.id;\n * const result = differenceWith(array1, array2, areItemsEqual);\n * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.\n */\nexport function differenceWith<T>(firstArr: T[], secondArr: T[], areItemsEqual: (x: T, y: T) => boolean): T[] {\n return firstArr.filter(firstItem => {\n return secondArr.every(secondItem => {\n return !areItemsEqual(firstItem, secondItem);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBO,SAAS,eAAkB,
|
|
1
|
+
{"version":3,"sources":["../../src/array/differenceWith.ts"],"sourcesContent":["/**\n * Computes the difference between two arrays based on a custom equality function.\n *\n * This function takes two arrays and a custom comparison function. It returns a new array containing\n * the elements that are present in the first array but not in the second array. The comparison to determine\n * if elements are equal is made using the provided custom function.\n *\n * @template T\n * @param {T[]} firstArr - The array from which to get the difference.\n * @param {T[]} secondArr - The array containing elements to exclude from the first array.\n * @param {(x: T, y: T) => boolean} areItemsEqual - A function to determine if two items are equal.\n * @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array\n * according to the custom equality function.\n *\n * @example\n * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];\n * const array2 = [{ id: 2 }, { id: 4 }];\n * const areItemsEqual = (a, b) => a.id === b.id;\n * const result = differenceWith(array1, array2, areItemsEqual);\n * // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.\n */\nexport function differenceWith<T>(firstArr: readonly T[], secondArr: readonly T[], areItemsEqual: (x: T, y: T) => boolean): T[] {\n return firstArr.filter(firstItem => {\n return secondArr.every(secondItem => {\n return !areItemsEqual(firstItem, secondItem);\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBO,SAAS,eAAkB,UAAwB,WAAyB,eAA6C;AAC9H,SAAO,SAAS,OAAO,eAAa;AAClC,WAAO,UAAU,MAAM,gBAAc;AACnC,aAAO,CAAC,cAAc,WAAW,UAAU;AAAA,IAC7C,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
package/dist/array/drop.d.mts
CHANGED
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* const result = drop(array, 2);
|
|
14
14
|
* // result will be [3, 4, 5] since the first two elements are dropped.
|
|
15
15
|
*/
|
|
16
|
-
declare function drop<T>(arr: T[], itemsCount: number): T[];
|
|
16
|
+
declare function drop<T>(arr: readonly T[], itemsCount: number): T[];
|
|
17
17
|
|
|
18
18
|
export { drop };
|
package/dist/array/drop.d.ts
CHANGED
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* const result = drop(array, 2);
|
|
14
14
|
* // result will be [3, 4, 5] since the first two elements are dropped.
|
|
15
15
|
*/
|
|
16
|
-
declare function drop<T>(arr: T[], itemsCount: number): T[];
|
|
16
|
+
declare function drop<T>(arr: readonly T[], itemsCount: number): T[];
|
|
17
17
|
|
|
18
18
|
export { drop };
|
package/dist/array/drop.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/drop.ts"],"sourcesContent":["/**\n * Removes a specified number of elements from the beginning of an array and returns the rest.\n *\n * This function takes an array and a number, and returns a new array with the specified number\n * of elements removed from the start.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {number} itemsCount - The number of elements to drop from the beginning of the array.\n * @returns {T[]} A new array with the specified number of elements removed from the start.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = drop(array, 2);\n * // result will be [3, 4, 5] since the first two elements are dropped.\n */\nexport function drop<T>(arr: T[], itemsCount: number): T[] {\n return arr.slice(itemsCount);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,SAAS,KAAQ,
|
|
1
|
+
{"version":3,"sources":["../../src/array/drop.ts"],"sourcesContent":["/**\n * Removes a specified number of elements from the beginning of an array and returns the rest.\n *\n * This function takes an array and a number, and returns a new array with the specified number\n * of elements removed from the start.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {number} itemsCount - The number of elements to drop from the beginning of the array.\n * @returns {T[]} A new array with the specified number of elements removed from the start.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = drop(array, 2);\n * // result will be [3, 4, 5] since the first two elements are dropped.\n */\nexport function drop<T>(arr: readonly T[], itemsCount: number): T[] {\n return arr.slice(itemsCount);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,SAAS,KAAQ,KAAmB,YAAyB;AAClE,SAAO,IAAI,MAAM,UAAU;AAC7B;","names":[]}
|
package/dist/array/drop.mjs
CHANGED
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* const result = dropRight(array, 2);
|
|
14
14
|
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
15
15
|
*/
|
|
16
|
-
declare function dropRight<T>(arr: T[], itemsCount: number): T[];
|
|
16
|
+
declare function dropRight<T>(arr: readonly T[], itemsCount: number): T[];
|
|
17
17
|
|
|
18
18
|
export { dropRight };
|
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
* const result = dropRight(array, 2);
|
|
14
14
|
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
15
15
|
*/
|
|
16
|
-
declare function dropRight<T>(arr: T[], itemsCount: number): T[];
|
|
16
|
+
declare function dropRight<T>(arr: readonly T[], itemsCount: number): T[];
|
|
17
17
|
|
|
18
18
|
export { dropRight };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/dropRight.ts"],"sourcesContent":["/**\n * Removes a specified number of elements from the end of an array and returns the rest.\n *\n * This function takes an array and a number, and returns a new array with the specified number\n * of elements removed from the end.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {number} itemsCount - The number of elements to drop from the end of the array.\n * @returns {T[]} A new array with the specified number of elements removed from the end.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropRight(array, 2);\n * // result will be [1, 2, 3] since the last two elements are dropped.\n */\nexport function dropRight<T>(arr: T[], itemsCount: number): T[] {\n return arr.slice(0, -itemsCount);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,SAAS,UAAa,
|
|
1
|
+
{"version":3,"sources":["../../src/array/dropRight.ts"],"sourcesContent":["/**\n * Removes a specified number of elements from the end of an array and returns the rest.\n *\n * This function takes an array and a number, and returns a new array with the specified number\n * of elements removed from the end.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {number} itemsCount - The number of elements to drop from the end of the array.\n * @returns {T[]} A new array with the specified number of elements removed from the end.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropRight(array, 2);\n * // result will be [1, 2, 3] since the last two elements are dropped.\n */\nexport function dropRight<T>(arr: readonly T[], itemsCount: number): T[] {\n return arr.slice(0, -itemsCount);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeO,SAAS,UAAa,KAAmB,YAAyB;AACvE,SAAO,IAAI,MAAM,GAAG,CAAC,UAAU;AACjC;","names":[]}
|
package/dist/array/dropRight.mjs
CHANGED
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* const result = dropRightWhile(array, x => x > 3);
|
|
16
16
|
* // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
|
|
17
17
|
*/
|
|
18
|
-
declare function dropRightWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[];
|
|
18
|
+
declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[];
|
|
19
19
|
|
|
20
20
|
export { dropRightWhile };
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* const result = dropRightWhile(array, x => x > 3);
|
|
16
16
|
* // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
|
|
17
17
|
*/
|
|
18
|
-
declare function dropRightWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[];
|
|
18
|
+
declare function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[];
|
|
19
19
|
|
|
20
20
|
export { dropRightWhile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/dropRightWhile.ts","../../src/array/dropWhile.ts"],"sourcesContent":["import { dropWhile } from './dropWhile';\n\n/**\n * Removes elements from the end of an array until the predicate returns false.\n *\n * This function iterates over an array from the end and drops elements until the provided\n * predicate function returns false. It then returns a new array with the remaining elements.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines\n * whether to continue dropping elements. The function is called with each element from the end,\n * and dropping continues as long as it returns true.\n * @returns {T[]} A new array with the elements remaining after the predicate returns false.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropRightWhile(array, x => x > 3);\n * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.\n */\nexport function dropRightWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[] {\n const reversed = arr.slice().reverse();\n const dropped = dropWhile(reversed, canContinueDropping);\n return dropped.slice().reverse();\n}\n","/**\n * Removes elements from the beginning of an array until the predicate returns false.\n *\n * This function iterates over an array and drops elements from the start until the provided\n * predicate function returns false. It then returns a new array with the remaining elements.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines\n * whether to continue dropping elements. The function is called with each element, and dropping\n * continues as long as it returns true.\n * @returns {T[]} A new array with the elements remaining after the predicate returns false.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropWhile(array, x => x < 3);\n * // result will be [3, 4, 5] since elements less than 3 are dropped.\n */\nexport function dropWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[] {\n const dropEndIndex = arr.findIndex(item => !canContinueDropping(item));\n return arr.slice(dropEndIndex);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,UAAa,
|
|
1
|
+
{"version":3,"sources":["../../src/array/dropRightWhile.ts","../../src/array/dropWhile.ts"],"sourcesContent":["import { dropWhile } from './dropWhile';\n\n/**\n * Removes elements from the end of an array until the predicate returns false.\n *\n * This function iterates over an array from the end and drops elements until the provided\n * predicate function returns false. It then returns a new array with the remaining elements.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines\n * whether to continue dropping elements. The function is called with each element from the end,\n * and dropping continues as long as it returns true.\n * @returns {T[]} A new array with the elements remaining after the predicate returns false.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropRightWhile(array, x => x > 3);\n * // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.\n */\nexport function dropRightWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[] {\n const reversed = arr.slice().reverse();\n const dropped = dropWhile(reversed, canContinueDropping);\n return dropped.slice().reverse();\n}\n","/**\n * Removes elements from the beginning of an array until the predicate returns false.\n *\n * This function iterates over an array and drops elements from the start until the provided\n * predicate function returns false. It then returns a new array with the remaining elements.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines\n * whether to continue dropping elements. The function is called with each element, and dropping\n * continues as long as it returns true.\n * @returns {T[]} A new array with the elements remaining after the predicate returns false.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropWhile(array, x => x < 3);\n * // result will be [3, 4, 5] since elements less than 3 are dropped.\n */\nexport function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[] {\n const dropEndIndex = arr.findIndex(item => !canContinueDropping(item));\n return arr.slice(dropEndIndex);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,UAAa,KAAmB,qBAAgD;AAC9F,QAAM,eAAe,IAAI,UAAU,UAAQ,CAAC,oBAAoB,IAAI,CAAC;AACrE,SAAO,IAAI,MAAM,YAAY;AAC/B;;;ADDO,SAAS,eAAkB,KAAmB,qBAAgD;AACnG,QAAM,WAAW,IAAI,MAAM,EAAE,QAAQ;AACrC,QAAM,UAAU,UAAU,UAAU,mBAAmB;AACvD,SAAO,QAAQ,MAAM,EAAE,QAAQ;AACjC;","names":[]}
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* const result = dropWhile(array, x => x < 3);
|
|
16
16
|
* // result will be [3, 4, 5] since elements less than 3 are dropped.
|
|
17
17
|
*/
|
|
18
|
-
declare function dropWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[];
|
|
18
|
+
declare function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[];
|
|
19
19
|
|
|
20
20
|
export { dropWhile };
|
|
@@ -15,6 +15,6 @@
|
|
|
15
15
|
* const result = dropWhile(array, x => x < 3);
|
|
16
16
|
* // result will be [3, 4, 5] since elements less than 3 are dropped.
|
|
17
17
|
*/
|
|
18
|
-
declare function dropWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[];
|
|
18
|
+
declare function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[];
|
|
19
19
|
|
|
20
20
|
export { dropWhile };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/dropWhile.ts"],"sourcesContent":["/**\n * Removes elements from the beginning of an array until the predicate returns false.\n *\n * This function iterates over an array and drops elements from the start until the provided\n * predicate function returns false. It then returns a new array with the remaining elements.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines\n * whether to continue dropping elements. The function is called with each element, and dropping\n * continues as long as it returns true.\n * @returns {T[]} A new array with the elements remaining after the predicate returns false.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropWhile(array, x => x < 3);\n * // result will be [3, 4, 5] since elements less than 3 are dropped.\n */\nexport function dropWhile<T>(arr: T[], canContinueDropping: (item: T) => boolean): T[] {\n const dropEndIndex = arr.findIndex(item => !canContinueDropping(item));\n return arr.slice(dropEndIndex);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,SAAS,UAAa,
|
|
1
|
+
{"version":3,"sources":["../../src/array/dropWhile.ts"],"sourcesContent":["/**\n * Removes elements from the beginning of an array until the predicate returns false.\n *\n * This function iterates over an array and drops elements from the start until the provided\n * predicate function returns false. It then returns a new array with the remaining elements.\n *\n * @param {T[]} arr - The array from which to drop elements.\n * @param {(item: T) => boolean} canContinueDropping - A predicate function that determines\n * whether to continue dropping elements. The function is called with each element, and dropping\n * continues as long as it returns true.\n * @returns {T[]} A new array with the elements remaining after the predicate returns false.\n *\n * @example\n * const array = [1, 2, 3, 4, 5];\n * const result = dropWhile(array, x => x < 3);\n * // result will be [3, 4, 5] since elements less than 3 are dropped.\n */\nexport function dropWhile<T>(arr: readonly T[], canContinueDropping: (item: T) => boolean): T[] {\n const dropEndIndex = arr.findIndex(item => !canContinueDropping(item));\n return arr.slice(dropEndIndex);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,SAAS,UAAa,KAAmB,qBAAgD;AAC9F,QAAM,eAAe,IAAI,UAAU,UAAQ,CAAC,oBAAoB,IAAI,CAAC;AACrE,SAAO,IAAI,MAAM,YAAY;AAC/B;","names":[]}
|
package/dist/array/dropWhile.mjs
CHANGED
package/dist/array/groupBy.d.mts
CHANGED
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
* // ]
|
|
29
29
|
* // }
|
|
30
30
|
*/
|
|
31
|
-
declare function groupBy<T, K extends string>(arr: T[], getKeyFromItem: (item: T) => K): Record<K, T[]>;
|
|
31
|
+
declare function groupBy<T, K extends string>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T[]>;
|
|
32
32
|
|
|
33
33
|
export { groupBy };
|
package/dist/array/groupBy.d.ts
CHANGED
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
* // ]
|
|
29
29
|
* // }
|
|
30
30
|
*/
|
|
31
|
-
declare function groupBy<T, K extends string>(arr: T[], getKeyFromItem: (item: T) => K): Record<K, T[]>;
|
|
31
|
+
declare function groupBy<T, K extends string>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T[]>;
|
|
32
32
|
|
|
33
33
|
export { groupBy };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/array/groupBy.ts"],"sourcesContent":["/**\n * Groups the elements of an array based on a provided key-generating function.\n *\n * This function takes an array and a function that generates a key from each element. It returns\n * an object where the keys are the generated keys and the values are arrays of elements that share\n * the same key.\n *\n * @param {T[]} arr - The array to group.\n * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.\n * @returns {Record<K, T[]>} An object where each key is associated with an array of elements that\n * share that key.\n *\n * @example\n * const array = [\n * { category: 'fruit', name: 'apple' },\n * { category: 'fruit', name: 'banana' },\n * { category: 'vegetable', name: 'carrot' }\n * ];\n * const result = groupBy(array, item => item.category);\n * // result will be:\n * // {\n * // fruit: [\n * // { category: 'fruit', name: 'apple' },\n * // { category: 'fruit', name: 'banana' }\n * // ],\n * // vegetable: [\n * // { category: 'vegetable', name: 'carrot' }\n * // ]\n * // }\n */\nexport function groupBy<T, K extends string>(arr: T[], getKeyFromItem: (item: T) => K): Record<K, T[]> {\n const result = {} as Record<K, T[]>;\n\n for (const item of arr) {\n const key = getKeyFromItem(item);\n\n if (result[key] == null) {\n result[key] = [];\n }\n\n result[key].push(item);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,SAAS,QAA6B,
|
|
1
|
+
{"version":3,"sources":["../../src/array/groupBy.ts"],"sourcesContent":["/**\n * Groups the elements of an array based on a provided key-generating function.\n *\n * This function takes an array and a function that generates a key from each element. It returns\n * an object where the keys are the generated keys and the values are arrays of elements that share\n * the same key.\n *\n * @param {T[]} arr - The array to group.\n * @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.\n * @returns {Record<K, T[]>} An object where each key is associated with an array of elements that\n * share that key.\n *\n * @example\n * const array = [\n * { category: 'fruit', name: 'apple' },\n * { category: 'fruit', name: 'banana' },\n * { category: 'vegetable', name: 'carrot' }\n * ];\n * const result = groupBy(array, item => item.category);\n * // result will be:\n * // {\n * // fruit: [\n * // { category: 'fruit', name: 'apple' },\n * // { category: 'fruit', name: 'banana' }\n * // ],\n * // vegetable: [\n * // { category: 'vegetable', name: 'carrot' }\n * // ]\n * // }\n */\nexport function groupBy<T, K extends string>(arr: readonly T[], getKeyFromItem: (item: T) => K): Record<K, T[]> {\n const result = {} as Record<K, T[]>;\n\n for (const item of arr) {\n const key = getKeyFromItem(item);\n\n if (result[key] == null) {\n result[key] = [];\n }\n\n result[key].push(item);\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BO,SAAS,QAA6B,KAAmB,gBAAgD;AAC9G,QAAM,SAAS,CAAC;AAEhB,aAAW,QAAQ,KAAK;AACtB,UAAM,MAAM,eAAe,IAAI;AAE/B,QAAI,OAAO,GAAG,KAAK,MAAM;AACvB,aAAO,GAAG,IAAI,CAAC;AAAA,IACjB;AAEA,WAAO,GAAG,EAAE,KAAK,IAAI;AAAA,EACvB;AAEA,SAAO;AACT;","names":[]}
|
package/dist/array/groupBy.mjs
CHANGED
package/dist/array/index.js
CHANGED
|
@@ -136,10 +136,8 @@ function intersection(firstArr, secondArr) {
|
|
|
136
136
|
|
|
137
137
|
// src/array/intersectionBy.ts
|
|
138
138
|
function intersectionBy(firstArr, secondArr, mapper) {
|
|
139
|
-
const
|
|
140
|
-
return firstArr.filter((item) =>
|
|
141
|
-
return mappedSecondArr.includes(mapper(item));
|
|
142
|
-
});
|
|
139
|
+
const mappedSecondSet = new Set(secondArr.map(mapper));
|
|
140
|
+
return firstArr.filter((item) => mappedSecondSet.has(mapper(item)));
|
|
143
141
|
}
|
|
144
142
|
|
|
145
143
|
// src/array/intersectionWith.ts
|
|
@@ -218,14 +216,7 @@ function takeWhile(arr, shouldContinueTaking) {
|
|
|
218
216
|
|
|
219
217
|
// src/array/uniq.ts
|
|
220
218
|
function uniq(arr) {
|
|
221
|
-
|
|
222
|
-
for (const item of arr) {
|
|
223
|
-
if (result.includes(item)) {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
result.push(item);
|
|
227
|
-
}
|
|
228
|
-
return result;
|
|
219
|
+
return Array.from(new Set(arr));
|
|
229
220
|
}
|
|
230
221
|
|
|
231
222
|
// src/array/union.ts
|
|
@@ -263,8 +254,8 @@ function unionWith(arr1, arr2, areItemsEqual) {
|
|
|
263
254
|
}
|
|
264
255
|
|
|
265
256
|
// src/array/uniqBy.ts
|
|
266
|
-
function uniqBy(arr,
|
|
267
|
-
return uniqWith(arr, (item1, item2) =>
|
|
257
|
+
function uniqBy(arr, mapper) {
|
|
258
|
+
return uniqWith(arr, (item1, item2) => mapper(item1) === mapper(item2));
|
|
268
259
|
}
|
|
269
260
|
|
|
270
261
|
// src/array/xor.ts
|