@sapphire/iterator-utilities 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +765 -0
- package/dist/cjs/index.cjs +385 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +55 -0
- package/dist/cjs/lib/append.cjs +15 -0
- package/dist/cjs/lib/append.cjs.map +1 -0
- package/dist/cjs/lib/append.d.cts +21 -0
- package/dist/cjs/lib/at.cjs +18 -0
- package/dist/cjs/lib/at.cjs.map +1 -0
- package/dist/cjs/lib/at.d.cts +25 -0
- package/dist/cjs/lib/average.cjs +21 -0
- package/dist/cjs/lib/average.cjs.map +1 -0
- package/dist/cjs/lib/average.d.cts +25 -0
- package/dist/cjs/lib/chain.cjs +16 -0
- package/dist/cjs/lib/chain.cjs.map +1 -0
- package/dist/cjs/lib/chain.d.cts +20 -0
- package/dist/cjs/lib/chunk.cjs +27 -0
- package/dist/cjs/lib/chunk.cjs.map +1 -0
- package/dist/cjs/lib/chunk.d.cts +20 -0
- package/dist/cjs/lib/compact.cjs +14 -0
- package/dist/cjs/lib/compact.cjs.map +1 -0
- package/dist/cjs/lib/compact.d.cts +19 -0
- package/dist/cjs/lib/compress.cjs +24 -0
- package/dist/cjs/lib/compress.cjs.map +1 -0
- package/dist/cjs/lib/compress.d.cts +26 -0
- package/dist/cjs/lib/contains.cjs +18 -0
- package/dist/cjs/lib/contains.cjs.map +1 -0
- package/dist/cjs/lib/contains.d.cts +25 -0
- package/dist/cjs/lib/count.cjs +19 -0
- package/dist/cjs/lib/count.cjs.map +1 -0
- package/dist/cjs/lib/count.d.cts +24 -0
- package/dist/cjs/lib/cycle.cjs +23 -0
- package/dist/cjs/lib/cycle.cjs.map +1 -0
- package/dist/cjs/lib/cycle.d.cts +21 -0
- package/dist/cjs/lib/difference.cjs +18 -0
- package/dist/cjs/lib/difference.cjs.map +1 -0
- package/dist/cjs/lib/difference.d.cts +25 -0
- package/dist/cjs/lib/drop.cjs +28 -0
- package/dist/cjs/lib/drop.cjs.map +1 -0
- package/dist/cjs/lib/drop.d.cts +21 -0
- package/dist/cjs/lib/dropLast.cjs +23 -0
- package/dist/cjs/lib/dropLast.cjs.map +1 -0
- package/dist/cjs/lib/dropLast.d.cts +25 -0
- package/dist/cjs/lib/dropWhile.cjs +22 -0
- package/dist/cjs/lib/dropWhile.cjs.map +1 -0
- package/dist/cjs/lib/dropWhile.d.cts +24 -0
- package/dist/cjs/lib/empty.cjs +14 -0
- package/dist/cjs/lib/empty.cjs.map +1 -0
- package/dist/cjs/lib/empty.d.cts +17 -0
- package/dist/cjs/lib/enumerate.cjs +17 -0
- package/dist/cjs/lib/enumerate.cjs.map +1 -0
- package/dist/cjs/lib/enumerate.d.cts +24 -0
- package/dist/cjs/lib/every.cjs +21 -0
- package/dist/cjs/lib/every.cjs.map +1 -0
- package/dist/cjs/lib/every.d.cts +29 -0
- package/dist/cjs/lib/filter.cjs +21 -0
- package/dist/cjs/lib/filter.cjs.map +1 -0
- package/dist/cjs/lib/filter.d.cts +22 -0
- package/dist/cjs/lib/find.cjs +15 -0
- package/dist/cjs/lib/find.cjs.map +1 -0
- package/dist/cjs/lib/find.d.cts +26 -0
- package/dist/cjs/lib/findIndex.cjs +23 -0
- package/dist/cjs/lib/findIndex.cjs.map +1 -0
- package/dist/cjs/lib/findIndex.d.cts +25 -0
- package/dist/cjs/lib/first.cjs +14 -0
- package/dist/cjs/lib/first.cjs.map +1 -0
- package/dist/cjs/lib/first.d.cts +24 -0
- package/dist/cjs/lib/flat.cjs +16 -0
- package/dist/cjs/lib/flat.cjs.map +1 -0
- package/dist/cjs/lib/flat.d.cts +20 -0
- package/dist/cjs/lib/flatMap.cjs +19 -0
- package/dist/cjs/lib/flatMap.cjs.map +1 -0
- package/dist/cjs/lib/flatMap.d.cts +21 -0
- package/dist/cjs/lib/forEach.cjs +19 -0
- package/dist/cjs/lib/forEach.cjs.map +1 -0
- package/dist/cjs/lib/forEach.d.cts +24 -0
- package/dist/cjs/lib/from.cjs +25 -0
- package/dist/cjs/lib/from.cjs.map +1 -0
- package/dist/cjs/lib/from.d.cts +21 -0
- package/dist/cjs/lib/indexOf.cjs +22 -0
- package/dist/cjs/lib/indexOf.cjs.map +1 -0
- package/dist/cjs/lib/indexOf.d.cts +25 -0
- package/dist/cjs/lib/intersect.cjs +16 -0
- package/dist/cjs/lib/intersect.cjs.map +1 -0
- package/dist/cjs/lib/intersect.d.cts +26 -0
- package/dist/cjs/lib/isEmpty.cjs +14 -0
- package/dist/cjs/lib/isEmpty.cjs.map +1 -0
- package/dist/cjs/lib/isEmpty.d.cts +26 -0
- package/dist/cjs/lib/last.cjs +18 -0
- package/dist/cjs/lib/last.cjs.map +1 -0
- package/dist/cjs/lib/last.d.cts +24 -0
- package/dist/cjs/lib/map.cjs +19 -0
- package/dist/cjs/lib/map.cjs.map +1 -0
- package/dist/cjs/lib/map.d.cts +20 -0
- package/dist/cjs/lib/max.cjs +20 -0
- package/dist/cjs/lib/max.cjs.map +1 -0
- package/dist/cjs/lib/max.d.cts +25 -0
- package/dist/cjs/lib/min.cjs +20 -0
- package/dist/cjs/lib/min.cjs.map +1 -0
- package/dist/cjs/lib/min.d.cts +25 -0
- package/dist/cjs/lib/partition.cjs +26 -0
- package/dist/cjs/lib/partition.cjs.map +1 -0
- package/dist/cjs/lib/partition.d.cts +33 -0
- package/dist/cjs/lib/peekable.cjs +32 -0
- package/dist/cjs/lib/peekable.cjs.map +1 -0
- package/dist/cjs/lib/peekable.d.cts +35 -0
- package/dist/cjs/lib/prepend.cjs +17 -0
- package/dist/cjs/lib/prepend.cjs.map +1 -0
- package/dist/cjs/lib/prepend.d.cts +22 -0
- package/dist/cjs/lib/product.cjs +19 -0
- package/dist/cjs/lib/product.cjs.map +1 -0
- package/dist/cjs/lib/product.d.cts +24 -0
- package/dist/cjs/lib/range.cjs +37 -0
- package/dist/cjs/lib/range.cjs.map +1 -0
- package/dist/cjs/lib/range.d.cts +33 -0
- package/dist/cjs/lib/reduce.cjs +32 -0
- package/dist/cjs/lib/reduce.cjs.map +1 -0
- package/dist/cjs/lib/reduce.d.cts +33 -0
- package/dist/cjs/lib/repeat.cjs +20 -0
- package/dist/cjs/lib/repeat.cjs.map +1 -0
- package/dist/cjs/lib/repeat.d.cts +20 -0
- package/dist/cjs/lib/reverse.cjs +20 -0
- package/dist/cjs/lib/reverse.cjs.map +1 -0
- package/dist/cjs/lib/reverse.d.cts +26 -0
- package/dist/cjs/lib/shared/_assertFunction.cjs +17 -0
- package/dist/cjs/lib/shared/_assertFunction.cjs.map +1 -0
- package/dist/cjs/lib/shared/_assertFunction.d.cts +3 -0
- package/dist/cjs/lib/shared/_assertNotNegative.cjs +17 -0
- package/dist/cjs/lib/shared/_assertNotNegative.cjs.map +1 -0
- package/dist/cjs/lib/shared/_assertNotNegative.d.cts +3 -0
- package/dist/cjs/lib/shared/_assertPositive.cjs +17 -0
- package/dist/cjs/lib/shared/_assertPositive.cjs.map +1 -0
- package/dist/cjs/lib/shared/_assertPositive.d.cts +3 -0
- package/dist/cjs/lib/shared/_makeIterableIterator.cjs +19 -0
- package/dist/cjs/lib/shared/_makeIterableIterator.cjs.map +1 -0
- package/dist/cjs/lib/shared/_makeIterableIterator.d.cts +3 -0
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs +21 -0
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.cjs.map +1 -0
- package/dist/cjs/lib/shared/_toIntegerOrInfinityOrThrow.d.cts +3 -0
- package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs +21 -0
- package/dist/cjs/lib/shared/_toIntegerOrThrow.cjs.map +1 -0
- package/dist/cjs/lib/shared/_toIntegerOrThrow.d.cts +3 -0
- package/dist/cjs/lib/shared/_toNumberOrThrow.cjs +34 -0
- package/dist/cjs/lib/shared/_toNumberOrThrow.cjs.map +1 -0
- package/dist/cjs/lib/shared/_toNumberOrThrow.d.cts +8 -0
- package/dist/cjs/lib/slice.cjs +44 -0
- package/dist/cjs/lib/slice.cjs.map +1 -0
- package/dist/cjs/lib/slice.d.cts +62 -0
- package/dist/cjs/lib/some.cjs +22 -0
- package/dist/cjs/lib/some.cjs.map +1 -0
- package/dist/cjs/lib/some.d.cts +33 -0
- package/dist/cjs/lib/sorted.cjs +14 -0
- package/dist/cjs/lib/sorted.cjs.map +1 -0
- package/dist/cjs/lib/sorted.d.cts +25 -0
- package/dist/cjs/lib/starMap.cjs +19 -0
- package/dist/cjs/lib/starMap.cjs.map +1 -0
- package/dist/cjs/lib/starMap.d.cts +28 -0
- package/dist/cjs/lib/sum.cjs +19 -0
- package/dist/cjs/lib/sum.cjs.map +1 -0
- package/dist/cjs/lib/sum.d.cts +25 -0
- package/dist/cjs/lib/take.cjs +25 -0
- package/dist/cjs/lib/take.cjs.map +1 -0
- package/dist/cjs/lib/take.d.cts +21 -0
- package/dist/cjs/lib/takeLast.cjs +31 -0
- package/dist/cjs/lib/takeLast.cjs.map +1 -0
- package/dist/cjs/lib/takeLast.d.cts +25 -0
- package/dist/cjs/lib/tee.cjs +39 -0
- package/dist/cjs/lib/tee.cjs.map +1 -0
- package/dist/cjs/lib/tee.d.cts +25 -0
- package/dist/cjs/lib/toArray.cjs +14 -0
- package/dist/cjs/lib/toArray.cjs.map +1 -0
- package/dist/cjs/lib/toArray.d.cts +36 -0
- package/dist/cjs/lib/toIterableIterator.cjs +19 -0
- package/dist/cjs/lib/toIterableIterator.cjs.map +1 -0
- package/dist/cjs/lib/toIterableIterator.d.cts +32 -0
- package/dist/cjs/lib/union.cjs +22 -0
- package/dist/cjs/lib/union.cjs.map +1 -0
- package/dist/cjs/lib/union.d.cts +20 -0
- package/dist/cjs/lib/unique.cjs +14 -0
- package/dist/cjs/lib/unique.cjs.map +1 -0
- package/dist/cjs/lib/unique.d.cts +20 -0
- package/dist/cjs/lib/unzip.cjs +37 -0
- package/dist/cjs/lib/unzip.cjs.map +1 -0
- package/dist/cjs/lib/unzip.d.cts +32 -0
- package/dist/cjs/lib/zip.cjs +24 -0
- package/dist/cjs/lib/zip.cjs.map +1 -0
- package/dist/cjs/lib/zip.d.cts +30 -0
- package/dist/esm/chunk-G5GHKT7C.mjs +6 -0
- package/dist/esm/chunk-G5GHKT7C.mjs.map +1 -0
- package/dist/esm/index.d.mts +55 -0
- package/dist/esm/index.mjs +56 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/lib/append.d.mts +21 -0
- package/dist/esm/lib/append.mjs +11 -0
- package/dist/esm/lib/append.mjs.map +1 -0
- package/dist/esm/lib/at.d.mts +25 -0
- package/dist/esm/lib/at.mjs +15 -0
- package/dist/esm/lib/at.mjs.map +1 -0
- package/dist/esm/lib/average.d.mts +25 -0
- package/dist/esm/lib/average.mjs +18 -0
- package/dist/esm/lib/average.mjs.map +1 -0
- package/dist/esm/lib/chain.d.mts +20 -0
- package/dist/esm/lib/chain.mjs +13 -0
- package/dist/esm/lib/chain.mjs.map +1 -0
- package/dist/esm/lib/chunk.d.mts +20 -0
- package/dist/esm/lib/chunk.mjs +24 -0
- package/dist/esm/lib/chunk.mjs.map +1 -0
- package/dist/esm/lib/compact.d.mts +19 -0
- package/dist/esm/lib/compact.mjs +11 -0
- package/dist/esm/lib/compact.mjs.map +1 -0
- package/dist/esm/lib/compress.d.mts +26 -0
- package/dist/esm/lib/compress.mjs +21 -0
- package/dist/esm/lib/compress.mjs.map +1 -0
- package/dist/esm/lib/contains.d.mts +25 -0
- package/dist/esm/lib/contains.mjs +15 -0
- package/dist/esm/lib/contains.mjs.map +1 -0
- package/dist/esm/lib/count.d.mts +24 -0
- package/dist/esm/lib/count.mjs +16 -0
- package/dist/esm/lib/count.mjs.map +1 -0
- package/dist/esm/lib/cycle.d.mts +21 -0
- package/dist/esm/lib/cycle.mjs +20 -0
- package/dist/esm/lib/cycle.mjs.map +1 -0
- package/dist/esm/lib/difference.d.mts +25 -0
- package/dist/esm/lib/difference.mjs +13 -0
- package/dist/esm/lib/difference.mjs.map +1 -0
- package/dist/esm/lib/drop.d.mts +21 -0
- package/dist/esm/lib/drop.mjs +24 -0
- package/dist/esm/lib/drop.mjs.map +1 -0
- package/dist/esm/lib/dropLast.d.mts +25 -0
- package/dist/esm/lib/dropLast.mjs +19 -0
- package/dist/esm/lib/dropLast.mjs.map +1 -0
- package/dist/esm/lib/dropWhile.d.mts +24 -0
- package/dist/esm/lib/dropWhile.mjs +18 -0
- package/dist/esm/lib/dropWhile.mjs.map +1 -0
- package/dist/esm/lib/empty.d.mts +17 -0
- package/dist/esm/lib/empty.mjs +11 -0
- package/dist/esm/lib/empty.mjs.map +1 -0
- package/dist/esm/lib/enumerate.d.mts +24 -0
- package/dist/esm/lib/enumerate.mjs +14 -0
- package/dist/esm/lib/enumerate.mjs.map +1 -0
- package/dist/esm/lib/every.d.mts +29 -0
- package/dist/esm/lib/every.mjs +18 -0
- package/dist/esm/lib/every.mjs.map +1 -0
- package/dist/esm/lib/filter.d.mts +22 -0
- package/dist/esm/lib/filter.mjs +17 -0
- package/dist/esm/lib/filter.mjs.map +1 -0
- package/dist/esm/lib/find.d.mts +26 -0
- package/dist/esm/lib/find.mjs +12 -0
- package/dist/esm/lib/find.mjs.map +1 -0
- package/dist/esm/lib/findIndex.d.mts +25 -0
- package/dist/esm/lib/findIndex.mjs +20 -0
- package/dist/esm/lib/findIndex.mjs.map +1 -0
- package/dist/esm/lib/first.d.mts +24 -0
- package/dist/esm/lib/first.mjs +11 -0
- package/dist/esm/lib/first.mjs.map +1 -0
- package/dist/esm/lib/flat.d.mts +20 -0
- package/dist/esm/lib/flat.mjs +13 -0
- package/dist/esm/lib/flat.mjs.map +1 -0
- package/dist/esm/lib/flatMap.d.mts +21 -0
- package/dist/esm/lib/flatMap.mjs +16 -0
- package/dist/esm/lib/flatMap.mjs.map +1 -0
- package/dist/esm/lib/forEach.d.mts +24 -0
- package/dist/esm/lib/forEach.mjs +16 -0
- package/dist/esm/lib/forEach.mjs.map +1 -0
- package/dist/esm/lib/from.d.mts +21 -0
- package/dist/esm/lib/from.mjs +22 -0
- package/dist/esm/lib/from.mjs.map +1 -0
- package/dist/esm/lib/indexOf.d.mts +25 -0
- package/dist/esm/lib/indexOf.mjs +18 -0
- package/dist/esm/lib/indexOf.mjs.map +1 -0
- package/dist/esm/lib/intersect.d.mts +26 -0
- package/dist/esm/lib/intersect.mjs +13 -0
- package/dist/esm/lib/intersect.mjs.map +1 -0
- package/dist/esm/lib/isEmpty.d.mts +26 -0
- package/dist/esm/lib/isEmpty.mjs +11 -0
- package/dist/esm/lib/isEmpty.mjs.map +1 -0
- package/dist/esm/lib/last.d.mts +24 -0
- package/dist/esm/lib/last.mjs +15 -0
- package/dist/esm/lib/last.mjs.map +1 -0
- package/dist/esm/lib/map.d.mts +20 -0
- package/dist/esm/lib/map.mjs +16 -0
- package/dist/esm/lib/map.mjs.map +1 -0
- package/dist/esm/lib/max.d.mts +25 -0
- package/dist/esm/lib/max.mjs +17 -0
- package/dist/esm/lib/max.mjs.map +1 -0
- package/dist/esm/lib/min.d.mts +25 -0
- package/dist/esm/lib/min.mjs +17 -0
- package/dist/esm/lib/min.mjs.map +1 -0
- package/dist/esm/lib/partition.d.mts +33 -0
- package/dist/esm/lib/partition.mjs +23 -0
- package/dist/esm/lib/partition.mjs.map +1 -0
- package/dist/esm/lib/peekable.d.mts +35 -0
- package/dist/esm/lib/peekable.mjs +29 -0
- package/dist/esm/lib/peekable.mjs.map +1 -0
- package/dist/esm/lib/prepend.d.mts +22 -0
- package/dist/esm/lib/prepend.mjs +14 -0
- package/dist/esm/lib/prepend.mjs.map +1 -0
- package/dist/esm/lib/product.d.mts +24 -0
- package/dist/esm/lib/product.mjs +16 -0
- package/dist/esm/lib/product.mjs.map +1 -0
- package/dist/esm/lib/range.d.mts +33 -0
- package/dist/esm/lib/range.mjs +34 -0
- package/dist/esm/lib/range.mjs.map +1 -0
- package/dist/esm/lib/reduce.d.mts +33 -0
- package/dist/esm/lib/reduce.mjs +29 -0
- package/dist/esm/lib/reduce.mjs.map +1 -0
- package/dist/esm/lib/repeat.d.mts +20 -0
- package/dist/esm/lib/repeat.mjs +17 -0
- package/dist/esm/lib/repeat.mjs.map +1 -0
- package/dist/esm/lib/reverse.d.mts +26 -0
- package/dist/esm/lib/reverse.mjs +17 -0
- package/dist/esm/lib/reverse.mjs.map +1 -0
- package/dist/esm/lib/shared/_assertFunction.d.mts +3 -0
- package/dist/esm/lib/shared/_assertFunction.mjs +14 -0
- package/dist/esm/lib/shared/_assertFunction.mjs.map +1 -0
- package/dist/esm/lib/shared/_assertNotNegative.d.mts +3 -0
- package/dist/esm/lib/shared/_assertNotNegative.mjs +14 -0
- package/dist/esm/lib/shared/_assertNotNegative.mjs.map +1 -0
- package/dist/esm/lib/shared/_assertPositive.d.mts +3 -0
- package/dist/esm/lib/shared/_assertPositive.mjs +14 -0
- package/dist/esm/lib/shared/_assertPositive.mjs.map +1 -0
- package/dist/esm/lib/shared/_makeIterableIterator.d.mts +3 -0
- package/dist/esm/lib/shared/_makeIterableIterator.mjs +16 -0
- package/dist/esm/lib/shared/_makeIterableIterator.mjs.map +1 -0
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.d.mts +3 -0
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs +18 -0
- package/dist/esm/lib/shared/_toIntegerOrInfinityOrThrow.mjs.map +1 -0
- package/dist/esm/lib/shared/_toIntegerOrThrow.d.mts +3 -0
- package/dist/esm/lib/shared/_toIntegerOrThrow.mjs +18 -0
- package/dist/esm/lib/shared/_toIntegerOrThrow.mjs.map +1 -0
- package/dist/esm/lib/shared/_toNumberOrThrow.d.mts +8 -0
- package/dist/esm/lib/shared/_toNumberOrThrow.mjs +31 -0
- package/dist/esm/lib/shared/_toNumberOrThrow.mjs.map +1 -0
- package/dist/esm/lib/slice.d.mts +62 -0
- package/dist/esm/lib/slice.mjs +41 -0
- package/dist/esm/lib/slice.mjs.map +1 -0
- package/dist/esm/lib/some.d.mts +33 -0
- package/dist/esm/lib/some.mjs +19 -0
- package/dist/esm/lib/some.mjs.map +1 -0
- package/dist/esm/lib/sorted.d.mts +25 -0
- package/dist/esm/lib/sorted.mjs +11 -0
- package/dist/esm/lib/sorted.mjs.map +1 -0
- package/dist/esm/lib/starMap.d.mts +28 -0
- package/dist/esm/lib/starMap.mjs +16 -0
- package/dist/esm/lib/starMap.mjs.map +1 -0
- package/dist/esm/lib/sum.d.mts +25 -0
- package/dist/esm/lib/sum.mjs +16 -0
- package/dist/esm/lib/sum.mjs.map +1 -0
- package/dist/esm/lib/take.d.mts +21 -0
- package/dist/esm/lib/take.mjs +22 -0
- package/dist/esm/lib/take.mjs.map +1 -0
- package/dist/esm/lib/takeLast.d.mts +25 -0
- package/dist/esm/lib/takeLast.mjs +28 -0
- package/dist/esm/lib/takeLast.mjs.map +1 -0
- package/dist/esm/lib/tee.d.mts +25 -0
- package/dist/esm/lib/tee.mjs +36 -0
- package/dist/esm/lib/tee.mjs.map +1 -0
- package/dist/esm/lib/toArray.d.mts +36 -0
- package/dist/esm/lib/toArray.mjs +11 -0
- package/dist/esm/lib/toArray.mjs.map +1 -0
- package/dist/esm/lib/toIterableIterator.d.mts +32 -0
- package/dist/esm/lib/toIterableIterator.mjs +16 -0
- package/dist/esm/lib/toIterableIterator.mjs.map +1 -0
- package/dist/esm/lib/union.d.mts +20 -0
- package/dist/esm/lib/union.mjs +19 -0
- package/dist/esm/lib/union.mjs.map +1 -0
- package/dist/esm/lib/unique.d.mts +20 -0
- package/dist/esm/lib/unique.mjs +11 -0
- package/dist/esm/lib/unique.mjs.map +1 -0
- package/dist/esm/lib/unzip.d.mts +32 -0
- package/dist/esm/lib/unzip.mjs +34 -0
- package/dist/esm/lib/unzip.mjs.map +1 -0
- package/dist/esm/lib/zip.d.mts +30 -0
- package/dist/esm/lib/zip.mjs +21 -0
- package/dist/esm/lib/zip.mjs.map +1 -0
- package/dist/iife/index.global.js +834 -0
- package/dist/iife/index.global.js.map +1 -0
- package/package.json +692 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { assertFunction } from './shared/_assertFunction.mjs';
|
|
3
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
4
|
+
|
|
5
|
+
function reduce(iterable, callbackFn, initialValue) {
|
|
6
|
+
callbackFn = assertFunction(callbackFn);
|
|
7
|
+
let index;
|
|
8
|
+
let accumulator;
|
|
9
|
+
const resolvedIterable = toIterableIterator(iterable);
|
|
10
|
+
if (arguments.length < 3) {
|
|
11
|
+
const firstValue = resolvedIterable.next();
|
|
12
|
+
if (firstValue.done)
|
|
13
|
+
throw new TypeError("Reduce of empty iterator with no initial value");
|
|
14
|
+
index = 1;
|
|
15
|
+
accumulator = firstValue.value;
|
|
16
|
+
} else {
|
|
17
|
+
index = 0;
|
|
18
|
+
accumulator = initialValue;
|
|
19
|
+
}
|
|
20
|
+
for (const value of resolvedIterable) {
|
|
21
|
+
accumulator = callbackFn(accumulator, value, index++);
|
|
22
|
+
}
|
|
23
|
+
return accumulator;
|
|
24
|
+
}
|
|
25
|
+
__name(reduce, "reduce");
|
|
26
|
+
|
|
27
|
+
export { reduce };
|
|
28
|
+
//# sourceMappingURL=out.js.map
|
|
29
|
+
//# sourceMappingURL=reduce.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/reduce.ts"],"names":[],"mappings":";;;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AA8B5B,SAAS,OACf,UACA,YACA,cACa;AACb,eAAa,eAAe,UAAU;AAEtC,MAAI;AACJ,MAAI;AACJ,QAAM,mBAAmB,mBAAmB,QAAQ;AACpD,MAAI,UAAU,SAAS,GAAG;AACzB,UAAM,aAAa,iBAAiB,KAAK;AACzC,QAAI,WAAW;AAAM,YAAM,IAAI,UAAU,gDAAgD;AAEzF,YAAQ;AACR,kBAAc,WAAW;AAAA,EAC1B,OAAO;AACN,YAAQ;AACR,kBAAc;AAAA,EACf;AAEA,aAAW,SAAS,kBAAkB;AACrC,kBAAc,WAAW,aAAa,OAAO,OAAO;AAAA,EACrD;AAEA,SAAO;AACR;AA1BgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable and reduces it to the reducer function's result.\n *\n * @param iterable An iterator to reduce.\n * @param callbackFn A function to execute for each element produced by the iterator. Its return value becomes the value\n * of the `accumulator` parameter on the next invocation of `callbackFn`. For the last invocation, the return value\n * becomes the return value of `reduce()`.\n * @param initialValue A value to which `accumulator` is initialized the first time the callback is called. If\n * `initialValue` is specified, `callbackFn` starts executing with the first element as `currentValue`. If\n * `initialValue` is not specified, `accumulator` is initialized to the first element, and `callbackFn` starts executing\n * with the second element as `currentValue`. In this case, if the iterator is empty (so that there's no first value to\n * return as `accumulator`), an error is thrown.\n * @returns\n *\n * @example\n * ```typescript\n * import { reduce } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(reduce(iterable, (accumulator, currentValue) => accumulator + currentValue));\n * // Output: 15\n * ```\n *\n * @remarks\n *\n * If `initialValue` is not provided, the first element of the iterator is used as the initial value of `accumulator`,\n * consuming the first element.\n */\nexport function reduce<const ElementType, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (accumulator: MappedType, currentValue: ElementType, currentIndex: number) => MappedType,\n\tinitialValue?: MappedType\n): MappedType {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index: number;\n\tlet accumulator: MappedType;\n\tconst resolvedIterable = toIterableIterator(iterable);\n\tif (arguments.length < 3) {\n\t\tconst firstValue = resolvedIterable.next();\n\t\tif (firstValue.done) throw new TypeError('Reduce of empty iterator with no initial value');\n\n\t\tindex = 1;\n\t\taccumulator = firstValue.value! as MappedType;\n\t} else {\n\t\tindex = 0;\n\t\taccumulator = initialValue!;\n\t}\n\n\tfor (const value of resolvedIterable) {\n\t\taccumulator = callbackFn(accumulator, value, index++);\n\t}\n\n\treturn accumulator;\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an iterable that repeats the input iterable `count` times.
|
|
3
|
+
*
|
|
4
|
+
* @param value The value to be repeated.
|
|
5
|
+
* @param count The number of times to repeat the value.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { repeat } from '@sapphire/iterator-utilities';
|
|
10
|
+
*
|
|
11
|
+
* const iterator = repeat('Hello, world!', 3);
|
|
12
|
+
* console.log([...iterator]);
|
|
13
|
+
* // Output: ['Hello, world!', 'Hello, world!', 'Hello, world!']
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @remarks This function does not clone `value`, it will be repeated as a reference.
|
|
17
|
+
*/
|
|
18
|
+
declare function repeat<const ElementType>(value: ElementType, count: number): IterableIterator<ElementType>;
|
|
19
|
+
|
|
20
|
+
export { repeat };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { assertNotNegative } from './shared/_assertNotNegative.mjs';
|
|
3
|
+
import { makeIterableIterator } from './shared/_makeIterableIterator.mjs';
|
|
4
|
+
import { toNumberOrThrow } from './shared/_toNumberOrThrow.mjs';
|
|
5
|
+
|
|
6
|
+
function repeat(value, count) {
|
|
7
|
+
count = assertNotNegative(toNumberOrThrow(count), count);
|
|
8
|
+
let i = 0;
|
|
9
|
+
return makeIterableIterator(
|
|
10
|
+
() => i >= count ? { done: true, value: void 0 } : (i++, { done: false, value })
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
__name(repeat, "repeat");
|
|
14
|
+
|
|
15
|
+
export { repeat };
|
|
16
|
+
//# sourceMappingURL=out.js.map
|
|
17
|
+
//# sourceMappingURL=repeat.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/repeat.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,uBAAuB;AAmBzB,SAAS,OAA0B,OAAoB,OAA8C;AAC3G,UAAQ,kBAAkB,gBAAgB,KAAK,GAAG,KAAK;AAEvD,MAAI,IAAI;AACR,SAAO;AAAA,IAAkC,MACxC,KAAK,QACF,EAAE,MAAM,MAAM,OAAO,OAAU,KAC9B,KAAK,EAAE,MAAM,OAAO,MAAM;AAAA,EAC/B;AACD;AATgB","sourcesContent":["import { assertNotNegative } from './shared/_assertNotNegative';\nimport { makeIterableIterator } from './shared/_makeIterableIterator';\nimport { toNumberOrThrow } from './shared/_toNumberOrThrow';\n\n/**\n * Creates an iterable that repeats the input iterable `count` times.\n *\n * @param value The value to be repeated.\n * @param count The number of times to repeat the value.\n *\n * @example\n * ```typescript\n * import { repeat } from '@sapphire/iterator-utilities';\n *\n * const iterator = repeat('Hello, world!', 3);\n * console.log([...iterator]);\n * // Output: ['Hello, world!', 'Hello, world!', 'Hello, world!']\n * ```\n *\n * @remarks This function does not clone `value`, it will be repeated as a reference.\n */\nexport function repeat<const ElementType>(value: ElementType, count: number): IterableIterator<ElementType> {\n\tcount = assertNotNegative(toNumberOrThrow(count), count);\n\n\tlet i = 0;\n\treturn makeIterableIterator<ElementType>(() =>\n\t\ti >= count //\n\t\t\t? { done: true, value: undefined }\n\t\t\t: (i++, { done: false, value })\n\t);\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable and returns a new iterable with the elements in reverse order.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable The iterator to reverse.
|
|
7
|
+
* @returns An iterator whose element correspond to the elements of the provided iterator in reverse order.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { reverse } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* console.log([...reverse([1, 2, 3, 4, 5])]);
|
|
14
|
+
* // Output: [5, 4, 3, 2, 1]
|
|
15
|
+
*
|
|
16
|
+
* console.log([...reverse('hello')]);
|
|
17
|
+
* // Output: ['o', 'l', 'l', 'e', 'h']
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
*
|
|
22
|
+
* This function collects all elements of the provided iterator into an array before yielding them in reverse order.
|
|
23
|
+
*/
|
|
24
|
+
declare function reverse<const ElementType>(iterable: IterableResolvable<ElementType>): IterableIterator<ElementType>;
|
|
25
|
+
|
|
26
|
+
export { reverse };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
3
|
+
|
|
4
|
+
function* reverse(iterable) {
|
|
5
|
+
const items = [];
|
|
6
|
+
for (const item of toIterableIterator(iterable)) {
|
|
7
|
+
items.push(item);
|
|
8
|
+
}
|
|
9
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
10
|
+
yield items[i];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
__name(reverse, "reverse");
|
|
14
|
+
|
|
15
|
+
export { reverse };
|
|
16
|
+
//# sourceMappingURL=out.js.map
|
|
17
|
+
//# sourceMappingURL=reverse.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/reverse.ts"],"names":[],"mappings":";;;;;AACA,SAAS,0BAA0B;AAuB5B,UAAU,QAA2B,UAA0E;AACrH,QAAM,QAAuB,CAAC;AAC9B,aAAW,QAAQ,mBAAmB,QAAQ,GAAG;AAChD,UAAM,KAAK,IAAI;AAAA,EAChB;AAEA,WAAS,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;AAC3C,UAAM,MAAM,CAAC;AAAA,EACd;AACD;AATiB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable and returns a new iterable with the elements in reverse order.\n *\n * @param iterable The iterator to reverse.\n * @returns An iterator whose element correspond to the elements of the provided iterator in reverse order.\n *\n * @example\n * ```typescript\n * import { reverse } from '@sapphire/iterator-utilities';\n *\n * console.log([...reverse([1, 2, 3, 4, 5])]);\n * // Output: [5, 4, 3, 2, 1]\n *\n * console.log([...reverse('hello')]);\n * // Output: ['o', 'l', 'l', 'e', 'h']\n * ```\n *\n * @remarks\n *\n * This function collects all elements of the provided iterator into an array before yielding them in reverse order.\n */\nexport function* reverse<const ElementType>(iterable: IterableResolvable<ElementType>): IterableIterator<ElementType> {\n\tconst items: ElementType[] = [];\n\tfor (const item of toIterableIterator(iterable)) {\n\t\titems.push(item);\n\t}\n\n\tfor (let i = items.length - 1; i >= 0; i--) {\n\t\tyield items[i];\n\t}\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __name } from '../../chunk-G5GHKT7C.mjs';
|
|
2
|
+
|
|
3
|
+
// src/lib/shared/_assertFunction.ts
|
|
4
|
+
function assertFunction(value) {
|
|
5
|
+
if (typeof value !== "function") {
|
|
6
|
+
throw new TypeError(`${value} must be a function`);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
__name(assertFunction, "assertFunction");
|
|
11
|
+
|
|
12
|
+
export { assertFunction };
|
|
13
|
+
//# sourceMappingURL=out.js.map
|
|
14
|
+
//# sourceMappingURL=_assertFunction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/_assertFunction.ts"],"names":[],"mappings":";;;;;AAAO,SAAS,eAAmD,OAAe;AACjF,MAAI,OAAO,UAAU,YAAY;AAChC,UAAM,IAAI,UAAU,GAAG,KAAK,qBAAqB;AAAA,EAClD;AAEA,SAAO;AACR;AANgB","sourcesContent":["export function assertFunction<Fn extends (...args: any[]) => any>(value: Fn): Fn {\n\tif (typeof value !== 'function') {\n\t\tthrow new TypeError(`${value} must be a function`);\n\t}\n\n\treturn value;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __name } from '../../chunk-G5GHKT7C.mjs';
|
|
2
|
+
|
|
3
|
+
// src/lib/shared/_assertNotNegative.ts
|
|
4
|
+
function assertNotNegative(value, original) {
|
|
5
|
+
if (value < 0) {
|
|
6
|
+
throw new RangeError(`${original} must be a non-negative number`);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
__name(assertNotNegative, "assertNotNegative");
|
|
11
|
+
|
|
12
|
+
export { assertNotNegative };
|
|
13
|
+
//# sourceMappingURL=out.js.map
|
|
14
|
+
//# sourceMappingURL=_assertNotNegative.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/_assertNotNegative.ts"],"names":[],"mappings":";;;;;AAAO,SAAS,kBAAkB,OAAe,UAA2B;AAC3E,MAAI,QAAQ,GAAG;AACd,UAAM,IAAI,WAAW,GAAG,QAAQ,gCAAgC;AAAA,EACjE;AAEA,SAAO;AACR;AANgB","sourcesContent":["export function assertNotNegative(value: number, original: unknown): number {\n\tif (value < 0) {\n\t\tthrow new RangeError(`${original} must be a non-negative number`);\n\t}\n\n\treturn value;\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { __name } from '../../chunk-G5GHKT7C.mjs';
|
|
2
|
+
|
|
3
|
+
// src/lib/shared/_assertPositive.ts
|
|
4
|
+
function assertPositive(value, original) {
|
|
5
|
+
if (value <= 0) {
|
|
6
|
+
throw new RangeError(`${original} must be a positive number`);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
__name(assertPositive, "assertPositive");
|
|
11
|
+
|
|
12
|
+
export { assertPositive };
|
|
13
|
+
//# sourceMappingURL=out.js.map
|
|
14
|
+
//# sourceMappingURL=_assertPositive.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/_assertPositive.ts"],"names":[],"mappings":";;;;;AAAO,SAAS,eAAe,OAAe,UAA2B;AACxE,MAAI,SAAS,GAAG;AACf,UAAM,IAAI,WAAW,GAAG,QAAQ,4BAA4B;AAAA,EAC7D;AAEA,SAAO;AACR;AANgB","sourcesContent":["export function assertPositive(value: number, original: unknown): number {\n\tif (value <= 0) {\n\t\tthrow new RangeError(`${original} must be a positive number`);\n\t}\n\n\treturn value;\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __name } from '../../chunk-G5GHKT7C.mjs';
|
|
2
|
+
|
|
3
|
+
// src/lib/shared/_makeIterableIterator.ts
|
|
4
|
+
function makeIterableIterator(next) {
|
|
5
|
+
return {
|
|
6
|
+
next,
|
|
7
|
+
[Symbol.iterator]() {
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
__name(makeIterableIterator, "makeIterableIterator");
|
|
13
|
+
|
|
14
|
+
export { makeIterableIterator };
|
|
15
|
+
//# sourceMappingURL=out.js.map
|
|
16
|
+
//# sourceMappingURL=_makeIterableIterator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/_makeIterableIterator.ts"],"names":[],"mappings":";;;;;AAAO,SAAS,qBAAwC,MAAoE;AAC3H,SAAO;AAAA,IACN;AAAA,IACA,CAAC,OAAO,QAAQ,IAAI;AACnB,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAPgB","sourcesContent":["export function makeIterableIterator<const ElementType>(next: Iterator<ElementType>['next']): IterableIterator<ElementType> {\n\treturn {\n\t\tnext,\n\t\t[Symbol.iterator]() {\n\t\t\treturn this;\n\t\t}\n\t};\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { __name } from '../../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { toNumberOrThrow } from './_toNumberOrThrow.mjs';
|
|
3
|
+
|
|
4
|
+
function toIntegerOrInfinityOrThrow(value) {
|
|
5
|
+
const number = toNumberOrThrow(value);
|
|
6
|
+
if (Number.isNaN(number) || number === 0)
|
|
7
|
+
return 0;
|
|
8
|
+
if (number === Number.POSITIVE_INFINITY)
|
|
9
|
+
return Number.POSITIVE_INFINITY;
|
|
10
|
+
if (number === Number.NEGATIVE_INFINITY)
|
|
11
|
+
return Number.NEGATIVE_INFINITY;
|
|
12
|
+
return Math.trunc(number);
|
|
13
|
+
}
|
|
14
|
+
__name(toIntegerOrInfinityOrThrow, "toIntegerOrInfinityOrThrow");
|
|
15
|
+
|
|
16
|
+
export { toIntegerOrInfinityOrThrow };
|
|
17
|
+
//# sourceMappingURL=out.js.map
|
|
18
|
+
//# sourceMappingURL=_toIntegerOrInfinityOrThrow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/_toIntegerOrInfinityOrThrow.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAEzB,SAAS,2BAA2B,OAAuB;AACjE,QAAM,SAAS,gBAAgB,KAAK;AACpC,MAAI,OAAO,MAAM,MAAM,KAAK,WAAW;AAAG,WAAO;AACjD,MAAI,WAAW,OAAO;AAAmB,WAAO,OAAO;AACvD,MAAI,WAAW,OAAO;AAAmB,WAAO,OAAO;AAEvD,SAAO,KAAK,MAAM,MAAM;AACzB;AAPgB","sourcesContent":["import { toNumberOrThrow } from './_toNumberOrThrow';\n\nexport function toIntegerOrInfinityOrThrow(value: number): number {\n\tconst number = toNumberOrThrow(value);\n\tif (Number.isNaN(number) || number === 0) return 0;\n\tif (number === Number.POSITIVE_INFINITY) return Number.POSITIVE_INFINITY;\n\tif (number === Number.NEGATIVE_INFINITY) return Number.NEGATIVE_INFINITY;\n\n\treturn Math.trunc(number);\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { __name } from '../../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { toNumberOrThrow } from './_toNumberOrThrow.mjs';
|
|
3
|
+
|
|
4
|
+
function toIntegerOrThrow(value) {
|
|
5
|
+
const number = toNumberOrThrow(value);
|
|
6
|
+
if (Number.isNaN(number) || number === 0)
|
|
7
|
+
return 0;
|
|
8
|
+
if (number === Number.POSITIVE_INFINITY)
|
|
9
|
+
throw new RangeError("+Infinity cannot be represented as an integer");
|
|
10
|
+
if (number === Number.NEGATIVE_INFINITY)
|
|
11
|
+
throw new RangeError("-Infinity cannot be represented as an integer");
|
|
12
|
+
return Math.trunc(number);
|
|
13
|
+
}
|
|
14
|
+
__name(toIntegerOrThrow, "toIntegerOrThrow");
|
|
15
|
+
|
|
16
|
+
export { toIntegerOrThrow };
|
|
17
|
+
//# sourceMappingURL=out.js.map
|
|
18
|
+
//# sourceMappingURL=_toIntegerOrThrow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/_toIntegerOrThrow.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAEzB,SAAS,iBAAiB,OAAuB;AACvD,QAAM,SAAS,gBAAgB,KAAK;AACpC,MAAI,OAAO,MAAM,MAAM,KAAK,WAAW;AAAG,WAAO;AACjD,MAAI,WAAW,OAAO;AAAmB,UAAM,IAAI,WAAW,+CAA+C;AAC7G,MAAI,WAAW,OAAO;AAAmB,UAAM,IAAI,WAAW,+CAA+C;AAE7G,SAAO,KAAK,MAAM,MAAM;AACzB;AAPgB","sourcesContent":["import { toNumberOrThrow } from './_toNumberOrThrow';\n\nexport function toIntegerOrThrow(value: number): number {\n\tconst number = toNumberOrThrow(value);\n\tif (Number.isNaN(number) || number === 0) return 0;\n\tif (number === Number.POSITIVE_INFINITY) throw new RangeError('+Infinity cannot be represented as an integer');\n\tif (number === Number.NEGATIVE_INFINITY) throw new RangeError('-Infinity cannot be represented as an integer');\n\n\treturn Math.trunc(number);\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare function toNumberOrThrow(value: NumberResolvable): number;
|
|
2
|
+
type NumberResolvable = number | boolean | null | {
|
|
3
|
+
valueOf(): number | boolean | null;
|
|
4
|
+
} | {
|
|
5
|
+
[Symbol.toPrimitive](): number | boolean | null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { type NumberResolvable, toNumberOrThrow };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { __name } from '../../chunk-G5GHKT7C.mjs';
|
|
2
|
+
|
|
3
|
+
// src/lib/shared/_toNumberOrThrow.ts
|
|
4
|
+
function toNumberOrThrow(value) {
|
|
5
|
+
switch (typeof value) {
|
|
6
|
+
case "bigint":
|
|
7
|
+
throw new TypeError("Cannot convert a BigInt value to a number");
|
|
8
|
+
case "symbol":
|
|
9
|
+
throw new TypeError("Cannot convert a Symbol value to a number");
|
|
10
|
+
case "boolean":
|
|
11
|
+
return value ? 1 : 0;
|
|
12
|
+
case "number":
|
|
13
|
+
return assertNumber(value, value);
|
|
14
|
+
case "undefined":
|
|
15
|
+
throw new TypeError("Cannot convert an undefined value to a number");
|
|
16
|
+
default:
|
|
17
|
+
return assertNumber(Number(value), value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
__name(toNumberOrThrow, "toNumberOrThrow");
|
|
21
|
+
function assertNumber(value, original) {
|
|
22
|
+
if (Number.isNaN(value)) {
|
|
23
|
+
throw new RangeError(`${original} must be a non-NaN number`);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
__name(assertNumber, "assertNumber");
|
|
28
|
+
|
|
29
|
+
export { toNumberOrThrow };
|
|
30
|
+
//# sourceMappingURL=out.js.map
|
|
31
|
+
//# sourceMappingURL=_toNumberOrThrow.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/shared/_toNumberOrThrow.ts"],"names":[],"mappings":";;;;;AAAO,SAAS,gBAAgB,OAAiC;AAChE,UAAQ,OAAO,OAAO;AAAA,IACrB,KAAK;AACJ,YAAM,IAAI,UAAU,2CAA2C;AAAA,IAChE,KAAK;AACJ,YAAM,IAAI,UAAU,2CAA2C;AAAA,IAChE,KAAK;AACJ,aAAO,QAAQ,IAAI;AAAA,IACpB,KAAK;AACJ,aAAO,aAAa,OAAO,KAAK;AAAA,IACjC,KAAK;AACJ,YAAM,IAAI,UAAU,+CAA+C;AAAA,IACpE;AACC,aAAO,aAAa,OAAO,KAAK,GAAG,KAAK;AAAA,EAC1C;AACD;AAfgB;AAmBhB,SAAS,aAAa,OAAe,UAA2B;AAC/D,MAAI,OAAO,MAAM,KAAK,GAAG;AACxB,UAAM,IAAI,WAAW,GAAG,QAAQ,2BAA2B;AAAA,EAC5D;AAEA,SAAO;AACR;AANS","sourcesContent":["export function toNumberOrThrow(value: NumberResolvable): number {\n\tswitch (typeof value) {\n\t\tcase 'bigint':\n\t\t\tthrow new TypeError('Cannot convert a BigInt value to a number');\n\t\tcase 'symbol':\n\t\t\tthrow new TypeError('Cannot convert a Symbol value to a number');\n\t\tcase 'boolean':\n\t\t\treturn value ? 1 : 0;\n\t\tcase 'number':\n\t\t\treturn assertNumber(value, value);\n\t\tcase 'undefined':\n\t\t\tthrow new TypeError('Cannot convert an undefined value to a number');\n\t\tdefault:\n\t\t\treturn assertNumber(Number(value), value);\n\t}\n}\n\nexport type NumberResolvable = number | boolean | null | { valueOf(): number | boolean | null } | { [Symbol.toPrimitive](): number | boolean | null };\n\nfunction assertNumber(value: number, original: unknown): number {\n\tif (Number.isNaN(value)) {\n\t\tthrow new RangeError(`${original} must be a non-NaN number`);\n\t}\n\n\treturn value;\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Produces an iterable with the elements from the `start` index to the `end` index (exclusive).
|
|
5
|
+
*
|
|
6
|
+
* @param iterable The iterator to slice.
|
|
7
|
+
* @param start The index at which to begin extraction.
|
|
8
|
+
* @param end The index at which to end extraction.
|
|
9
|
+
* @returns An iterator that contains the elements of the provided iterator from `start` to `end`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { slice } from '@sapphire/iterator-utilities';
|
|
14
|
+
*
|
|
15
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
16
|
+
* console.log([...slice(, 1, 3)]);
|
|
17
|
+
* // Output: [2, 3]
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
23
|
+
* console.log([...slice(iterable, -2)]);
|
|
24
|
+
* // Output: [4, 5]
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
30
|
+
* console.log([...slice(iterable, 2)]);
|
|
31
|
+
* // Output: [3, 4, 5]
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
37
|
+
* console.log([...slice(iterable, 2, -1)]);
|
|
38
|
+
* // Output: [3, 4]
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
44
|
+
* console.log([...slice(iterable, -2, -1)]);
|
|
45
|
+
* // Output: [4]
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
51
|
+
* console.log([...slice(iterable, 2, 1)]);
|
|
52
|
+
* // Output: []
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
*
|
|
57
|
+
* This function consumes the input iterator based on the `start` and `end` values, therefore, you should not use the
|
|
58
|
+
* original iterator after calling this function.
|
|
59
|
+
*/
|
|
60
|
+
declare function slice<const ElementType>(iterable: IterableResolvable<ElementType>, start?: number, end?: number): IterableIterator<ElementType>;
|
|
61
|
+
|
|
62
|
+
export { slice };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { drop } from './drop.mjs';
|
|
3
|
+
import { dropLast } from './dropLast.mjs';
|
|
4
|
+
import { empty } from './empty.mjs';
|
|
5
|
+
import { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow.mjs';
|
|
6
|
+
import { take } from './take.mjs';
|
|
7
|
+
import { takeLast } from './takeLast.mjs';
|
|
8
|
+
|
|
9
|
+
function slice(iterable, start, end) {
|
|
10
|
+
start = toIntegerOrInfinityOrThrow(start ?? 0);
|
|
11
|
+
if (start === Number.NEGATIVE_INFINITY) {
|
|
12
|
+
start = 0;
|
|
13
|
+
}
|
|
14
|
+
if (end === void 0) {
|
|
15
|
+
return start >= 0 ? drop(iterable, start) : takeLast(iterable, -start);
|
|
16
|
+
}
|
|
17
|
+
end = toIntegerOrInfinityOrThrow(end);
|
|
18
|
+
if (end < 0) {
|
|
19
|
+
if (end === Number.NEGATIVE_INFINITY) {
|
|
20
|
+
return empty();
|
|
21
|
+
}
|
|
22
|
+
if (start === 0) {
|
|
23
|
+
return dropLast(iterable, -end);
|
|
24
|
+
}
|
|
25
|
+
if (start >= 0) {
|
|
26
|
+
return dropLast(drop(iterable, start), -end);
|
|
27
|
+
}
|
|
28
|
+
if (start >= end) {
|
|
29
|
+
return empty();
|
|
30
|
+
}
|
|
31
|
+
return take(takeLast(iterable, -start), end - start);
|
|
32
|
+
}
|
|
33
|
+
if (start >= end)
|
|
34
|
+
return empty();
|
|
35
|
+
return end === Number.POSITIVE_INFINITY ? drop(iterable, start) : take(drop(iterable, start), end - start);
|
|
36
|
+
}
|
|
37
|
+
__name(slice, "slice");
|
|
38
|
+
|
|
39
|
+
export { slice };
|
|
40
|
+
//# sourceMappingURL=out.js.map
|
|
41
|
+
//# sourceMappingURL=slice.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/slice.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAEtB,SAAS,kCAAkC;AAC3C,SAAS,YAAY;AACrB,SAAS,gBAAgB;AA2DlB,SAAS,MAAyB,UAA2C,OAAgB,KAA6C;AAEhJ,UAAQ,2BAA2B,SAAS,CAAC;AAC7C,MAAI,UAAU,OAAO,mBAAmB;AACvC,YAAQ;AAAA,EACT;AAIA,MAAI,QAAQ,QAAW;AACtB,WAAO,SAAS,IACb,KAAK,UAAU,KAAK,IACpB,SAAS,UAAU,CAAC,KAAK;AAAA,EAC7B;AAEA,QAAM,2BAA2B,GAAG;AAEpC,MAAI,MAAM,GAAG;AAGZ,QAAI,QAAQ,OAAO,mBAAmB;AACrC,aAAO,MAAM;AAAA,IACd;AAGA,QAAI,UAAU,GAAG;AAChB,aAAO,SAAS,UAAU,CAAC,GAAG;AAAA,IAC/B;AAIA,QAAI,SAAS,GAAG;AACf,aAAO,SAAS,KAAK,UAAU,KAAK,GAAG,CAAC,GAAG;AAAA,IAC5C;AAIA,QAAI,SAAS,KAAK;AACjB,aAAO,MAAM;AAAA,IACd;AAIA,WAAO,KAAK,SAAS,UAAU,CAAC,KAAK,GAAG,MAAM,KAAK;AAAA,EACpD;AAGA,MAAI,SAAS;AAAK,WAAO,MAAM;AAG/B,SAAO,QAAQ,OAAO,oBACnB,KAAK,UAAU,KAAK,IACpB,KAAK,KAAK,UAAU,KAAK,GAAG,MAAM,KAAK;AAC3C;AArDgB","sourcesContent":["import { drop } from './drop';\nimport { dropLast } from './dropLast';\nimport { empty } from './empty';\nimport type { IterableResolvable } from './from';\nimport { toIntegerOrInfinityOrThrow } from './shared/_toIntegerOrInfinityOrThrow';\nimport { take } from './take';\nimport { takeLast } from './takeLast';\n\n/**\n * Produces an iterable with the elements from the `start` index to the `end` index (exclusive).\n *\n * @param iterable The iterator to slice.\n * @param start The index at which to begin extraction.\n * @param end The index at which to end extraction.\n * @returns An iterator that contains the elements of the provided iterator from `start` to `end`.\n *\n * @example\n * ```typescript\n * import { slice } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...slice(, 1, 3)]);\n * // Output: [2, 3]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...slice(iterable, -2)]);\n * // Output: [4, 5]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...slice(iterable, 2)]);\n * // Output: [3, 4, 5]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...slice(iterable, 2, -1)]);\n * // Output: [3, 4]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...slice(iterable, -2, -1)]);\n * // Output: [4]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...slice(iterable, 2, 1)]);\n * // Output: []\n * ```\n *\n * @remarks\n *\n * This function consumes the input iterator based on the `start` and `end` values, therefore, you should not use the\n * original iterator after calling this function.\n */\nexport function slice<const ElementType>(iterable: IterableResolvable<ElementType>, start?: number, end?: number): IterableIterator<ElementType> {\n\t// https://tc39.es/ecma262/#sec-array.prototype.slice\n\tstart = toIntegerOrInfinityOrThrow(start ?? 0);\n\tif (start === Number.NEGATIVE_INFINITY) {\n\t\tstart = 0;\n\t}\n\n\t// 1. If end is not provided, `slice` behaves like `drop` or `takeLast`,\n\t// depending on the sign of `start`:\n\tif (end === undefined) {\n\t\treturn start >= 0 //\n\t\t\t? drop(iterable, start)\n\t\t\t: takeLast(iterable, -start);\n\t}\n\n\tend = toIntegerOrInfinityOrThrow(end);\n\t// 2. If end is negative:\n\tif (end < 0) {\n\t\t// 2.1. If `end` is `-Infinity`, end would be `0`, which will always\n\t\t// result on an empty iterator:\n\t\tif (end === Number.NEGATIVE_INFINITY) {\n\t\t\treturn empty();\n\t\t}\n\n\t\t// 2.2. If start is positive, drop the last n elements:\n\t\tif (start === 0) {\n\t\t\treturn dropLast(iterable, -end);\n\t\t}\n\n\t\t// 2.3. If the start is positive, drop the first n elements and take the\n\t\t// last m elements:\n\t\tif (start >= 0) {\n\t\t\treturn dropLast(drop(iterable, start), -end);\n\t\t}\n\n\t\t// 2.4. If the start is the same or greater than the end, return an\n\t\t// empty iterator:\n\t\tif (start >= end) {\n\t\t\treturn empty();\n\t\t}\n\n\t\t// 2.5. `start` and `end` are negative, take the elements between the\n\t\t// start and end:\n\t\treturn take(takeLast(iterable, -start), end - start);\n\t}\n\n\t// 3.0. If `start` is greater than or equal to `end`, return an empty iterator:\n\tif (start >= end) return empty();\n\n\t// 4.0. Otherwise, take the elements between `start` and `end`:\n\treturn end === Number.POSITIVE_INFINITY //\n\t\t? drop(iterable, start)\n\t\t: take(drop(iterable, start), end - start);\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Advances the iterable until it finds a matching element, returning `true` if it's found and `false` otherwise.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to search for a value in.
|
|
7
|
+
* @param callbackFn A function to execute for each element produced by the iterator. It should return a truthy value to
|
|
8
|
+
* indicate the element passes the test, and a falsy value otherwise.
|
|
9
|
+
* @returns `true` if the callback function returns a truthy value for at least one element. Otherwise, `false`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { some } from '@sapphire/iterator-utilities';
|
|
14
|
+
*
|
|
15
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
16
|
+
* console.log(some(iterable, (value) => value % 2 === 0));
|
|
17
|
+
* // Output: true
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
23
|
+
* console.log(some(iterable, (value) => value % 6 === 0));
|
|
24
|
+
* // Output: false
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
*
|
|
29
|
+
* This function consumes the iterator until the value is found or the iterator is exhausted.
|
|
30
|
+
*/
|
|
31
|
+
declare function some<const ElementType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => boolean): boolean;
|
|
32
|
+
|
|
33
|
+
export { some };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { assertFunction } from './shared/_assertFunction.mjs';
|
|
3
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
4
|
+
|
|
5
|
+
function some(iterable, callbackFn) {
|
|
6
|
+
callbackFn = assertFunction(callbackFn);
|
|
7
|
+
let index = 0;
|
|
8
|
+
for (const value of toIterableIterator(iterable)) {
|
|
9
|
+
if (callbackFn(value, index++)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
__name(some, "some");
|
|
16
|
+
|
|
17
|
+
export { some };
|
|
18
|
+
//# sourceMappingURL=out.js.map
|
|
19
|
+
//# sourceMappingURL=some.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/some.ts"],"names":[],"mappings":";;;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AA8B5B,SAAS,KACf,UACA,YACU;AACV,eAAa,eAAe,UAAU;AAEtC,MAAI,QAAQ;AACZ,aAAW,SAAS,mBAAmB,QAAQ,GAAG;AACjD,QAAI,WAAW,OAAO,OAAO,GAAG;AAC/B,aAAO;AAAA,IACR;AAAA,EACD;AAEA,SAAO;AACR;AAdgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Advances the iterable until it finds a matching element, returning `true` if it's found and `false` otherwise.\n *\n * @param iterable An iterator to search for a value in.\n * @param callbackFn A function to execute for each element produced by the iterator. It should return a truthy value to\n * indicate the element passes the test, and a falsy value otherwise.\n * @returns `true` if the callback function returns a truthy value for at least one element. Otherwise, `false`.\n *\n * @example\n * ```typescript\n * import { some } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(some(iterable, (value) => value % 2 === 0));\n * // Output: true\n * ```\n *\n * @example\n * ```typescript\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(some(iterable, (value) => value % 6 === 0));\n * // Output: false\n * ```\n *\n * @remarks\n *\n * This function consumes the iterator until the value is found or the iterator is exhausted.\n */\nexport function some<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => boolean\n): boolean {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tif (callbackFn(value, index++)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable and returns a new iterable with the elements sorted.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to sort.
|
|
7
|
+
* @param compareFn A function that defines the sort order. If omitted, the values are sorted in ascending order.
|
|
8
|
+
* @returns An iterator that yields the values of the provided iterator in sorted order.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { sorted } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const iterable = [5, 3, 1, 4, 2];
|
|
15
|
+
* console.log([...sorted(iterable)]);
|
|
16
|
+
* // Output: [1, 2, 3, 4, 5]
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
*
|
|
21
|
+
* This function consumes the entire input iterator.
|
|
22
|
+
*/
|
|
23
|
+
declare function sorted<const ElementType>(iterable: IterableResolvable<ElementType>, compareFn?: (a: ElementType, b: ElementType) => number): IterableIterator<ElementType>;
|
|
24
|
+
|
|
25
|
+
export { sorted };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import { toArray } from './toArray.mjs';
|
|
3
|
+
|
|
4
|
+
function sorted(iterable, compareFn) {
|
|
5
|
+
return toArray(iterable).sort(compareFn).values();
|
|
6
|
+
}
|
|
7
|
+
__name(sorted, "sorted");
|
|
8
|
+
|
|
9
|
+
export { sorted };
|
|
10
|
+
//# sourceMappingURL=out.js.map
|
|
11
|
+
//# sourceMappingURL=sorted.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/sorted.ts"],"names":[],"mappings":";;;;;AACA,SAAS,eAAe;AAsBjB,SAAS,OACf,UACA,WACgC;AAChC,SAAO,QAAQ,QAAQ,EAAE,KAAK,SAAS,EAAE,OAAO;AACjD;AALgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toArray } from './toArray';\n\n/**\n * Consumes the iterable and returns a new iterable with the elements sorted.\n *\n * @param iterable An iterator to sort.\n * @param compareFn A function that defines the sort order. If omitted, the values are sorted in ascending order.\n * @returns An iterator that yields the values of the provided iterator in sorted order.\n *\n * @example\n * ```typescript\n * import { sorted } from '@sapphire/iterator-utilities';\n *\n * const iterable = [5, 3, 1, 4, 2];\n * console.log([...sorted(iterable)]);\n * // Output: [1, 2, 3, 4, 5]\n * ```\n *\n * @remarks\n *\n * This function consumes the entire input iterator.\n */\nexport function sorted<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tcompareFn?: (a: ElementType, b: ElementType) => number\n): IterableIterator<ElementType> {\n\treturn toArray(iterable).sort(compareFn).values();\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterable with the results of calling a provided function on each element of the input iterables as the function's parameters.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable The iterable to map over.
|
|
7
|
+
* @param callbackFn The callback function to apply to each element.
|
|
8
|
+
* @returns An iterable iterator that yields the mapped elements.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { starMap } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const iterable = [[1, 2], [3, 4], [5, 6]];
|
|
15
|
+
* console.log([...starMap(iterable, (a, b) => a + b)]);
|
|
16
|
+
* // Output: [3, 7, 11]
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
*
|
|
21
|
+
* While very similar to {@link map}, `starMap` takes an iterable of iterables (which can be an array of tuples) and
|
|
22
|
+
* calls the function with each inner iterable's values as the function's parameters. {@link map} calls the function
|
|
23
|
+
* with the value and the index by comparison.
|
|
24
|
+
*/
|
|
25
|
+
declare function starMap<const ElementType extends IterableResolvable<any>, const MappedType>(iterable: IterableResolvable<ElementType>, callbackFn: (...args: StarMapParameters<ElementType>) => MappedType): IterableIterator<MappedType>;
|
|
26
|
+
type StarMapParameters<ElementType> = ElementType extends readonly [...infer ElementTypeEntry] ? ElementTypeEntry : ElementType extends IterableResolvable<infer ElementType> ? ElementType[] : never;
|
|
27
|
+
|
|
28
|
+
export { type StarMapParameters, starMap };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { __name } from '../chunk-G5GHKT7C.mjs';
|
|
2
|
+
import './from.mjs';
|
|
3
|
+
import { assertFunction } from './shared/_assertFunction.mjs';
|
|
4
|
+
import { toIterableIterator } from './toIterableIterator.mjs';
|
|
5
|
+
|
|
6
|
+
function* starMap(iterable, callbackFn) {
|
|
7
|
+
callbackFn = assertFunction(callbackFn);
|
|
8
|
+
for (const value of toIterableIterator(iterable)) {
|
|
9
|
+
yield callbackFn(...toIterableIterator(value));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
__name(starMap, "starMap");
|
|
13
|
+
|
|
14
|
+
export { starMap };
|
|
15
|
+
//# sourceMappingURL=out.js.map
|
|
16
|
+
//# sourceMappingURL=starMap.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/starMap.ts"],"names":[],"mappings":";;;;;AAAA,OAAwC;AACxC,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AAwB5B,UAAU,QAChB,UACA,YAC+B;AAC/B,eAAa,eAAe,UAAU;AAEtC,aAAW,SAAS,mBAAmB,QAAQ,GAAG;AACjD,UAAM,WAAW,GAAI,mBAAmB,KAAK,CAAS;AAAA,EACvD;AACD;AATiB","sourcesContent":["import { type IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterable with the results of calling a provided function on each element of the input iterables as the function's parameters.\n *\n * @param iterable The iterable to map over.\n * @param callbackFn The callback function to apply to each element.\n * @returns An iterable iterator that yields the mapped elements.\n *\n * @example\n * ```typescript\n * import { starMap } from '@sapphire/iterator-utilities';\n *\n * const iterable = [[1, 2], [3, 4], [5, 6]];\n * console.log([...starMap(iterable, (a, b) => a + b)]);\n * // Output: [3, 7, 11]\n * ```\n *\n * @remarks\n *\n * While very similar to {@link map}, `starMap` takes an iterable of iterables (which can be an array of tuples) and\n * calls the function with each inner iterable's values as the function's parameters. {@link map} calls the function\n * with the value and the index by comparison.\n */\nexport function* starMap<const ElementType extends IterableResolvable<any>, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (...args: StarMapParameters<ElementType>) => MappedType\n): IterableIterator<MappedType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tyield callbackFn(...(toIterableIterator(value) as any));\n\t}\n}\n\nexport type StarMapParameters<ElementType> = ElementType extends readonly [...infer ElementTypeEntry]\n\t? ElementTypeEntry\n\t: ElementType extends IterableResolvable<infer ElementType>\n\t\t? ElementType[]\n\t\t: never;\n"]}
|