es-toolkit 1.0.3 → 1.0.4-dev.39
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 +6 -0
- package/{esm/array/chunk.mjs → dist/array/chunk.d.mts} +1 -13
- package/dist/array/chunk.d.ts +3 -1
- package/dist/array/chunk.js +43 -0
- package/dist/array/chunk.js.map +1 -0
- package/dist/array/chunk.mjs +8 -0
- package/dist/array/chunk.mjs.map +1 -0
- package/{esm/array/difference.mjs → dist/array/difference.d.mts} +8 -12
- package/dist/array/difference.d.ts +3 -1
- package/dist/array/difference.js +35 -0
- package/dist/array/difference.js.map +1 -0
- package/dist/array/difference.mjs +8 -0
- package/dist/array/difference.mjs.map +1 -0
- package/{esm/array/differenceBy.mjs → dist/array/differenceBy.d.mts} +10 -17
- package/dist/array/differenceBy.d.ts +3 -1
- package/dist/array/differenceBy.js +36 -0
- package/dist/array/differenceBy.js.map +1 -0
- package/dist/array/differenceBy.mjs +8 -0
- package/dist/array/differenceBy.mjs.map +1 -0
- package/{esm/array/differenceWith.mjs → dist/array/differenceWith.d.mts} +6 -12
- package/dist/array/differenceWith.d.ts +3 -1
- package/dist/array/differenceWith.js +37 -0
- package/dist/array/differenceWith.js.map +1 -0
- package/dist/array/differenceWith.mjs +8 -0
- package/dist/array/differenceWith.mjs.map +1 -0
- package/{esm/array/drop.mjs → dist/array/drop.d.mts} +4 -6
- package/dist/array/drop.d.ts +3 -1
- package/dist/array/drop.js +33 -0
- package/dist/array/drop.js.map +1 -0
- package/dist/array/drop.mjs +8 -0
- package/dist/array/drop.mjs.map +1 -0
- package/{esm/array/dropRight.mjs → dist/array/dropRight.d.mts} +3 -5
- package/dist/array/dropRight.d.ts +3 -1
- package/dist/array/dropRight.js +33 -0
- package/dist/array/dropRight.js.map +1 -0
- package/dist/array/dropRight.mjs +8 -0
- package/dist/array/dropRight.mjs.map +1 -0
- package/{esm/array/dropRightWhile.mjs → dist/array/dropRightWhile.d.mts} +5 -11
- package/dist/array/dropRightWhile.d.ts +3 -1
- package/dist/array/dropRightWhile.js +43 -0
- package/dist/array/dropRightWhile.js.map +1 -0
- package/dist/array/dropRightWhile.mjs +9 -0
- package/dist/array/dropRightWhile.mjs.map +1 -0
- package/{esm/array/dropWhile.mjs → dist/array/dropWhile.d.mts} +5 -10
- package/dist/array/dropWhile.d.ts +3 -1
- package/dist/array/dropWhile.js +34 -0
- package/dist/array/dropWhile.js.map +1 -0
- package/dist/array/dropWhile.mjs +8 -0
- package/dist/array/dropWhile.mjs.map +1 -0
- package/{esm/array/groupBy.mjs → dist/array/groupBy.d.mts} +5 -26
- package/dist/array/groupBy.d.ts +3 -1
- package/dist/array/groupBy.js +41 -0
- package/dist/array/groupBy.js.map +1 -0
- package/dist/array/groupBy.mjs +8 -0
- package/dist/array/groupBy.mjs.map +1 -0
- package/dist/array/index.d.ts +30 -30
- package/dist/array/index.js +199 -842
- package/dist/array/index.js.map +1 -0
- package/dist/array/index.mjs +125 -0
- package/dist/array/index.mjs.map +1 -0
- package/{esm/array/intersection.mjs → dist/array/intersection.d.mts} +4 -8
- package/dist/array/intersection.d.ts +3 -1
- package/dist/array/intersection.js +35 -0
- package/dist/array/intersection.js.map +1 -0
- package/dist/array/intersection.mjs +8 -0
- package/dist/array/intersection.mjs.map +1 -0
- package/{esm/array/intersectionBy.mjs → dist/array/intersectionBy.d.mts} +5 -12
- package/dist/array/intersectionBy.d.ts +3 -1
- package/dist/array/intersectionBy.js +36 -0
- package/dist/array/intersectionBy.js.map +1 -0
- package/dist/array/intersectionBy.mjs +8 -0
- package/dist/array/intersectionBy.mjs.map +1 -0
- package/{esm/array/intersectionWith.mjs → dist/array/intersectionWith.d.mts} +6 -12
- package/dist/array/intersectionWith.d.ts +3 -1
- package/dist/array/intersectionWith.js +37 -0
- package/dist/array/intersectionWith.js.map +1 -0
- package/dist/array/intersectionWith.mjs +8 -0
- package/dist/array/intersectionWith.mjs.map +1 -0
- package/{esm/array/partition.mjs → dist/array/partition.d.mts} +8 -30
- package/dist/array/partition.d.ts +3 -1
- package/dist/array/partition.js +42 -0
- package/dist/array/partition.js.map +1 -0
- package/dist/array/partition.mjs +8 -0
- package/dist/array/partition.mjs.map +1 -0
- package/{esm/array/sample.mjs → dist/array/sample.d.mts} +2 -5
- package/dist/array/sample.d.ts +3 -1
- package/dist/array/sample.js +34 -0
- package/dist/array/sample.js.map +1 -0
- package/dist/array/sample.mjs +8 -0
- package/dist/array/sample.mjs.map +1 -0
- package/{esm/array/shuffle.mjs → dist/array/shuffle.d.mts} +2 -13
- package/dist/array/shuffle.d.ts +3 -1
- package/dist/array/shuffle.js +37 -0
- package/dist/array/shuffle.js.map +1 -0
- package/dist/array/shuffle.mjs +8 -0
- package/dist/array/shuffle.mjs.map +1 -0
- package/{esm/array/take.mjs → dist/array/take.d.mts} +5 -7
- package/dist/array/take.d.ts +3 -1
- package/dist/array/take.js +33 -0
- package/dist/array/take.js.map +1 -0
- package/dist/array/take.mjs +8 -0
- package/dist/array/take.mjs.map +1 -0
- package/{esm/array/takeRight.mjs → dist/array/takeRight.d.mts} +5 -10
- package/dist/array/takeRight.d.ts +3 -1
- package/dist/array/takeRight.js +36 -0
- package/dist/array/takeRight.js.map +1 -0
- package/dist/array/takeRight.mjs +8 -0
- package/dist/array/takeRight.mjs.map +1 -0
- package/{esm/array/takeRightWhile.mjs → dist/array/takeRightWhile.d.mts} +5 -12
- package/dist/array/takeRightWhile.d.ts +3 -1
- package/dist/array/takeRightWhile.js +38 -0
- package/dist/array/takeRightWhile.js.map +1 -0
- package/dist/array/takeRightWhile.mjs +8 -0
- package/dist/array/takeRightWhile.mjs.map +1 -0
- package/{esm/array/takeWhile.mjs → dist/array/takeWhile.d.mts} +1 -21
- package/dist/array/takeWhile.d.ts +3 -1
- package/dist/array/takeWhile.js +40 -0
- package/dist/array/takeWhile.js.map +1 -0
- package/dist/array/takeWhile.mjs +8 -0
- package/dist/array/takeWhile.mjs.map +1 -0
- package/{esm/array/union.mjs → dist/array/union.d.mts} +3 -7
- package/dist/array/union.d.ts +3 -1
- package/dist/array/union.js +47 -0
- package/dist/array/union.js.map +1 -0
- package/dist/array/union.mjs +9 -0
- package/dist/array/union.mjs.map +1 -0
- package/{esm/array/unionBy.mjs → dist/array/unionBy.d.mts} +4 -16
- package/dist/array/unionBy.d.ts +3 -1
- package/dist/array/unionBy.js +40 -0
- package/dist/array/unionBy.js.map +1 -0
- package/dist/array/unionBy.mjs +8 -0
- package/dist/array/unionBy.mjs.map +1 -0
- package/{esm/array/unionWith.mjs → dist/array/unionWith.d.mts} +4 -8
- package/dist/array/unionWith.d.ts +3 -1
- package/dist/array/unionWith.js +47 -0
- package/dist/array/unionWith.js.map +1 -0
- package/dist/array/unionWith.mjs +9 -0
- package/dist/array/unionWith.mjs.map +1 -0
- package/dist/array/uniq.d.mts +17 -0
- package/dist/array/uniq.d.ts +3 -1
- package/dist/array/uniq.js +40 -0
- package/dist/array/uniq.js.map +1 -0
- package/dist/array/uniq.mjs +8 -0
- package/dist/array/uniq.mjs.map +1 -0
- package/{esm/array/uniqBy.mjs → dist/array/uniqBy.d.mts} +1 -7
- package/dist/array/uniqBy.d.ts +3 -1
- package/dist/array/uniqBy.js +47 -0
- package/dist/array/uniqBy.js.map +1 -0
- package/dist/array/uniqBy.mjs +9 -0
- package/dist/array/uniqBy.mjs.map +1 -0
- package/dist/array/uniqWith.d.mts +14 -0
- package/dist/array/uniqWith.d.ts +3 -1
- package/dist/array/uniqWith.js +40 -0
- package/dist/array/uniqWith.js.map +1 -0
- package/dist/array/uniqWith.mjs +8 -0
- package/dist/array/uniqWith.mjs.map +1 -0
- package/{esm/array/xor.mjs → dist/array/xor.d.mts} +4 -10
- package/dist/array/xor.d.ts +3 -1
- package/dist/array/xor.js +66 -0
- package/dist/array/xor.js.map +1 -0
- package/dist/array/xor.mjs +12 -0
- package/dist/array/xor.mjs.map +1 -0
- package/{esm/array/xorBy.mjs → dist/array/xorBy.d.mts} +5 -13
- package/dist/array/xorBy.d.ts +3 -1
- package/dist/array/xorBy.js +65 -0
- package/dist/array/xorBy.js.map +1 -0
- package/dist/array/xorBy.mjs +11 -0
- package/dist/array/xorBy.mjs.map +1 -0
- package/{esm/array/xorWith.mjs → dist/array/xorWith.d.mts} +5 -13
- package/dist/array/xorWith.d.ts +3 -1
- package/dist/array/xorWith.js +72 -0
- package/dist/array/xorWith.js.map +1 -0
- package/dist/array/xorWith.mjs +12 -0
- package/dist/array/xorWith.mjs.map +1 -0
- package/dist/array/zip.d.mts +27 -0
- package/dist/array/zip.d.ts +6 -4
- package/dist/array/zip.js +42 -0
- package/dist/array/zip.js.map +1 -0
- package/dist/array/zip.mjs +8 -0
- package/dist/array/zip.mjs.map +1 -0
- package/{esm/array/zipWith.mjs → dist/array/zipWith.d.mts} +6 -26
- package/dist/array/zipWith.d.ts +6 -4
- package/dist/array/zipWith.js +41 -0
- package/dist/array/zipWith.js.map +1 -0
- package/dist/array/zipWith.mjs +8 -0
- package/dist/array/zipWith.mjs.map +1 -0
- package/dist/chunk-2KXLTAVK.mjs +16 -0
- package/dist/chunk-2KXLTAVK.mjs.map +1 -0
- package/dist/chunk-2MM5EJJX.mjs +21 -0
- package/dist/chunk-2MM5EJJX.mjs.map +1 -0
- package/dist/chunk-2VB6XU3I.mjs +12 -0
- package/dist/chunk-2VB6XU3I.mjs.map +1 -0
- package/dist/chunk-35TWSMYS.mjs +19 -0
- package/dist/chunk-35TWSMYS.mjs.map +1 -0
- package/dist/chunk-5JWSGT4R.mjs +18 -0
- package/dist/chunk-5JWSGT4R.mjs.map +1 -0
- package/dist/chunk-724PNXPR.mjs +13 -0
- package/dist/chunk-724PNXPR.mjs.map +1 -0
- package/dist/chunk-7GWOR247.mjs +11 -0
- package/dist/chunk-7GWOR247.mjs.map +1 -0
- package/dist/chunk-7OZZODAE.mjs +19 -0
- package/dist/chunk-7OZZODAE.mjs.map +1 -0
- package/dist/chunk-7PPND7QY.mjs +16 -0
- package/dist/chunk-7PPND7QY.mjs.map +1 -0
- package/dist/chunk-7SJHJHBN.mjs +11 -0
- package/dist/chunk-7SJHJHBN.mjs.map +1 -0
- package/dist/chunk-ARWKEQMQ.mjs +19 -0
- package/dist/chunk-ARWKEQMQ.mjs.map +1 -0
- package/dist/chunk-ARZ5BDR6.mjs +1 -0
- package/dist/chunk-ARZ5BDR6.mjs.map +1 -0
- package/dist/chunk-BAJC3BM7.mjs +12 -0
- package/dist/chunk-BAJC3BM7.mjs.map +1 -0
- package/dist/chunk-EAI4DDCQ.mjs +16 -0
- package/dist/chunk-EAI4DDCQ.mjs.map +1 -0
- package/dist/chunk-EAI6NLXI.mjs +12 -0
- package/dist/chunk-EAI6NLXI.mjs.map +1 -0
- package/dist/chunk-EJGAXTF7.mjs +1 -0
- package/dist/chunk-EJGAXTF7.mjs.map +1 -0
- package/dist/chunk-FUWEG5ZM.mjs +9 -0
- package/dist/chunk-FUWEG5ZM.mjs.map +1 -0
- package/dist/chunk-GJM7F3TH.mjs +13 -0
- package/dist/chunk-GJM7F3TH.mjs.map +1 -0
- package/dist/chunk-HQF6OFGM.mjs +9 -0
- package/dist/chunk-HQF6OFGM.mjs.map +1 -0
- package/dist/chunk-IJLQVGW4.mjs +1 -0
- package/dist/chunk-IJLQVGW4.mjs.map +1 -0
- package/dist/chunk-J3NTLMAE.mjs +10 -0
- package/dist/chunk-J3NTLMAE.mjs.map +1 -0
- package/dist/chunk-JMLFPGZ3.mjs +13 -0
- package/dist/chunk-JMLFPGZ3.mjs.map +1 -0
- package/dist/chunk-L4Y3G6AJ.mjs +23 -0
- package/dist/chunk-L4Y3G6AJ.mjs.map +1 -0
- package/dist/chunk-LAZNLIBJ.mjs +10 -0
- package/dist/chunk-LAZNLIBJ.mjs.map +1 -0
- package/dist/chunk-MAJSPFA6.mjs +1 -0
- package/dist/chunk-MAJSPFA6.mjs.map +1 -0
- package/dist/chunk-NEMQJ2GF.mjs +18 -0
- package/dist/chunk-NEMQJ2GF.mjs.map +1 -0
- package/dist/chunk-NK2262VG.mjs +9 -0
- package/dist/chunk-NK2262VG.mjs.map +1 -0
- package/dist/chunk-NSYWEYWT.mjs +13 -0
- package/dist/chunk-NSYWEYWT.mjs.map +1 -0
- package/dist/chunk-NYVT33DR.mjs +9 -0
- package/dist/chunk-NYVT33DR.mjs.map +1 -0
- package/dist/chunk-OBMK7JO2.mjs +13 -0
- package/dist/chunk-OBMK7JO2.mjs.map +1 -0
- package/dist/chunk-PTQLD7TG.mjs +11 -0
- package/dist/chunk-PTQLD7TG.mjs.map +1 -0
- package/dist/chunk-PWMHSN27.mjs +14 -0
- package/dist/chunk-PWMHSN27.mjs.map +1 -0
- package/dist/chunk-QRQPLMV4.mjs +16 -0
- package/dist/chunk-QRQPLMV4.mjs.map +1 -0
- package/dist/chunk-R5DNKXDI.mjs +21 -0
- package/dist/chunk-R5DNKXDI.mjs.map +1 -0
- package/dist/chunk-RK6PRCEJ.mjs +12 -0
- package/dist/chunk-RK6PRCEJ.mjs.map +1 -0
- package/dist/chunk-RLDY4N3Q.mjs +13 -0
- package/dist/chunk-RLDY4N3Q.mjs.map +1 -0
- package/dist/chunk-RU3RXBUC.mjs +17 -0
- package/dist/chunk-RU3RXBUC.mjs.map +1 -0
- package/dist/chunk-S767XFOS.mjs +10 -0
- package/dist/chunk-S767XFOS.mjs.map +1 -0
- package/dist/chunk-SGSQKXDO.mjs +15 -0
- package/dist/chunk-SGSQKXDO.mjs.map +1 -0
- package/dist/chunk-SYQTG4N4.mjs +1 -0
- package/dist/chunk-SYQTG4N4.mjs.map +1 -0
- package/dist/chunk-T5JCRGXA.mjs +1 -0
- package/dist/chunk-T5JCRGXA.mjs.map +1 -0
- package/dist/chunk-TOLR2FNF.mjs +13 -0
- package/dist/chunk-TOLR2FNF.mjs.map +1 -0
- package/dist/chunk-UNX3KZO2.mjs +17 -0
- package/dist/chunk-UNX3KZO2.mjs.map +1 -0
- package/dist/chunk-UZP4YX7I.mjs +17 -0
- package/dist/chunk-UZP4YX7I.mjs.map +1 -0
- package/dist/chunk-VACGGQOL.mjs +9 -0
- package/dist/chunk-VACGGQOL.mjs.map +1 -0
- package/dist/chunk-VAKCSKGR.mjs +17 -0
- package/dist/chunk-VAKCSKGR.mjs.map +1 -0
- package/dist/chunk-VJGGYY4Y.mjs +13 -0
- package/dist/chunk-VJGGYY4Y.mjs.map +1 -0
- package/dist/chunk-WFQ3LAHQ.mjs +9 -0
- package/dist/chunk-WFQ3LAHQ.mjs.map +1 -0
- package/dist/chunk-XS4ZPJMT.mjs +21 -0
- package/dist/chunk-XS4ZPJMT.mjs.map +1 -0
- package/dist/chunk-XW452I77.mjs +16 -0
- package/dist/chunk-XW452I77.mjs.map +1 -0
- package/dist/chunk-YMNXRH52.mjs +9 -0
- package/dist/chunk-YMNXRH52.mjs.map +1 -0
- package/dist/chunk-Z4IO7EIH.mjs +16 -0
- package/dist/chunk-Z4IO7EIH.mjs.map +1 -0
- package/{esm/function/debounce.mjs → dist/function/debounce.d.mts} +5 -18
- package/dist/function/debounce.d.ts +3 -1
- package/dist/function/debounce.js +47 -0
- package/dist/function/debounce.js.map +1 -0
- package/dist/function/debounce.mjs +8 -0
- package/dist/function/debounce.mjs.map +1 -0
- package/dist/function/index.d.ts +3 -3
- package/dist/function/index.js +47 -78
- package/dist/function/index.js.map +1 -0
- package/dist/function/index.mjs +17 -0
- package/dist/function/index.mjs.map +1 -0
- package/{esm/function/once.mjs → dist/function/once.d.mts} +2 -14
- package/dist/function/once.d.ts +3 -1
- package/dist/function/once.js +43 -0
- package/dist/function/once.js.map +1 -0
- package/dist/function/once.mjs +8 -0
- package/dist/function/once.mjs.map +1 -0
- package/{esm/function/throttle.mjs → dist/function/throttle.d.mts} +3 -13
- package/dist/function/throttle.d.ts +3 -1
- package/dist/function/throttle.js +41 -0
- package/dist/function/throttle.js.map +1 -0
- package/dist/function/throttle.mjs +8 -0
- package/dist/function/throttle.mjs.map +1 -0
- package/dist/index.d.ts +45 -6
- package/dist/index.js +288 -1271
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +190 -0
- package/dist/index.mjs.map +1 -0
- package/{esm/math/clamp.mjs → dist/math/clamp.d.mts} +2 -7
- package/dist/math/clamp.d.ts +4 -2
- package/dist/math/clamp.js +36 -0
- package/dist/math/clamp.js.map +1 -0
- package/dist/math/clamp.mjs +8 -0
- package/dist/math/clamp.mjs.map +1 -0
- package/dist/math/index.d.ts +3 -3
- package/dist/math/index.js +41 -132
- package/dist/math/index.js.map +1 -0
- package/dist/math/index.mjs +17 -0
- package/dist/math/index.mjs.map +1 -0
- package/{esm/math/round.mjs → dist/math/round.d.mts} +3 -7
- package/dist/math/round.d.ts +3 -1
- package/dist/math/round.js +34 -0
- package/dist/math/round.js.map +1 -0
- package/dist/math/round.mjs +8 -0
- package/dist/math/round.mjs.map +1 -0
- package/dist/math/sum.d.mts +16 -0
- package/dist/math/sum.d.ts +3 -1
- package/dist/math/sum.js +37 -0
- package/dist/math/sum.js.map +1 -0
- package/dist/math/sum.mjs +8 -0
- package/dist/math/sum.mjs.map +1 -0
- package/dist/object/index.d.ts +4 -4
- package/dist/object/index.js +62 -256
- package/dist/object/index.js.map +1 -0
- package/dist/object/index.mjs +21 -0
- package/dist/object/index.mjs.map +1 -0
- package/{esm/object/omit.mjs → dist/object/omit.d.mts} +2 -19
- package/dist/object/omit.d.ts +3 -1
- package/dist/object/omit.js +51 -0
- package/dist/object/omit.js.map +1 -0
- package/dist/object/omit.mjs +8 -0
- package/dist/object/omit.mjs.map +1 -0
- package/{esm/object/omitBy.mjs → dist/object/omitBy.d.mts} +4 -18
- package/dist/object/omitBy.d.ts +3 -1
- package/dist/object/omitBy.js +40 -0
- package/dist/object/omitBy.js.map +1 -0
- package/dist/object/omitBy.mjs +8 -0
- package/dist/object/omitBy.mjs.map +1 -0
- package/{esm/object/pick.mjs → dist/object/pick.d.mts} +2 -19
- package/dist/object/pick.d.ts +3 -1
- package/dist/object/pick.js +37 -0
- package/dist/object/pick.js.map +1 -0
- package/dist/object/pick.mjs +8 -0
- package/dist/object/pick.mjs.map +1 -0
- package/{esm/object/pickBy.mjs → dist/object/pickBy.d.mts} +4 -18
- package/dist/object/pickBy.d.ts +3 -1
- package/dist/object/pickBy.js +40 -0
- package/dist/object/pickBy.js.map +1 -0
- package/dist/object/pickBy.mjs +8 -0
- package/dist/object/pickBy.mjs.map +1 -0
- package/dist/predicate/index.d.ts +4 -4
- package/dist/predicate/index.js +42 -84
- package/dist/predicate/index.js.map +1 -0
- package/dist/predicate/index.mjs +21 -0
- package/dist/predicate/index.mjs.map +1 -0
- package/{esm/predicate/isNil.mjs → dist/predicate/isNil.d.mts} +4 -6
- package/dist/predicate/isNil.d.ts +3 -1
- package/dist/predicate/isNil.js +33 -0
- package/dist/predicate/isNil.js.map +1 -0
- package/dist/predicate/isNil.mjs +8 -0
- package/dist/predicate/isNil.mjs.map +1 -0
- package/{esm/predicate/isNotNil.mjs → dist/predicate/isNotNil.d.mts} +2 -4
- package/dist/predicate/isNotNil.d.ts +3 -1
- package/dist/predicate/isNotNil.js +33 -0
- package/dist/predicate/isNotNil.js.map +1 -0
- package/dist/predicate/isNotNil.mjs +8 -0
- package/dist/predicate/isNotNil.mjs.map +1 -0
- package/{esm/predicate/isNull.mjs → dist/predicate/isNull.d.mts} +4 -6
- package/dist/predicate/isNull.d.ts +3 -1
- package/dist/predicate/isNull.js +33 -0
- package/dist/predicate/isNull.js.map +1 -0
- package/dist/predicate/isNull.mjs +8 -0
- package/dist/predicate/isNull.mjs.map +1 -0
- package/{esm/predicate/isUndefined.mjs → dist/predicate/isUndefined.d.mts} +4 -6
- package/dist/predicate/isUndefined.d.ts +3 -1
- package/dist/predicate/isUndefined.js +33 -0
- package/dist/predicate/isUndefined.js.map +1 -0
- package/dist/predicate/isUndefined.mjs +8 -0
- package/dist/predicate/isUndefined.mjs.map +1 -0
- package/{esm/promise/delay.mjs → dist/promise/delay.d.mts} +4 -8
- package/dist/promise/delay.d.ts +3 -1
- package/dist/promise/delay.js +35 -0
- package/dist/promise/delay.js.map +1 -0
- package/dist/promise/delay.mjs +8 -0
- package/dist/promise/delay.mjs.map +1 -0
- package/dist/promise/index.d.ts +1 -1
- package/dist/promise/index.js +31 -23
- package/dist/promise/index.js.map +1 -0
- package/dist/promise/index.mjs +9 -0
- package/dist/promise/index.mjs.map +1 -0
- package/package.json +120 -49
- package/dist/array/chunk.spec.d.ts +0 -1
- package/dist/array/difference.spec.d.ts +0 -1
- package/dist/array/differenceBy.spec.d.ts +0 -1
- package/dist/array/differenceWith.spec.d.ts +0 -1
- package/dist/array/drop.spec.d.ts +0 -1
- package/dist/array/dropRight.spec.d.ts +0 -1
- package/dist/array/dropRightWhile.spec.d.ts +0 -1
- package/dist/array/dropWhile.spec.d.ts +0 -1
- package/dist/array/groupBy.spec.d.ts +0 -1
- package/dist/array/intersection.spec.d.ts +0 -1
- package/dist/array/intersectionBy.spec.d.ts +0 -1
- package/dist/array/intersectionWith.spec.d.ts +0 -1
- package/dist/array/partition.spec.d.ts +0 -1
- package/dist/array/sample.spec.d.ts +0 -1
- package/dist/array/shuffle.spec.d.ts +0 -1
- package/dist/array/take.spec.d.ts +0 -1
- package/dist/array/takeRight.spec.d.ts +0 -1
- package/dist/array/takeRightWhile.spec.d.ts +0 -1
- package/dist/array/takeWhile.spec.d.ts +0 -1
- package/dist/array/union.spec.d.ts +0 -1
- package/dist/array/unionBy.spec.d.ts +0 -1
- package/dist/array/unionWith.spec.d.ts +0 -1
- package/dist/array/uniq.spec.d.ts +0 -1
- package/dist/array/uniqBy.spec.d.ts +0 -1
- package/dist/array/uniqWith.spec.d.ts +0 -1
- package/dist/array/xor.spec.d.ts +0 -1
- package/dist/array/xorBy.spec.d.ts +0 -1
- package/dist/array/xorWith.spec.d.ts +0 -1
- package/dist/array/zip.spec.d.ts +0 -1
- package/dist/array/zipWith.spec.d.ts +0 -1
- package/dist/function/debounce.spec.d.ts +0 -1
- package/dist/function/once.spec.d.ts +0 -1
- package/dist/function/throttle.spec.d.ts +0 -1
- package/dist/math/clamp.spec.d.ts +0 -1
- package/dist/math/round.spec.d.ts +0 -1
- package/dist/math/sum.spec.d.ts +0 -1
- package/dist/object/omit.spec.d.ts +0 -1
- package/dist/object/omitBy.spec.d.ts +0 -1
- package/dist/object/pick.spec.d.ts +0 -1
- package/dist/object/pickBy.spec.d.ts +0 -1
- package/dist/predicate/isNil.spec.d.ts +0 -1
- package/dist/predicate/isNotNil.spec.d.ts +0 -1
- package/dist/predicate/isNull.spec.d.ts +0 -1
- package/dist/predicate/isUndefined.spec.d.ts +0 -1
- package/dist/promise/delay.spec.d.ts +0 -1
- package/esm/_virtual/_rollupPluginBabelHelpers.mjs +0 -163
- package/esm/array/_virtual/_rollupPluginBabelHelpers.mjs +0 -78
- package/esm/array/uniq.mjs +0 -37
- package/esm/array/uniqWith.mjs +0 -39
- package/esm/array/zip.mjs +0 -52
- package/esm/math/_virtual/_rollupPluginBabelHelpers.mjs +0 -66
- package/esm/math/sum.mjs +0 -33
- package/esm/object/_virtual/_rollupPluginBabelHelpers.mjs +0 -151
- /package/{esm/array/index.mjs → dist/array/index.d.mts} +0 -0
- /package/{esm/function/index.mjs → dist/function/index.d.mts} +0 -0
- /package/{esm/index.mjs → dist/index.d.mts} +0 -0
- /package/{esm/math/index.mjs → dist/math/index.d.mts} +0 -0
- /package/{esm/object/index.mjs → dist/object/index.d.mts} +0 -0
- /package/{esm/predicate/index.mjs → dist/predicate/index.d.mts} +0 -0
- /package/{esm/promise/index.mjs → dist/promise/index.d.mts} +0 -0
package/dist/array/index.js
CHANGED
|
@@ -1,562 +1,192 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/array/index.ts
|
|
21
|
+
var array_exports = {};
|
|
22
|
+
__export(array_exports, {
|
|
23
|
+
chunk: () => chunk,
|
|
24
|
+
difference: () => difference,
|
|
25
|
+
differenceBy: () => differenceBy,
|
|
26
|
+
differenceWith: () => differenceWith,
|
|
27
|
+
drop: () => drop,
|
|
28
|
+
dropRight: () => dropRight,
|
|
29
|
+
dropRightWhile: () => dropRightWhile,
|
|
30
|
+
dropWhile: () => dropWhile,
|
|
31
|
+
groupBy: () => groupBy,
|
|
32
|
+
intersection: () => intersection,
|
|
33
|
+
intersectionBy: () => intersectionBy,
|
|
34
|
+
intersectionWith: () => intersectionWith,
|
|
35
|
+
partition: () => partition,
|
|
36
|
+
sample: () => sample,
|
|
37
|
+
shuffle: () => shuffle,
|
|
38
|
+
take: () => take,
|
|
39
|
+
takeRight: () => takeRight,
|
|
40
|
+
takeRightWhile: () => takeRightWhile,
|
|
41
|
+
takeWhile: () => takeWhile,
|
|
42
|
+
union: () => union,
|
|
43
|
+
unionBy: () => unionBy,
|
|
44
|
+
unionWith: () => unionWith,
|
|
45
|
+
uniq: () => uniq,
|
|
46
|
+
uniqBy: () => uniqBy,
|
|
47
|
+
uniqWith: () => uniqWith,
|
|
48
|
+
xor: () => xor,
|
|
49
|
+
xorBy: () => xorBy,
|
|
50
|
+
xorWith: () => xorWith,
|
|
51
|
+
zip: () => zip,
|
|
52
|
+
zipWith: () => zipWith
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(array_exports);
|
|
55
|
+
|
|
56
|
+
// src/array/chunk.ts
|
|
28
57
|
function chunk(arr, size) {
|
|
29
58
|
if (!Number.isInteger(size) || size <= 0) {
|
|
30
|
-
throw new Error(
|
|
59
|
+
throw new Error("Size must be an integer greater than zero.");
|
|
31
60
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
for (
|
|
35
|
-
|
|
36
|
-
|
|
61
|
+
const chunkLength = Math.ceil(arr.length / size);
|
|
62
|
+
const result = Array(chunkLength);
|
|
63
|
+
for (let index = 0; index < chunkLength; index++) {
|
|
64
|
+
const start = index * size;
|
|
65
|
+
const end = start + size;
|
|
37
66
|
result[index] = arr.slice(start, end);
|
|
38
67
|
}
|
|
39
68
|
return result;
|
|
40
69
|
}
|
|
41
70
|
|
|
42
|
-
|
|
43
|
-
* Computes the difference between two arrays.
|
|
44
|
-
*
|
|
45
|
-
* This function takes two arrays and returns a new array containing the elements
|
|
46
|
-
* that are present in the first array but not in the second array. It effectively
|
|
47
|
-
* filters out any elements from the first array that also appear in the second array.
|
|
48
|
-
*
|
|
49
|
-
* @template T
|
|
50
|
-
* @param {T[]} firstArr - The array from which to derive the difference. This is the primary array
|
|
51
|
-
* from which elements will be compared and filtered.
|
|
52
|
-
* @param {T[]} secondArr - The array containing elements to be excluded from the first array.
|
|
53
|
-
* Each element in this array will be checked against the first array, and if a match is found,
|
|
54
|
-
* that element will be excluded from the result.
|
|
55
|
-
* @returns {T[]} A new array containing the elements that are present in the first array but not
|
|
56
|
-
* in the second array.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* * const array1 = [1, 2, 3, 4, 5];
|
|
60
|
-
* const array2 = [2, 4];
|
|
61
|
-
* const result = difference(array1, array2);
|
|
62
|
-
* // result will be [1, 3, 5] since 2 and 4 are in both arrays and are excluded from the result.
|
|
63
|
-
*/
|
|
71
|
+
// src/array/difference.ts
|
|
64
72
|
function difference(firstArr, secondArr) {
|
|
65
|
-
return firstArr.filter(
|
|
73
|
+
return firstArr.filter((item) => {
|
|
66
74
|
return !secondArr.includes(item);
|
|
67
75
|
});
|
|
68
76
|
}
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
* Computes the difference between two arrays after mapping their elements through a provided function.
|
|
72
|
-
*
|
|
73
|
-
* This function takes two arrays and a mapper function. It returns a new array containing the elements
|
|
74
|
-
* that are present in the first array but not in the second array, based on the identity calculated
|
|
75
|
-
* by the mapper function.
|
|
76
|
-
*
|
|
77
|
-
* Essentially, it filters out any elements from the first array that, when
|
|
78
|
-
* mapped, match an element in the mapped version of the second array.
|
|
79
|
-
*
|
|
80
|
-
* @template T, U
|
|
81
|
-
* @param {T[]} firstArr - The primary array from which to derive the difference.
|
|
82
|
-
* @param {T[]} secondArr - The array containing elements to be excluded from the first array.
|
|
83
|
-
* @param {(value: T) => U} mapper - The function to map the elements of both arrays. This function
|
|
84
|
-
* is applied to each element in both arrays, and the comparison is made based on the mapped values.
|
|
85
|
-
* @returns {T[]} A new array containing the elements from the first array that do not have a corresponding
|
|
86
|
-
* mapped identity in the second array.
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
90
|
-
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
91
|
-
* const mapper = item => item.id;
|
|
92
|
-
* const result = differenceBy(array1, array2, mapper);
|
|
93
|
-
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are in both arrays and are excluded from the result.
|
|
94
|
-
*/
|
|
78
|
+
// src/array/differenceBy.ts
|
|
95
79
|
function differenceBy(firstArr, secondArr, mapper) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
return firstArr.filter(function (item) {
|
|
80
|
+
const mappedSecondArr = secondArr.map((item) => mapper(item));
|
|
81
|
+
return firstArr.filter((item) => {
|
|
100
82
|
return !mappedSecondArr.includes(mapper(item));
|
|
101
83
|
});
|
|
102
84
|
}
|
|
103
85
|
|
|
104
|
-
|
|
105
|
-
* Computes the difference between two arrays based on a custom equality function.
|
|
106
|
-
*
|
|
107
|
-
* This function takes two arrays and a custom comparison function. It returns a new array containing
|
|
108
|
-
* the elements that are present in the first array but not in the second array. The comparison to determine
|
|
109
|
-
* if elements are equal is made using the provided custom function.
|
|
110
|
-
*
|
|
111
|
-
* @template T
|
|
112
|
-
* @param {T[]} firstArr - The array from which to get the difference.
|
|
113
|
-
* @param {T[]} secondArr - The array containing elements to exclude from the first array.
|
|
114
|
-
* @param {(x: T, y: T) => boolean} areItemsEqual - A function to determine if two items are equal.
|
|
115
|
-
* @returns {T[]} A new array containing the elements from the first array that do not match any elements in the second array
|
|
116
|
-
* according to the custom equality function.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
120
|
-
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
121
|
-
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
122
|
-
* const result = differenceWith(array1, array2, areItemsEqual);
|
|
123
|
-
* // result will be [{ id: 1 }, { id: 3 }] since the elements with id 2 are considered equal and are excluded from the result.
|
|
124
|
-
*/
|
|
86
|
+
// src/array/differenceWith.ts
|
|
125
87
|
function differenceWith(firstArr, secondArr, areItemsEqual) {
|
|
126
|
-
return firstArr.filter(
|
|
127
|
-
return secondArr.every(
|
|
88
|
+
return firstArr.filter((firstItem) => {
|
|
89
|
+
return secondArr.every((secondItem) => {
|
|
128
90
|
return !areItemsEqual(firstItem, secondItem);
|
|
129
91
|
});
|
|
130
92
|
});
|
|
131
93
|
}
|
|
132
94
|
|
|
133
|
-
|
|
134
|
-
* Removes a specified number of elements from the beginning of an array and returns the rest.
|
|
135
|
-
*
|
|
136
|
-
* This function takes an array and a number, and returns a new array with the specified number
|
|
137
|
-
* of elements removed from the start.
|
|
138
|
-
*
|
|
139
|
-
* @param {T[]} arr - The array from which to drop elements.
|
|
140
|
-
* @param {number} itemsCount - The number of elements to drop from the beginning of the array.
|
|
141
|
-
* @returns {T[]} A new array with the specified number of elements removed from the start.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* * const array = [1, 2, 3, 4, 5];
|
|
145
|
-
* const result = drop(array, 2);
|
|
146
|
-
* // result will be [3, 4, 5] since the first two elements are dropped.
|
|
147
|
-
*/
|
|
95
|
+
// src/array/drop.ts
|
|
148
96
|
function drop(arr, itemsCount) {
|
|
149
97
|
return arr.slice(itemsCount);
|
|
150
98
|
}
|
|
151
99
|
|
|
152
|
-
|
|
153
|
-
* Removes a specified number of elements from the end of an array and returns the rest.
|
|
154
|
-
*
|
|
155
|
-
* This function takes an array and a number, and returns a new array with the specified number
|
|
156
|
-
* of elements removed from the end.
|
|
157
|
-
*
|
|
158
|
-
* @param {T[]} arr - The array from which to drop elements.
|
|
159
|
-
* @param {number} itemsCount - The number of elements to drop from the end of the array.
|
|
160
|
-
* @returns {T[]} A new array with the specified number of elements removed from the end.
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* * const array = [1, 2, 3, 4, 5];
|
|
164
|
-
* const result = dropRight(array, 2);
|
|
165
|
-
* // result will be [1, 2, 3] since the last two elements are dropped.
|
|
166
|
-
*/
|
|
100
|
+
// src/array/dropRight.ts
|
|
167
101
|
function dropRight(arr, itemsCount) {
|
|
168
102
|
return arr.slice(0, -itemsCount);
|
|
169
103
|
}
|
|
170
104
|
|
|
171
|
-
|
|
172
|
-
* Removes elements from the beginning of an array until the predicate returns false.
|
|
173
|
-
*
|
|
174
|
-
* This function iterates over an array and drops elements from the start until the provided
|
|
175
|
-
* predicate function returns false. It then returns a new array with the remaining elements.
|
|
176
|
-
*
|
|
177
|
-
* @param {T[]} arr - The array from which to drop elements.
|
|
178
|
-
* @param {(item: T) => boolean} canContinueDropping - A predicate function that determines
|
|
179
|
-
* whether to continue dropping elements. The function is called with each element, and dropping
|
|
180
|
-
* continues as long as it returns true.
|
|
181
|
-
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* const array = [1, 2, 3, 4, 5];
|
|
185
|
-
* const result = dropWhile(array, x => x < 3);
|
|
186
|
-
* // result will be [3, 4, 5] since elements less than 3 are dropped.
|
|
187
|
-
*/
|
|
105
|
+
// src/array/dropWhile.ts
|
|
188
106
|
function dropWhile(arr, canContinueDropping) {
|
|
189
|
-
|
|
190
|
-
return !canContinueDropping(item);
|
|
191
|
-
});
|
|
107
|
+
const dropEndIndex = arr.findIndex((item) => !canContinueDropping(item));
|
|
192
108
|
return arr.slice(dropEndIndex);
|
|
193
109
|
}
|
|
194
110
|
|
|
195
|
-
|
|
196
|
-
* Removes elements from the end of an array until the predicate returns false.
|
|
197
|
-
*
|
|
198
|
-
* This function iterates over an array from the end and drops elements until the provided
|
|
199
|
-
* predicate function returns false. It then returns a new array with the remaining elements.
|
|
200
|
-
*
|
|
201
|
-
* @param {T[]} arr - The array from which to drop elements.
|
|
202
|
-
* @param {function(item: T): boolean} canContinueDropping - A predicate function that determines
|
|
203
|
-
* whether to continue dropping elements. The function is called with each element from the end,
|
|
204
|
-
* and dropping continues as long as it returns true.
|
|
205
|
-
* @returns {T[]} A new array with the elements remaining after the predicate returns false.
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* const array = [1, 2, 3, 4, 5];
|
|
209
|
-
* const result = dropRightWhile(array, x => x > 3);
|
|
210
|
-
* // result will be [1, 2, 3] since elements greater than 3 are dropped from the end.
|
|
211
|
-
*/
|
|
111
|
+
// src/array/dropRightWhile.ts
|
|
212
112
|
function dropRightWhile(arr, canContinueDropping) {
|
|
213
|
-
|
|
214
|
-
|
|
113
|
+
const reversed = arr.slice().reverse();
|
|
114
|
+
const dropped = dropWhile(reversed, canContinueDropping);
|
|
215
115
|
return dropped.slice().reverse();
|
|
216
116
|
}
|
|
217
117
|
|
|
218
|
-
|
|
219
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
220
|
-
}
|
|
221
|
-
function _arrayWithoutHoles(arr) {
|
|
222
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
223
|
-
}
|
|
224
|
-
function _iterableToArray(iter) {
|
|
225
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
226
|
-
}
|
|
227
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
228
|
-
if (!o) return;
|
|
229
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
230
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
231
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
232
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
233
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
234
|
-
}
|
|
235
|
-
function _arrayLikeToArray(arr, len) {
|
|
236
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
237
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
238
|
-
return arr2;
|
|
239
|
-
}
|
|
240
|
-
function _nonIterableSpread() {
|
|
241
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
242
|
-
}
|
|
243
|
-
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
244
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
245
|
-
if (!it) {
|
|
246
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
247
|
-
if (it) o = it;
|
|
248
|
-
var i = 0;
|
|
249
|
-
var F = function () {};
|
|
250
|
-
return {
|
|
251
|
-
s: F,
|
|
252
|
-
n: function () {
|
|
253
|
-
if (i >= o.length) return {
|
|
254
|
-
done: true
|
|
255
|
-
};
|
|
256
|
-
return {
|
|
257
|
-
done: false,
|
|
258
|
-
value: o[i++]
|
|
259
|
-
};
|
|
260
|
-
},
|
|
261
|
-
e: function (e) {
|
|
262
|
-
throw e;
|
|
263
|
-
},
|
|
264
|
-
f: F
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
268
|
-
}
|
|
269
|
-
var normalCompletion = true,
|
|
270
|
-
didErr = false,
|
|
271
|
-
err;
|
|
272
|
-
return {
|
|
273
|
-
s: function () {
|
|
274
|
-
it = it.call(o);
|
|
275
|
-
},
|
|
276
|
-
n: function () {
|
|
277
|
-
var step = it.next();
|
|
278
|
-
normalCompletion = step.done;
|
|
279
|
-
return step;
|
|
280
|
-
},
|
|
281
|
-
e: function (e) {
|
|
282
|
-
didErr = true;
|
|
283
|
-
err = e;
|
|
284
|
-
},
|
|
285
|
-
f: function () {
|
|
286
|
-
try {
|
|
287
|
-
if (!normalCompletion && it.return != null) it.return();
|
|
288
|
-
} finally {
|
|
289
|
-
if (didErr) throw err;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Groups the elements of an array based on a provided key-generating function.
|
|
297
|
-
*
|
|
298
|
-
* This function takes an array and a function that generates a key from each element. It returns
|
|
299
|
-
* an object where the keys are the generated keys and the values are arrays of elements that share
|
|
300
|
-
* the same key.
|
|
301
|
-
*
|
|
302
|
-
* @param {T[]} arr - The array to group.
|
|
303
|
-
* @param {(item: T) => K} getKeyFromItem - A function that generates a key from an element.
|
|
304
|
-
* @returns {Record<K, T[]>} An object where each key is associated with an array of elements that
|
|
305
|
-
* share that key.
|
|
306
|
-
*
|
|
307
|
-
* @example
|
|
308
|
-
* const array = [
|
|
309
|
-
* { category: 'fruit', name: 'apple' },
|
|
310
|
-
* { category: 'fruit', name: 'banana' },
|
|
311
|
-
* { category: 'vegetable', name: 'carrot' }
|
|
312
|
-
* ];
|
|
313
|
-
* const result = groupBy(array, item => item.category);
|
|
314
|
-
* // result will be:
|
|
315
|
-
* // {
|
|
316
|
-
* // fruit: [
|
|
317
|
-
* // { category: 'fruit', name: 'apple' },
|
|
318
|
-
* // { category: 'fruit', name: 'banana' }
|
|
319
|
-
* // ],
|
|
320
|
-
* // vegetable: [
|
|
321
|
-
* // { category: 'vegetable', name: 'carrot' }
|
|
322
|
-
* // ]
|
|
323
|
-
* // }
|
|
324
|
-
*/
|
|
118
|
+
// src/array/groupBy.ts
|
|
325
119
|
function groupBy(arr, getKeyFromItem) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
var item = _step.value;
|
|
332
|
-
var key = getKeyFromItem(item);
|
|
333
|
-
if (result[key] == null) {
|
|
334
|
-
result[key] = [];
|
|
335
|
-
}
|
|
336
|
-
result[key].push(item);
|
|
120
|
+
const result = {};
|
|
121
|
+
for (const item of arr) {
|
|
122
|
+
const key = getKeyFromItem(item);
|
|
123
|
+
if (result[key] == null) {
|
|
124
|
+
result[key] = [];
|
|
337
125
|
}
|
|
338
|
-
|
|
339
|
-
_iterator.e(err);
|
|
340
|
-
} finally {
|
|
341
|
-
_iterator.f();
|
|
126
|
+
result[key].push(item);
|
|
342
127
|
}
|
|
343
128
|
return result;
|
|
344
129
|
}
|
|
345
130
|
|
|
346
|
-
|
|
347
|
-
* Returns the intersection of two arrays.
|
|
348
|
-
*
|
|
349
|
-
* This function takes two arrays and returns a new array containing the elements that are
|
|
350
|
-
* present in both arrays. It effectively filters out any elements from the first array that
|
|
351
|
-
* are not found in the second array.
|
|
352
|
-
*
|
|
353
|
-
* @param {T[]} firstArr - The first array to compare.
|
|
354
|
-
* @param {T[]} secondArr - The second array to compare.
|
|
355
|
-
* @returns {T[]} A new array containing the elements that are present in both arrays.
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* const array1 = [1, 2, 3, 4, 5];
|
|
359
|
-
* const array2 = [3, 4, 5, 6, 7];
|
|
360
|
-
* const result = intersection(array1, array2);
|
|
361
|
-
* // result will be [3, 4, 5] since these elements are in both arrays.
|
|
362
|
-
*/
|
|
131
|
+
// src/array/intersection.ts
|
|
363
132
|
function intersection(firstArr, secondArr) {
|
|
364
|
-
return firstArr.filter(
|
|
133
|
+
return firstArr.filter((item) => {
|
|
365
134
|
return secondArr.includes(item);
|
|
366
135
|
});
|
|
367
136
|
}
|
|
368
137
|
|
|
369
|
-
|
|
370
|
-
* Returns the intersection of two arrays based on a mapping function.
|
|
371
|
-
*
|
|
372
|
-
* This function takes two arrays and a mapping function. It returns a new array containing
|
|
373
|
-
* the elements from the first array that, when mapped using the provided function, have matching
|
|
374
|
-
* mapped elements in the second array. It effectively filters out any elements from the first array
|
|
375
|
-
* that do not have corresponding mapped values in the second array.
|
|
376
|
-
*
|
|
377
|
-
* @param {T[]} firstArr - The first array to compare.
|
|
378
|
-
* @param {T[]} secondArr - The second array to compare.
|
|
379
|
-
* @param {(item: T) => U} mapper - A function to map the elements of both arrays for comparison.
|
|
380
|
-
* @returns {T[]} A new array containing the elements from the first array that have corresponding mapped values in the second array.
|
|
381
|
-
*
|
|
382
|
-
* @example
|
|
383
|
-
* const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
384
|
-
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
385
|
-
* const mapper = item => item.id;
|
|
386
|
-
* const result = intersectionBy(array1, array2, mapper);
|
|
387
|
-
* // result will be [{ id: 2 }] since only this element has a matching id in both arrays.
|
|
388
|
-
*/
|
|
138
|
+
// src/array/intersectionBy.ts
|
|
389
139
|
function intersectionBy(firstArr, secondArr, mapper) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
});
|
|
393
|
-
return firstArr.filter(function (item) {
|
|
140
|
+
const mappedSecondArr = secondArr.map((x) => mapper(x));
|
|
141
|
+
return firstArr.filter((item) => {
|
|
394
142
|
return mappedSecondArr.includes(mapper(item));
|
|
395
143
|
});
|
|
396
144
|
}
|
|
397
145
|
|
|
398
|
-
|
|
399
|
-
* Returns the intersection of two arrays based on a custom equality function.
|
|
400
|
-
*
|
|
401
|
-
* This function takes two arrays and a custom equality function. It returns a new array containing
|
|
402
|
-
* the elements from the first array that have matching elements in the second array, as determined
|
|
403
|
-
* by the custom equality function. It effectively filters out any elements from the first array that
|
|
404
|
-
* do not have corresponding matches in the second array according to the equality function.
|
|
405
|
-
*
|
|
406
|
-
* @param {T[]} firstArr - The first array to compare.
|
|
407
|
-
* @param {T[]} secondArr - The second array to compare.
|
|
408
|
-
* @param {(x: T, y: T) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
|
|
409
|
-
* This function takes two arguments, one from each array, and returns `true` if the elements are considered equal, and `false` otherwise.
|
|
410
|
-
* @returns {T[]} A new array containing the elements from the first array that have corresponding matches in the second array according to the custom equality function.
|
|
411
|
-
*
|
|
412
|
-
* @example
|
|
413
|
-
* * const array1 = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
414
|
-
* const array2 = [{ id: 2 }, { id: 4 }];
|
|
415
|
-
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
416
|
-
* const result = intersectionWith(array1, array2, areItemsEqual);
|
|
417
|
-
* // result will be [{ id: 2 }] since this element has a matching id in both arrays.
|
|
418
|
-
*/
|
|
146
|
+
// src/array/intersectionWith.ts
|
|
419
147
|
function intersectionWith(firstArr, secondArr, areItemsEqual) {
|
|
420
|
-
return firstArr.filter(
|
|
421
|
-
return secondArr.some(
|
|
148
|
+
return firstArr.filter((firstItem) => {
|
|
149
|
+
return secondArr.some((secondItem) => {
|
|
422
150
|
return areItemsEqual(firstItem, secondItem);
|
|
423
151
|
});
|
|
424
152
|
});
|
|
425
153
|
}
|
|
426
154
|
|
|
427
|
-
|
|
428
|
-
* Splits an array into two groups based on a predicate function.
|
|
429
|
-
*
|
|
430
|
-
* This function takes an array and a predicate function. It returns a tuple of two arrays:
|
|
431
|
-
* the first array contains elements for which the predicate function returns true, and
|
|
432
|
-
* the second array contains elements for which the predicate function returns false.
|
|
433
|
-
*
|
|
434
|
-
* @param {T[]} arr - The array to partition.
|
|
435
|
-
* @param {(value: T) => boolean} isInTruthy - A predicate function that determines
|
|
436
|
-
* whether an element should be placed in the truthy array. The function is called with each
|
|
437
|
-
* element of the array.
|
|
438
|
-
* @returns {[T[], T[]]} A tuple containing two arrays: the first array contains elements for
|
|
439
|
-
* which the predicate returned true, and the second array contains elements for which the
|
|
440
|
-
* predicate returned false.
|
|
441
|
-
*
|
|
442
|
-
* @example
|
|
443
|
-
* const array = [1, 2, 3, 4, 5];
|
|
444
|
-
* const isEven = x => x % 2 === 0;
|
|
445
|
-
* const [even, odd] = partition(array, isEven);
|
|
446
|
-
* // even will be [2, 4], and odd will be [1, 3, 5]
|
|
447
|
-
*/
|
|
155
|
+
// src/array/partition.ts
|
|
448
156
|
function partition(arr, isInTruthy) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
if (isInTruthy(item)) {
|
|
457
|
-
truthy.push(item);
|
|
458
|
-
} else {
|
|
459
|
-
falsy.push(item);
|
|
460
|
-
}
|
|
157
|
+
const truthy = [];
|
|
158
|
+
const falsy = [];
|
|
159
|
+
for (const item of arr) {
|
|
160
|
+
if (isInTruthy(item)) {
|
|
161
|
+
truthy.push(item);
|
|
162
|
+
} else {
|
|
163
|
+
falsy.push(item);
|
|
461
164
|
}
|
|
462
|
-
} catch (err) {
|
|
463
|
-
_iterator.e(err);
|
|
464
|
-
} finally {
|
|
465
|
-
_iterator.f();
|
|
466
165
|
}
|
|
467
166
|
return [truthy, falsy];
|
|
468
167
|
}
|
|
469
168
|
|
|
470
|
-
|
|
471
|
-
* Returns a random element from an array.
|
|
472
|
-
*
|
|
473
|
-
* This function takes an array and returns a single element selected randomly from the array.
|
|
474
|
-
*
|
|
475
|
-
* @param {T[]} arr - The array to sample from.
|
|
476
|
-
* @returns {T} A random element from the array.
|
|
477
|
-
*
|
|
478
|
-
* @example
|
|
479
|
-
* const array = [1, 2, 3, 4, 5];
|
|
480
|
-
* const randomElement = sample(array);
|
|
481
|
-
* // randomElement will be one of the elements from the array, selected randomly.
|
|
482
|
-
*/
|
|
169
|
+
// src/array/sample.ts
|
|
483
170
|
function sample(arr) {
|
|
484
|
-
|
|
171
|
+
const randomIndex = Math.floor(Math.random() * arr.length);
|
|
485
172
|
return arr[randomIndex];
|
|
486
173
|
}
|
|
487
174
|
|
|
488
|
-
|
|
489
|
-
* Randomizes the order of elements in an array using the Fisher-Yates algorithm.
|
|
490
|
-
*
|
|
491
|
-
* This function takes an array and returns a new array with its elements shuffled in a random order.
|
|
492
|
-
*
|
|
493
|
-
* @param {T[]} arr - The array to shuffle.
|
|
494
|
-
* @returns {T[]} A new array with its elements shuffled in random order.
|
|
495
|
-
*
|
|
496
|
-
* @example
|
|
497
|
-
* const array = [1, 2, 3, 4, 5];
|
|
498
|
-
* const shuffledArray = shuffle(array);
|
|
499
|
-
* // shuffledArray will be a new array with elements of array in random order, e.g., [3, 1, 4, 5, 2]
|
|
500
|
-
*/
|
|
175
|
+
// src/array/shuffle.ts
|
|
501
176
|
function shuffle(arr) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
for (var i = arr.length - 1; i >= 1; i--) {
|
|
506
|
-
var j = Math.floor(Math.random() * (i + 1));
|
|
507
|
-
var _ref = [arr[j], arr[i]];
|
|
508
|
-
arr[i] = _ref[0];
|
|
509
|
-
arr[j] = _ref[1];
|
|
177
|
+
for (let i = arr.length - 1; i >= 1; i--) {
|
|
178
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
179
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
510
180
|
}
|
|
511
181
|
return arr;
|
|
512
182
|
}
|
|
513
183
|
|
|
514
|
-
|
|
515
|
-
* Returns a new array containing the first `count` elements from the input array `arr`.
|
|
516
|
-
* If `count` is greater than the length of `arr`, the entire array is returned.
|
|
517
|
-
*
|
|
518
|
-
* @template T - Type of elements in the input array.
|
|
519
|
-
*
|
|
520
|
-
* @param {T[]} arr - The array to take elements from.
|
|
521
|
-
* @param {number} count - The number of elements to take.
|
|
522
|
-
* @returns {T[]} A new array containing the first `count` elements from `arr`.
|
|
523
|
-
*
|
|
524
|
-
* @example
|
|
525
|
-
* // Returns [1, 2, 3]
|
|
526
|
-
* take([1, 2, 3, 4, 5], 3);
|
|
527
|
-
*
|
|
528
|
-
* @example
|
|
529
|
-
* // Returns ['a', 'b']
|
|
530
|
-
* take(['a', 'b', 'c'], 2);
|
|
531
|
-
*
|
|
532
|
-
* @example
|
|
533
|
-
* // Returns [1, 2, 3]
|
|
534
|
-
* take([1, 2, 3], 5);
|
|
535
|
-
*/
|
|
184
|
+
// src/array/take.ts
|
|
536
185
|
function take(arr, count) {
|
|
537
186
|
return arr.slice(0, count);
|
|
538
187
|
}
|
|
539
188
|
|
|
540
|
-
|
|
541
|
-
* Returns a new array containing the last `count` elements from the input array `arr`.
|
|
542
|
-
* If `count` is greater than the length of `arr`, the entire array is returned.
|
|
543
|
-
*
|
|
544
|
-
* @param {T[]} arr - The array to take elements from.
|
|
545
|
-
* @param {number} count - The number of elements to take.
|
|
546
|
-
* @returns {T[]} A new array containing the last `count` elements from `arr`.
|
|
547
|
-
*
|
|
548
|
-
* @example
|
|
549
|
-
* // Returns [4, 5]
|
|
550
|
-
* takeRight([1, 2, 3, 4, 5], 2);
|
|
551
|
-
*
|
|
552
|
-
* @example
|
|
553
|
-
* // Returns ['b', 'c']
|
|
554
|
-
* takeRight(['a', 'b', 'c'], 2);
|
|
555
|
-
*
|
|
556
|
-
* @example
|
|
557
|
-
* // Returns [1, 2, 3]
|
|
558
|
-
* takeRight([1, 2, 3], 5);
|
|
559
|
-
*/
|
|
189
|
+
// src/array/takeRight.ts
|
|
560
190
|
function takeRight(arr, count) {
|
|
561
191
|
if (count === 0) {
|
|
562
192
|
return [];
|
|
@@ -564,25 +194,9 @@ function takeRight(arr, count) {
|
|
|
564
194
|
return arr.slice(-count);
|
|
565
195
|
}
|
|
566
196
|
|
|
567
|
-
|
|
568
|
-
* Takes elements from the end of the array while the predicate function returns `true`.
|
|
569
|
-
*
|
|
570
|
-
* @template T - Type of elements in the input array.
|
|
571
|
-
*
|
|
572
|
-
* @param {T[]} arr - The array to take elements from.
|
|
573
|
-
* @param {function(T): boolean} shouldContinueTaking - The function invoked per element.
|
|
574
|
-
* @returns {T[]} A new array containing the elements taken from the end while the predicate returns `true`.
|
|
575
|
-
*
|
|
576
|
-
* @example
|
|
577
|
-
* // Returns [3, 2, 1]
|
|
578
|
-
* takeRightWhile([5, 4, 3, 2, 1], n => n < 4);
|
|
579
|
-
*
|
|
580
|
-
* @example
|
|
581
|
-
* // Returns []
|
|
582
|
-
* takeRightWhile([1, 2, 3], n => n > 3);
|
|
583
|
-
*/
|
|
197
|
+
// src/array/takeRightWhile.ts
|
|
584
198
|
function takeRightWhile(arr, shouldContinueTaking) {
|
|
585
|
-
for (
|
|
199
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
586
200
|
if (!shouldContinueTaking(arr[i])) {
|
|
587
201
|
return arr.slice(i + 1);
|
|
588
202
|
}
|
|
@@ -590,402 +204,145 @@ function takeRightWhile(arr, shouldContinueTaking) {
|
|
|
590
204
|
return arr.slice();
|
|
591
205
|
}
|
|
592
206
|
|
|
593
|
-
|
|
594
|
-
* Returns a new array containing the leading elements of the provided array
|
|
595
|
-
* that satisfy the provided predicate function. It stops taking elements as soon
|
|
596
|
-
* as an element does not satisfy the predicate.
|
|
597
|
-
*
|
|
598
|
-
* @template T - The type of elements in the array.
|
|
599
|
-
* @param {T[]} arr - The array to process.
|
|
600
|
-
* @param {(element: T) => boolean} shouldContinueTaking - The predicate function that is called with each element. Elements are included in the result as long as this function returns true.
|
|
601
|
-
* @returns {T[]} A new array containing the leading elements that satisfy the predicate.
|
|
602
|
-
*
|
|
603
|
-
* @example
|
|
604
|
-
* // Returns [1, 2]
|
|
605
|
-
* takeWhile([1, 2, 3, 4], x => x < 3);
|
|
606
|
-
*
|
|
607
|
-
* @example
|
|
608
|
-
* // Returns []
|
|
609
|
-
* takeWhile([1, 2, 3, 4], x => x > 3);
|
|
610
|
-
*/
|
|
207
|
+
// src/array/takeWhile.ts
|
|
611
208
|
function takeWhile(arr, shouldContinueTaking) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
617
|
-
var item = _step.value;
|
|
618
|
-
if (!shouldContinueTaking(item)) {
|
|
619
|
-
break;
|
|
620
|
-
}
|
|
621
|
-
result.push(item);
|
|
209
|
+
const result = [];
|
|
210
|
+
for (const item of arr) {
|
|
211
|
+
if (!shouldContinueTaking(item)) {
|
|
212
|
+
break;
|
|
622
213
|
}
|
|
623
|
-
|
|
624
|
-
_iterator.e(err);
|
|
625
|
-
} finally {
|
|
626
|
-
_iterator.f();
|
|
214
|
+
result.push(item);
|
|
627
215
|
}
|
|
628
216
|
return result;
|
|
629
217
|
}
|
|
630
218
|
|
|
631
|
-
|
|
632
|
-
* Creates a duplicate-free version of an array.
|
|
633
|
-
*
|
|
634
|
-
* This function takes an array and returns a new array containing only the unique values
|
|
635
|
-
* from the original array, preserving the order of first occurrence.
|
|
636
|
-
*
|
|
637
|
-
* @param {T[]} arr - The array to process.
|
|
638
|
-
* @returns {T[]} A new array with only unique values from the original array.
|
|
639
|
-
*
|
|
640
|
-
* @example
|
|
641
|
-
* * const array = [1, 2, 2, 3, 4, 4, 5];
|
|
642
|
-
* const result = uniq(array);
|
|
643
|
-
* // result will be [1, 2, 3, 4, 5]
|
|
644
|
-
*/
|
|
219
|
+
// src/array/uniq.ts
|
|
645
220
|
function uniq(arr) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
651
|
-
var item = _step.value;
|
|
652
|
-
if (result.includes(item)) {
|
|
653
|
-
continue;
|
|
654
|
-
}
|
|
655
|
-
result.push(item);
|
|
221
|
+
const result = [];
|
|
222
|
+
for (const item of arr) {
|
|
223
|
+
if (result.includes(item)) {
|
|
224
|
+
continue;
|
|
656
225
|
}
|
|
657
|
-
|
|
658
|
-
_iterator.e(err);
|
|
659
|
-
} finally {
|
|
660
|
-
_iterator.f();
|
|
226
|
+
result.push(item);
|
|
661
227
|
}
|
|
662
228
|
return result;
|
|
663
229
|
}
|
|
664
230
|
|
|
665
|
-
|
|
666
|
-
* Creates an array of unique values from all given arrays.
|
|
667
|
-
*
|
|
668
|
-
* This function takes two arrays, merges them into a single array, and returns a new array
|
|
669
|
-
* containing only the unique values from the merged array.
|
|
670
|
-
*
|
|
671
|
-
* @param {T[]} arr1 - The first array to merge and filter for unique values.
|
|
672
|
-
* @param {T[]} arr2 - The second array to merge and filter for unique values.
|
|
673
|
-
* @returns {T[]} A new array of unique values.
|
|
674
|
-
*
|
|
675
|
-
* @example
|
|
676
|
-
* const array1 = [1, 2, 3];
|
|
677
|
-
* const array2 = [3, 4, 5];
|
|
678
|
-
* const result = union(array1, array2);
|
|
679
|
-
* // result will be [1, 2, 3, 4, 5]
|
|
680
|
-
*/
|
|
231
|
+
// src/array/union.ts
|
|
681
232
|
function union(arr1, arr2) {
|
|
682
233
|
return uniq(arr1.concat(arr2));
|
|
683
234
|
}
|
|
684
235
|
|
|
685
|
-
|
|
686
|
-
* Creates an array of unique values, in order, from all given arrays using a provided mapping function to determine equality.
|
|
687
|
-
*
|
|
688
|
-
* @param {T[]} arr1 - The first array.
|
|
689
|
-
* @param {T[]} arr2 - The second array.
|
|
690
|
-
* @param {function(item: T): U} mapper - The function to map array elements to comparison values.
|
|
691
|
-
* @returns {T[]} A new array containing the union of unique elements from `arr1` and `arr2`, based on the values returned by the mapping function.
|
|
692
|
-
*
|
|
693
|
-
* @example
|
|
694
|
-
* // Custom mapping function for numbers (modulo comparison)
|
|
695
|
-
* const moduloMapper = (x) => x % 3;
|
|
696
|
-
* unionBy([1, 2, 3], [4, 5, 6], moduloMapper);
|
|
697
|
-
* // Returns [1, 2, 3]
|
|
698
|
-
*
|
|
699
|
-
* @example
|
|
700
|
-
* // Custom mapping function for objects with an 'id' property
|
|
701
|
-
* const idMapper = (obj) => obj.id;
|
|
702
|
-
* unionBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper);
|
|
703
|
-
* // Returns [{ id: 1 }, { id: 2 }, { id: 3 }]
|
|
704
|
-
*/
|
|
236
|
+
// src/array/unionBy.ts
|
|
705
237
|
function unionBy(arr1, arr2, mapper) {
|
|
706
|
-
|
|
707
|
-
for (
|
|
708
|
-
|
|
709
|
-
var key = mapper(item);
|
|
238
|
+
const map = /* @__PURE__ */ new Map();
|
|
239
|
+
for (const item of [...arr1, ...arr2]) {
|
|
240
|
+
const key = mapper(item);
|
|
710
241
|
if (!map.has(key)) {
|
|
711
242
|
map.set(key, item);
|
|
712
243
|
}
|
|
713
244
|
}
|
|
714
|
-
return
|
|
245
|
+
return [...map.values()];
|
|
715
246
|
}
|
|
716
247
|
|
|
717
|
-
|
|
718
|
-
* The `uniqWith` function takes an array as its first argument and a 'comparator' function as the second.
|
|
719
|
-
*
|
|
720
|
-
* It evaluates the elements of the array using the comparator function, and if true is returned, it considers those elements as duplicates and removes them.
|
|
721
|
-
*
|
|
722
|
-
* @example
|
|
723
|
-
* ```ts
|
|
724
|
-
* uniqWith([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], (a, b) => Math.abs(a - b) < 1);
|
|
725
|
-
* // [1, 2, 3, 5, 7]
|
|
726
|
-
* ```
|
|
727
|
-
*/
|
|
248
|
+
// src/array/uniqWith.ts
|
|
728
249
|
function uniqWith(arr, areItemsEqual) {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
var item = _step.value;
|
|
735
|
-
var isUniq = result.every(function (v) {
|
|
736
|
-
return !areItemsEqual(v, item);
|
|
737
|
-
});
|
|
738
|
-
if (isUniq) {
|
|
739
|
-
result.push(item);
|
|
740
|
-
}
|
|
741
|
-
};
|
|
742
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
743
|
-
_loop();
|
|
250
|
+
const result = [];
|
|
251
|
+
for (const item of arr) {
|
|
252
|
+
const isUniq = result.every((v) => !areItemsEqual(v, item));
|
|
253
|
+
if (isUniq) {
|
|
254
|
+
result.push(item);
|
|
744
255
|
}
|
|
745
|
-
} catch (err) {
|
|
746
|
-
_iterator.e(err);
|
|
747
|
-
} finally {
|
|
748
|
-
_iterator.f();
|
|
749
256
|
}
|
|
750
257
|
return result;
|
|
751
258
|
}
|
|
752
259
|
|
|
753
|
-
|
|
754
|
-
* Creates an array of unique values from two given arrays based on a custom equality function.
|
|
755
|
-
*
|
|
756
|
-
* This function takes two arrays and a custom equality function, merges the arrays, and returns
|
|
757
|
-
* a new array containing only the unique values as determined by the custom equality function.
|
|
758
|
-
*
|
|
759
|
-
* @param {T[]} arr1 - The first array to merge and filter for unique values.
|
|
760
|
-
* @param {T[]} arr2 - The second array to merge and filter for unique values.
|
|
761
|
-
* @param {(item1: T, item2: T) => boolean} areItemsEqual - A custom function to determine if two elements are equal.
|
|
762
|
-
* It takes two arguments and returns `true` if the elements are considered equal, and `false` otherwise.
|
|
763
|
-
* @returns {T[]} A new array of unique values based on the custom equality function.
|
|
764
|
-
*
|
|
765
|
-
* @example
|
|
766
|
-
* const array1 = [{ id: 1 }, { id: 2 }];
|
|
767
|
-
* const array2 = [{ id: 2 }, { id: 3 }];
|
|
768
|
-
* const areItemsEqual = (a, b) => a.id === b.id;
|
|
769
|
-
* const result = unionWith(array1, array2, areItemsEqual);
|
|
770
|
-
* // result will be [{ id: 1 }, { id: 2 }, { id: 3 }] since { id: 2 } is considered equal in both arrays
|
|
771
|
-
*/
|
|
260
|
+
// src/array/unionWith.ts
|
|
772
261
|
function unionWith(arr1, arr2, areItemsEqual) {
|
|
773
262
|
return uniqWith(arr1.concat(arr2), areItemsEqual);
|
|
774
263
|
}
|
|
775
264
|
|
|
776
|
-
|
|
777
|
-
* The `uniqBy` function takes an array as its first argument and a 'converter' function as the second. It maps the array elements using the converter function, then removes any duplicates.
|
|
778
|
-
*
|
|
779
|
-
* It filters out elements with the same value, meaning it does not check for duplicates in data types like Objects.
|
|
780
|
-
*
|
|
781
|
-
* @example
|
|
782
|
-
* ```ts
|
|
783
|
-
* uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);
|
|
784
|
-
* // [1.2, 2.1, 3.3, 5.7, 7.19]
|
|
785
|
-
* ```
|
|
786
|
-
*/
|
|
265
|
+
// src/array/uniqBy.ts
|
|
787
266
|
function uniqBy(arr, converter) {
|
|
788
|
-
return uniqWith(arr,
|
|
789
|
-
return converter(item1) === converter(item2);
|
|
790
|
-
});
|
|
267
|
+
return uniqWith(arr, (item1, item2) => converter(item1) === converter(item2));
|
|
791
268
|
}
|
|
792
269
|
|
|
793
|
-
|
|
794
|
-
* Computes the symmetric difference between two arrays. The symmetric difference is the set of elements
|
|
795
|
-
* which are in either of the arrays, but not in their intersection.
|
|
796
|
-
*
|
|
797
|
-
* @param {T[]} arr1 - The first array.
|
|
798
|
-
* @param {T[]} arr2 - The second array.
|
|
799
|
-
* @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both.
|
|
800
|
-
*
|
|
801
|
-
* @example
|
|
802
|
-
* // Returns [1, 2, 5, 6]
|
|
803
|
-
* xor([1, 2, 3, 4], [3, 4, 5, 6]);
|
|
804
|
-
*
|
|
805
|
-
* @example
|
|
806
|
-
* // Returns ['a', 'c']
|
|
807
|
-
* xor(['a', 'b'], ['b', 'c']);
|
|
808
|
-
*/
|
|
270
|
+
// src/array/xor.ts
|
|
809
271
|
function xor(arr1, arr2) {
|
|
810
272
|
return difference(union(arr1, arr2), intersection(arr1, arr2));
|
|
811
273
|
}
|
|
812
274
|
|
|
813
|
-
|
|
814
|
-
* Computes the symmetric difference between two arrays using a custom mapping function.
|
|
815
|
-
* The symmetric difference is the set of elements which are in either of the arrays,
|
|
816
|
-
* but not in their intersection, determined by the result of the mapping function.
|
|
817
|
-
*
|
|
818
|
-
* @template T - Type of elements in the input arrays.
|
|
819
|
-
* @template U - Type of the values returned by the mapping function.
|
|
820
|
-
*
|
|
821
|
-
* @param {T[]} arr1 - The first array.
|
|
822
|
-
* @param {T[]} arr2 - The second array.
|
|
823
|
-
* @param {function(item: T): U} mapper - The function to map array elements to comparison values.
|
|
824
|
-
* @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the values returned by the mapping function.
|
|
825
|
-
*
|
|
826
|
-
* @example
|
|
827
|
-
* // Custom mapping function for objects with an 'id' property
|
|
828
|
-
* const idMapper = obj => obj.id;
|
|
829
|
-
* xorBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], idMapper);
|
|
830
|
-
* // Returns [{ id: 1 }, { id: 3 }]
|
|
831
|
-
*/
|
|
275
|
+
// src/array/xorBy.ts
|
|
832
276
|
function xorBy(arr1, arr2, mapper) {
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
return differenceBy(
|
|
277
|
+
const union2 = unionBy(arr1, arr2, mapper);
|
|
278
|
+
const intersection2 = intersectionBy(arr1, arr2, mapper);
|
|
279
|
+
return differenceBy(union2, intersection2, mapper);
|
|
836
280
|
}
|
|
837
281
|
|
|
838
|
-
|
|
839
|
-
* Computes the symmetric difference between two arrays using a custom equality function.
|
|
840
|
-
* The symmetric difference is the set of elements which are in either of the arrays,
|
|
841
|
-
* but not in their intersection.
|
|
842
|
-
*
|
|
843
|
-
* @template T - Type of elements in the input arrays.
|
|
844
|
-
*
|
|
845
|
-
* @param {T[]} arr1 - The first array.
|
|
846
|
-
* @param {T[]} arr2 - The second array.
|
|
847
|
-
* @param {(item1: T, item2: T) => boolean} areElementsEqual - The custom equality function to compare elements.
|
|
848
|
-
* @returns {T[]} An array containing the elements that are present in either `arr1` or `arr2` but not in both, based on the custom equality function.
|
|
849
|
-
*
|
|
850
|
-
* @example
|
|
851
|
-
* // Custom equality function for objects with an 'id' property
|
|
852
|
-
* const areObjectsEqual = (a, b) => a.id === b.id;
|
|
853
|
-
* xorWith([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], areObjectsEqual);
|
|
854
|
-
* // Returns [{ id: 1 }, { id: 3 }]
|
|
855
|
-
*/
|
|
282
|
+
// src/array/xorWith.ts
|
|
856
283
|
function xorWith(arr1, arr2, areElementsEqual) {
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
return differenceWith(
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
* @param {...T[][]} arrs - The arrays to zip together.
|
|
871
|
-
* @returns {T[][]} A new array of tuples containing the corresponding elements from the input arrays.
|
|
872
|
-
*
|
|
873
|
-
* @example
|
|
874
|
-
* const arr1 = [1, 2, 3];
|
|
875
|
-
* const arr2 = ['a', 'b', 'c'];
|
|
876
|
-
* const result = zip(arr1, arr2);
|
|
877
|
-
* // result will be [[1, 'a'], [2, 'b'], [3, 'c']]
|
|
878
|
-
*
|
|
879
|
-
* const arr3 = [true, false];
|
|
880
|
-
* const result2 = zip(arr1, arr2, arr3);
|
|
881
|
-
* // result2 will be [[1, 'a', true], [2, 'b', false], [3, 'c', undefined]]
|
|
882
|
-
*/
|
|
883
|
-
|
|
884
|
-
function zip() {
|
|
885
|
-
var result = [];
|
|
886
|
-
for (var _len = arguments.length, arrs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
887
|
-
arrs[_key] = arguments[_key];
|
|
888
|
-
}
|
|
889
|
-
var maxIndex = Math.max.apply(Math, _toConsumableArray(arrs.map(function (x) {
|
|
890
|
-
return x.length;
|
|
891
|
-
})));
|
|
892
|
-
for (var i = 0; i < maxIndex; i++) {
|
|
893
|
-
var element = [];
|
|
894
|
-
var _iterator = _createForOfIteratorHelper(arrs),
|
|
895
|
-
_step;
|
|
896
|
-
try {
|
|
897
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
898
|
-
var arr = _step.value;
|
|
899
|
-
element.push(arr[i]);
|
|
900
|
-
}
|
|
901
|
-
} catch (err) {
|
|
902
|
-
_iterator.e(err);
|
|
903
|
-
} finally {
|
|
904
|
-
_iterator.f();
|
|
284
|
+
const union2 = unionWith(arr1, arr2, areElementsEqual);
|
|
285
|
+
const intersection2 = intersectionWith(arr1, arr2, areElementsEqual);
|
|
286
|
+
return differenceWith(union2, intersection2, areElementsEqual);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/array/zip.ts
|
|
290
|
+
function zip(...arrs) {
|
|
291
|
+
const result = [];
|
|
292
|
+
const maxIndex = Math.max(...arrs.map((x) => x.length));
|
|
293
|
+
for (let i = 0; i < maxIndex; i++) {
|
|
294
|
+
const element = [];
|
|
295
|
+
for (const arr of arrs) {
|
|
296
|
+
element.push(arr[i]);
|
|
905
297
|
}
|
|
906
298
|
result.push(element);
|
|
907
299
|
}
|
|
908
300
|
return result;
|
|
909
301
|
}
|
|
910
302
|
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
* @param {W[]} [arr4] - The fourth array to zip (optional).
|
|
921
|
-
* @param {function} combine - The combiner function that takes corresponding elements from each array and returns a single value.
|
|
922
|
-
* @returns {R[]} A new array where each element is the result of applying the combiner function to the corresponding elements of the input arrays.
|
|
923
|
-
*
|
|
924
|
-
* @example
|
|
925
|
-
* // Example usage with two arrays:
|
|
926
|
-
* const arr1 = [1, 2, 3];
|
|
927
|
-
* const arr2 = [4, 5, 6];
|
|
928
|
-
* const result = zipWith(arr1, arr2, (a, b) => a + b);
|
|
929
|
-
* // result will be [5, 7, 9]
|
|
930
|
-
*
|
|
931
|
-
* @example
|
|
932
|
-
* // Example usage with three arrays:
|
|
933
|
-
* const arr1 = [1, 2];
|
|
934
|
-
* const arr2 = [3, 4];
|
|
935
|
-
* const arr3 = [5, 6];
|
|
936
|
-
* const result = zipWith(arr1, arr2, arr3, (a, b, c) => `${a}${b}${c}`);
|
|
937
|
-
* // result will be [`135`, `246`]
|
|
938
|
-
*/
|
|
939
|
-
|
|
940
|
-
function zipWith(arr1) {
|
|
941
|
-
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
942
|
-
rest[_key - 1] = arguments[_key];
|
|
943
|
-
}
|
|
944
|
-
var arrs = [arr1].concat(_toConsumableArray(rest.slice(0, -1)));
|
|
945
|
-
var combine = rest[rest.length - 1];
|
|
946
|
-
var result = [];
|
|
947
|
-
var maxIndex = Math.max.apply(Math, _toConsumableArray(arrs.map(function (arr) {
|
|
948
|
-
return arr.length;
|
|
949
|
-
})));
|
|
950
|
-
var _loop = function _loop(i) {
|
|
951
|
-
var elements = arrs.map(function (arr) {
|
|
952
|
-
return arr[i];
|
|
953
|
-
});
|
|
954
|
-
result.push(combine.apply(void 0, _toConsumableArray(elements)));
|
|
955
|
-
};
|
|
956
|
-
for (var i = 0; i < maxIndex; i++) {
|
|
957
|
-
_loop(i);
|
|
303
|
+
// src/array/zipWith.ts
|
|
304
|
+
function zipWith(arr1, ...rest) {
|
|
305
|
+
const arrs = [arr1, ...rest.slice(0, -1)];
|
|
306
|
+
const combine = rest[rest.length - 1];
|
|
307
|
+
const result = [];
|
|
308
|
+
const maxIndex = Math.max(...arrs.map((arr) => arr.length));
|
|
309
|
+
for (let i = 0; i < maxIndex; i++) {
|
|
310
|
+
const elements = arrs.map((arr) => arr[i]);
|
|
311
|
+
result.push(combine(...elements));
|
|
958
312
|
}
|
|
959
313
|
return result;
|
|
960
314
|
}
|
|
961
|
-
|
|
962
|
-
exports
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
315
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
316
|
+
0 && (module.exports = {
|
|
317
|
+
chunk,
|
|
318
|
+
difference,
|
|
319
|
+
differenceBy,
|
|
320
|
+
differenceWith,
|
|
321
|
+
drop,
|
|
322
|
+
dropRight,
|
|
323
|
+
dropRightWhile,
|
|
324
|
+
dropWhile,
|
|
325
|
+
groupBy,
|
|
326
|
+
intersection,
|
|
327
|
+
intersectionBy,
|
|
328
|
+
intersectionWith,
|
|
329
|
+
partition,
|
|
330
|
+
sample,
|
|
331
|
+
shuffle,
|
|
332
|
+
take,
|
|
333
|
+
takeRight,
|
|
334
|
+
takeRightWhile,
|
|
335
|
+
takeWhile,
|
|
336
|
+
union,
|
|
337
|
+
unionBy,
|
|
338
|
+
unionWith,
|
|
339
|
+
uniq,
|
|
340
|
+
uniqBy,
|
|
341
|
+
uniqWith,
|
|
342
|
+
xor,
|
|
343
|
+
xorBy,
|
|
344
|
+
xorWith,
|
|
345
|
+
zip,
|
|
346
|
+
zipWith
|
|
347
|
+
});
|
|
348
|
+
//# sourceMappingURL=index.js.map
|