@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,24 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable until it's exhausted, returning the last element.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to return the last value of.
|
|
7
|
+
* @returns The value at the last position in the source iterator, or `undefined` if the iterator is empty.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { last } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
14
|
+
* console.log(last(iterable));
|
|
15
|
+
* // Output: 5
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
*
|
|
20
|
+
* This function consumes the entire iterator to find the last value.
|
|
21
|
+
*/
|
|
22
|
+
declare function last<const ElementType>(iterable: IterableResolvable<ElementType>): ElementType | undefined;
|
|
23
|
+
|
|
24
|
+
export { last };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _assertFunction_cjs = require('./shared/_assertFunction.cjs');
|
|
4
|
+
var toIterableIterator_cjs = require('./toIterableIterator.cjs');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
function* map(iterable, callbackFn) {
|
|
9
|
+
callbackFn = _assertFunction_cjs.assertFunction(callbackFn);
|
|
10
|
+
let index = 0;
|
|
11
|
+
for (const element of toIterableIterator_cjs.toIterableIterator(iterable)) {
|
|
12
|
+
yield callbackFn(element, index++);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
__name(map, "map");
|
|
16
|
+
|
|
17
|
+
exports.map = map;
|
|
18
|
+
//# sourceMappingURL=out.js.map
|
|
19
|
+
//# sourceMappingURL=map.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/map.ts"],"names":[],"mappings":";;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AAiB5B,UAAU,IAChB,UACA,YAC+B;AAC/B,eAAa,eAAe,UAAU;AAEtC,MAAI,QAAQ;AACZ,aAAW,WAAW,mBAAmB,QAAQ,GAAG;AACnD,UAAM,WAAW,SAAS,OAAO;AAAA,EAClC;AACD;AAViB","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.\n *\n * @param iterable An iterator to map over.\n * @param callbackFn A function to execute for each element produced by the iterator. Its return value is yielded by the iterator helper.\n *\n * @example\n * ```typescript\n * import { map } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log([...map(iterable, (value) => value * 2)]);\n * // Output: [2, 4, 6, 8, 10]\n * ```\n */\nexport function* map<const ElementType, const MappedType>(\n\titerable: IterableResolvable<ElementType>,\n\tcallbackFn: (element: ElementType, index: number) => MappedType\n): IterableIterator<MappedType> {\n\tcallbackFn = assertFunction(callbackFn);\n\n\tlet index = 0;\n\tfor (const element of toIterableIterator(iterable)) {\n\t\tyield callbackFn(element, index++);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterable with the results of calling a provided function on each element.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to map over.
|
|
7
|
+
* @param callbackFn A function to execute for each element produced by the iterator. Its return value is yielded by the iterator helper.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { map } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
14
|
+
* console.log([...map(iterable, (value) => value * 2)]);
|
|
15
|
+
* // Output: [2, 4, 6, 8, 10]
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare function map<const ElementType, const MappedType>(iterable: IterableResolvable<ElementType>, callbackFn: (element: ElementType, index: number) => MappedType): IterableIterator<MappedType>;
|
|
19
|
+
|
|
20
|
+
export { map };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var map_cjs = require('./map.cjs');
|
|
4
|
+
var _toNumberOrThrow_cjs = require('./shared/_toNumberOrThrow.cjs');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
function max(iterable) {
|
|
9
|
+
let max2 = null;
|
|
10
|
+
for (const value of map_cjs.map(iterable, _toNumberOrThrow_cjs.toNumberOrThrow)) {
|
|
11
|
+
if (max2 === null || value > max2)
|
|
12
|
+
max2 = value;
|
|
13
|
+
}
|
|
14
|
+
return max2;
|
|
15
|
+
}
|
|
16
|
+
__name(max, "max");
|
|
17
|
+
|
|
18
|
+
exports.max = max;
|
|
19
|
+
//# sourceMappingURL=out.js.map
|
|
20
|
+
//# sourceMappingURL=max.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/max.ts"],"names":["max"],"mappings":";;;;AACA,SAAS,WAAW;AACpB,SAAS,uBAA8C;AAqBhD,SAAS,IAAI,UAA+D;AAClF,MAAIA,OAAqB;AACzB,aAAW,SAAS,IAAI,UAAU,eAAe,GAAG;AACnD,QAAIA,SAAQ,QAAQ,QAAQA;AAAK,MAAAA,OAAM;AAAA,EACxC;AAEA,SAAOA;AACR;AAPgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { map } from './map';\nimport { toNumberOrThrow, type NumberResolvable } from './shared/_toNumberOrThrow';\n\n/**\n * Consumes the iterable and returns the highest number element. If the iterable is empty, or contains only non-number values, it returns `null`.\n *\n * @param iterable An iterator of number values to determine the maximum value of.\n * @returns The maximum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.\n *\n * @example\n * ```typescript\n * import { max } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(max(iterable));\n * // Output: 5\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function max(iterable: IterableResolvable<NumberResolvable>): number | null {\n\tlet max: number | null = null;\n\tfor (const value of map(iterable, toNumberOrThrow)) {\n\t\tif (max === null || value > max) max = value;\n\t}\n\n\treturn max;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
import { NumberResolvable } from './shared/_toNumberOrThrow.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Consumes the iterable and returns the highest number element. If the iterable is empty, or contains only non-number values, it returns `null`.
|
|
6
|
+
*
|
|
7
|
+
* @param iterable An iterator of number values to determine the maximum value of.
|
|
8
|
+
* @returns The maximum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { max } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
15
|
+
* console.log(max(iterable));
|
|
16
|
+
* // Output: 5
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
*
|
|
21
|
+
* This function consumes the entire iterator.
|
|
22
|
+
*/
|
|
23
|
+
declare function max(iterable: IterableResolvable<NumberResolvable>): number | null;
|
|
24
|
+
|
|
25
|
+
export { max };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var map_cjs = require('./map.cjs');
|
|
4
|
+
var _toNumberOrThrow_cjs = require('./shared/_toNumberOrThrow.cjs');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
function min(iterable) {
|
|
9
|
+
let min2 = null;
|
|
10
|
+
for (const value of map_cjs.map(iterable, _toNumberOrThrow_cjs.toNumberOrThrow)) {
|
|
11
|
+
if (min2 === null || value < min2)
|
|
12
|
+
min2 = value;
|
|
13
|
+
}
|
|
14
|
+
return min2;
|
|
15
|
+
}
|
|
16
|
+
__name(min, "min");
|
|
17
|
+
|
|
18
|
+
exports.min = min;
|
|
19
|
+
//# sourceMappingURL=out.js.map
|
|
20
|
+
//# sourceMappingURL=min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/min.ts"],"names":["min"],"mappings":";;;;AACA,SAAS,WAAW;AACpB,SAAS,uBAA8C;AAqBhD,SAAS,IAAI,UAA+D;AAClF,MAAIA,OAAqB;AACzB,aAAW,SAAS,IAAI,UAAU,eAAe,GAAG;AACnD,QAAIA,SAAQ,QAAQ,QAAQA;AAAK,MAAAA,OAAM;AAAA,EACxC;AAEA,SAAOA;AACR;AAPgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { map } from './map';\nimport { toNumberOrThrow, type NumberResolvable } from './shared/_toNumberOrThrow';\n\n/**\n * Consumes the iterable and returns the lowest number element. If the iterable is empty, or contains only non-number values, it returns `null`.\n *\n * @param iterable An iterator of number values to determine the minimum value of.\n * @returns The minimum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.\n *\n * @example\n * ```typescript\n * import { min } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(min(iterable));\n * // Output: 1\n * ```\n *\n * @remarks\n *\n * This function consumes the entire iterator.\n */\nexport function min(iterable: IterableResolvable<NumberResolvable>): number | null {\n\tlet min: number | null = null;\n\tfor (const value of map(iterable, toNumberOrThrow)) {\n\t\tif (min === null || value < min) min = value;\n\t}\n\n\treturn min;\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
import { NumberResolvable } from './shared/_toNumberOrThrow.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Consumes the iterable and returns the lowest number element. If the iterable is empty, or contains only non-number values, it returns `null`.
|
|
6
|
+
*
|
|
7
|
+
* @param iterable An iterator of number values to determine the minimum value of.
|
|
8
|
+
* @returns The minimum value in the input iterator, or `null` if the iterator is empty or contains only non-number values.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { min } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
15
|
+
* console.log(min(iterable));
|
|
16
|
+
* // Output: 1
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
*
|
|
21
|
+
* This function consumes the entire iterator.
|
|
22
|
+
*/
|
|
23
|
+
declare function min(iterable: IterableResolvable<NumberResolvable>): number | null;
|
|
24
|
+
|
|
25
|
+
export { min };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _assertFunction_cjs = require('./shared/_assertFunction.cjs');
|
|
4
|
+
var toIterableIterator_cjs = require('./toIterableIterator.cjs');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
function partition(iterable, predicate) {
|
|
9
|
+
predicate = _assertFunction_cjs.assertFunction(predicate);
|
|
10
|
+
const bufferLeft = [];
|
|
11
|
+
const bufferRight = [];
|
|
12
|
+
let index = 0;
|
|
13
|
+
for (const value of toIterableIterator_cjs.toIterableIterator(iterable)) {
|
|
14
|
+
if (predicate(value, index++)) {
|
|
15
|
+
bufferLeft.push(value);
|
|
16
|
+
} else {
|
|
17
|
+
bufferRight.push(value);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return [bufferLeft, bufferRight];
|
|
21
|
+
}
|
|
22
|
+
__name(partition, "partition");
|
|
23
|
+
|
|
24
|
+
exports.partition = partition;
|
|
25
|
+
//# sourceMappingURL=out.js.map
|
|
26
|
+
//# sourceMappingURL=partition.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/partition.ts"],"names":[],"mappings":";;;;AACA,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AAsC5B,SAAS,UACf,UACA,WACiC;AACjC,cAAY,eAAe,SAAS;AAEpC,QAAM,aAA4B,CAAC;AACnC,QAAM,cAA6B,CAAC;AAEpC,MAAI,QAAQ;AACZ,aAAW,SAAS,mBAAmB,QAAQ,GAAG;AACjD,QAAI,UAAU,OAAO,OAAO,GAAG;AAC9B,iBAAW,KAAK,KAAK;AAAA,IACtB,OAAO;AACN,kBAAY,KAAK,KAAK;AAAA,IACvB;AAAA,EACD;AAEA,SAAO,CAAC,YAAY,WAAW;AAChC;AAnBgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { assertFunction } from './shared/_assertFunction';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Consumes the iterable and creates two arrays, one with the elements that pass the test and another with the elements that don't.\n *\n * @param iterable An iterator to partition.\n * @param predicate A function that determines which partition an element belongs to.\n * @returns An array containing two iterators. The first iterator contains elements that satisfy the predicate, and the\n * second iterator contains elements that do not.\n *\n * @example\n * ```typescript\n * import { partition } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * const [even, odd] = partition(iterable, (value) => value % 2 === 0);\n *\n * console.log(even);\n * // Output: [2, 4]\n *\n * console.log(odd);\n * // Output: [1, 3, 5]\n * ```\n *\n * @remarks\n *\n * This function collects all elements of the provided iterator into two arrays based on the predicate before returning\n * them, which may not be desirable for large iterators.\n */\nexport function partition<const ElementType, const FilteredType extends ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tpredicate: (value: ElementType, index: number) => value is FilteredType\n): [FilteredType[], Exclude<ElementType, FilteredType>[]];\nexport function partition<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tpredicate: (value: ElementType, index: number) => boolean\n): [ElementType[], ElementType[]];\n\nexport function partition<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\tpredicate: (value: ElementType, index: number) => boolean\n): [ElementType[], ElementType[]] {\n\tpredicate = assertFunction(predicate);\n\n\tconst bufferLeft: ElementType[] = [];\n\tconst bufferRight: ElementType[] = [];\n\n\tlet index = 0;\n\tfor (const value of toIterableIterator(iterable)) {\n\t\tif (predicate(value, index++)) {\n\t\t\tbufferLeft.push(value);\n\t\t} else {\n\t\t\tbufferRight.push(value);\n\t\t}\n\t}\n\n\treturn [bufferLeft, bufferRight];\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable and creates two arrays, one with the elements that pass the test and another with the elements that don't.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to partition.
|
|
7
|
+
* @param predicate A function that determines which partition an element belongs to.
|
|
8
|
+
* @returns An array containing two iterators. The first iterator contains elements that satisfy the predicate, and the
|
|
9
|
+
* second iterator contains elements that do not.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { partition } from '@sapphire/iterator-utilities';
|
|
14
|
+
*
|
|
15
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
16
|
+
* const [even, odd] = partition(iterable, (value) => value % 2 === 0);
|
|
17
|
+
*
|
|
18
|
+
* console.log(even);
|
|
19
|
+
* // Output: [2, 4]
|
|
20
|
+
*
|
|
21
|
+
* console.log(odd);
|
|
22
|
+
* // Output: [1, 3, 5]
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
*
|
|
27
|
+
* This function collects all elements of the provided iterator into two arrays based on the predicate before returning
|
|
28
|
+
* them, which may not be desirable for large iterators.
|
|
29
|
+
*/
|
|
30
|
+
declare function partition<const ElementType, const FilteredType extends ElementType>(iterable: IterableResolvable<ElementType>, predicate: (value: ElementType, index: number) => value is FilteredType): [FilteredType[], Exclude<ElementType, FilteredType>[]];
|
|
31
|
+
declare function partition<const ElementType>(iterable: IterableResolvable<ElementType>, predicate: (value: ElementType, index: number) => boolean): [ElementType[], ElementType[]];
|
|
32
|
+
|
|
33
|
+
export { partition };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var from_cjs = require('./from.cjs');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function peekable(iterable) {
|
|
8
|
+
const resolvedIterable = from_cjs.from(iterable);
|
|
9
|
+
let peeked;
|
|
10
|
+
return {
|
|
11
|
+
next() {
|
|
12
|
+
if (peeked) {
|
|
13
|
+
const value = peeked;
|
|
14
|
+
peeked = void 0;
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
return resolvedIterable.next();
|
|
18
|
+
},
|
|
19
|
+
peek() {
|
|
20
|
+
peeked = peeked ?? resolvedIterable.next();
|
|
21
|
+
return peeked;
|
|
22
|
+
},
|
|
23
|
+
[Symbol.iterator]() {
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
__name(peekable, "peekable");
|
|
29
|
+
|
|
30
|
+
exports.peekable = peekable;
|
|
31
|
+
//# sourceMappingURL=out.js.map
|
|
32
|
+
//# sourceMappingURL=peekable.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/peekable.ts"],"names":[],"mappings":";;;;AAAA,SAAS,YAAqC;AA6BvC,SAAS,SAA4B,UAAkE;AAC7G,QAAM,mBAAmB,KAAK,QAAQ;AACtC,MAAI;AACJ,SAAO;AAAA,IACN,OAAO;AACN,UAAI,QAAQ;AACX,cAAM,QAAQ;AACd,iBAAS;AACT,eAAO;AAAA,MACR;AAEA,aAAO,iBAAiB,KAAK;AAAA,IAC9B;AAAA,IACA,OAAO;AACN,eAAS,UAAU,iBAAiB,KAAK;AACzC,aAAO;AAAA,IACR;AAAA,IACA,CAAC,OAAO,QAAQ,IAAI;AACnB,aAAO;AAAA,IACR;AAAA,EACD;AACD;AArBgB","sourcesContent":["import { from, type IterableResolvable } from './from';\n\n/**\n * Creates an iterator that allows you to peek at the next element without advancing the iterator.\n *\n * @template ElementType The type of elements in the iterable.\n * @param iterable The iterable to create a peekable iterator from.\n * @returns A new peekable iterator.\n *\n * @example\n * ```typescript\n * import { peekable } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * const peekableIterator = peekable(iterable);\n *\n * console.log(peekableIterator.next());\n * // Output: { value: 1, done: false }\n *\n * console.log(peekableIterator.peek());\n * // Output: { value: 2, done: false }\n *\n * console.log(peekableIterator.next());\n * // Output: { value: 2, done: false }\n *\n * console.log(peekableIterator.next());\n * // Output: { value: 3, done: false }\n * ```\n */\nexport function peekable<const ElementType>(iterable: IterableResolvable<ElementType>): Peekable<ElementType> {\n\tconst resolvedIterable = from(iterable);\n\tlet peeked: IteratorResult<ElementType> | undefined;\n\treturn {\n\t\tnext() {\n\t\t\tif (peeked) {\n\t\t\t\tconst value = peeked;\n\t\t\t\tpeeked = undefined;\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\treturn resolvedIterable.next();\n\t\t},\n\t\tpeek() {\n\t\t\tpeeked = peeked ?? resolvedIterable.next();\n\t\t\treturn peeked;\n\t\t},\n\t\t[Symbol.iterator]() {\n\t\t\treturn this as IterableIterator<ElementType>;\n\t\t}\n\t};\n}\n\nexport interface Peekable<T> extends IterableIterator<T> {\n\tpeek(): IteratorResult<T> | undefined;\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterator that allows you to peek at the next element without advancing the iterator.
|
|
5
|
+
*
|
|
6
|
+
* @template ElementType The type of elements in the iterable.
|
|
7
|
+
* @param iterable The iterable to create a peekable iterator from.
|
|
8
|
+
* @returns A new peekable iterator.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { peekable } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
15
|
+
* const peekableIterator = peekable(iterable);
|
|
16
|
+
*
|
|
17
|
+
* console.log(peekableIterator.next());
|
|
18
|
+
* // Output: { value: 1, done: false }
|
|
19
|
+
*
|
|
20
|
+
* console.log(peekableIterator.peek());
|
|
21
|
+
* // Output: { value: 2, done: false }
|
|
22
|
+
*
|
|
23
|
+
* console.log(peekableIterator.next());
|
|
24
|
+
* // Output: { value: 2, done: false }
|
|
25
|
+
*
|
|
26
|
+
* console.log(peekableIterator.next());
|
|
27
|
+
* // Output: { value: 3, done: false }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function peekable<const ElementType>(iterable: IterableResolvable<ElementType>): Peekable<ElementType>;
|
|
31
|
+
interface Peekable<T> extends IterableIterator<T> {
|
|
32
|
+
peek(): IteratorResult<T> | undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { type Peekable, peekable };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var toIterableIterator_cjs = require('./toIterableIterator.cjs');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function* prepend(iterable, ...iterables) {
|
|
8
|
+
for (const iterable2 of iterables) {
|
|
9
|
+
yield* toIterableIterator_cjs.toIterableIterator(iterable2);
|
|
10
|
+
}
|
|
11
|
+
yield* toIterableIterator_cjs.toIterableIterator(iterable);
|
|
12
|
+
}
|
|
13
|
+
__name(prepend, "prepend");
|
|
14
|
+
|
|
15
|
+
exports.prepend = prepend;
|
|
16
|
+
//# sourceMappingURL=out.js.map
|
|
17
|
+
//# sourceMappingURL=prepend.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/prepend.ts"],"names":["iterable"],"mappings":";;;;AACA,SAAS,0BAA0B;AAmB5B,UAAU,QAChB,aACG,WAC6B;AAChC,aAAWA,aAAY,WAAW;AACjC,WAAO,mBAAmBA,SAAQ;AAAA,EACnC;AAEA,SAAO,mBAAmB,QAAQ;AACnC;AATiB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { toIterableIterator } from './toIterableIterator';\n\n/**\n * Creates an iterator with the provided iterables prepended to the first iterable.\n *\n * @param iterable The iterator to prepend values to.\n * @param iterables The iterables to prepend to the iterator.\n * @returns An iterator that yields the values of the provided iterator followed by the values of the provided iterables.\n *\n * @example\n * ```typescript\n * import { prepend } from '@sapphire/iterator-utilities';\n *\n * console.log([...prepend([3, 4, 5], [1, 2])]);\n * // Output: [1, 2, 3, 4, 5]\n * ```\n *\n * @seealso {@link append} to append values to the end of an iterator.\n */\nexport function* prepend<const ElementType>(\n\titerable: IterableResolvable<ElementType>,\n\t...iterables: IterableResolvable<ElementType>[]\n): IterableIterator<ElementType> {\n\tfor (const iterable of iterables) {\n\t\tyield* toIterableIterator(iterable);\n\t}\n\n\tyield* toIterableIterator(iterable);\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates an iterator with the provided iterables prepended to the first iterable.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable The iterator to prepend values to.
|
|
7
|
+
* @param iterables The iterables to prepend to the iterator.
|
|
8
|
+
* @returns An iterator that yields the values of the provided iterator followed by the values of the provided iterables.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { prepend } from '@sapphire/iterator-utilities';
|
|
13
|
+
*
|
|
14
|
+
* console.log([...prepend([3, 4, 5], [1, 2])]);
|
|
15
|
+
* // Output: [1, 2, 3, 4, 5]
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @seealso {@link append} to append values to the end of an iterator.
|
|
19
|
+
*/
|
|
20
|
+
declare function prepend<const ElementType>(iterable: IterableResolvable<ElementType>, ...iterables: IterableResolvable<ElementType>[]): IterableIterator<ElementType>;
|
|
21
|
+
|
|
22
|
+
export { prepend };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var map_cjs = require('./map.cjs');
|
|
4
|
+
var _toNumberOrThrow_cjs = require('./shared/_toNumberOrThrow.cjs');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
function product(iterable) {
|
|
9
|
+
let result = 1;
|
|
10
|
+
for (const value of map_cjs.map(iterable, _toNumberOrThrow_cjs.toNumberOrThrow)) {
|
|
11
|
+
result *= value;
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
__name(product, "product");
|
|
16
|
+
|
|
17
|
+
exports.product = product;
|
|
18
|
+
//# sourceMappingURL=out.js.map
|
|
19
|
+
//# sourceMappingURL=product.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/product.ts"],"names":[],"mappings":";;;;AACA,SAAS,WAAW;AACpB,SAAS,uBAAuB;AAqBzB,SAAS,QAAQ,UAA8C;AACrE,MAAI,SAAS;AACb,aAAW,SAAS,IAAI,UAAU,eAAe,GAAG;AACnD,cAAU;AAAA,EACX;AAEA,SAAO;AACR;AAPgB","sourcesContent":["import type { IterableResolvable } from './from';\nimport { map } from './map';\nimport { toNumberOrThrow } from './shared/_toNumberOrThrow';\n\n/**\n * Consumes the iterable and returns the product of all the elements. If the iterable is empty, it returns `1`.\n *\n * @param iterable An iterator to calculate the product of.\n * @returns The product of the elements in the input iterator.\n *\n * @example\n * ```typescript\n * import { product } from '@sapphire/iterator-utilities';\n *\n * const iterable = [1, 2, 3, 4, 5];\n * console.log(product(iterable));\n * // Output: 120\n *\n * const iterable = [1, 2, 3, 4, 5, 0];\n * console.log(product(iterable));\n * // Output: 0\n * ```\n */\nexport function product(iterable: IterableResolvable<number>): number {\n\tlet result = 1;\n\tfor (const value of map(iterable, toNumberOrThrow)) {\n\t\tresult *= value;\n\t}\n\n\treturn result;\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable and returns the product of all the elements. If the iterable is empty, it returns `1`.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to calculate the product of.
|
|
7
|
+
* @returns The product of the elements in the input iterator.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { product } from '@sapphire/iterator-utilities';
|
|
12
|
+
*
|
|
13
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
14
|
+
* console.log(product(iterable));
|
|
15
|
+
* // Output: 120
|
|
16
|
+
*
|
|
17
|
+
* const iterable = [1, 2, 3, 4, 5, 0];
|
|
18
|
+
* console.log(product(iterable));
|
|
19
|
+
* // Output: 0
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare function product(iterable: IterableResolvable<number>): number;
|
|
23
|
+
|
|
24
|
+
export { product };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _toNumberOrThrow_cjs = require('./shared/_toNumberOrThrow.cjs');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function* range(start, end, step) {
|
|
8
|
+
start = _toNumberOrThrow_cjs.toNumberOrThrow(start);
|
|
9
|
+
end = _toNumberOrThrow_cjs.toNumberOrThrow(end);
|
|
10
|
+
if (step === void 0) {
|
|
11
|
+
step = start < end ? 1 : -1;
|
|
12
|
+
} else {
|
|
13
|
+
step = _toNumberOrThrow_cjs.toNumberOrThrow(step);
|
|
14
|
+
if (step === 0) {
|
|
15
|
+
throw new RangeError("Step cannot be zero");
|
|
16
|
+
}
|
|
17
|
+
if (step > 0 && start > end) {
|
|
18
|
+
throw new RangeError("Start must be less than end when step is positive");
|
|
19
|
+
} else if (step < 0 && start < end) {
|
|
20
|
+
throw new RangeError("Start must be greater than end when step is negative");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (start < end) {
|
|
24
|
+
for (let i = start; i < end; i += step) {
|
|
25
|
+
yield i;
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
for (let i = start; i > end; i += step) {
|
|
29
|
+
yield i;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
__name(range, "range");
|
|
34
|
+
|
|
35
|
+
exports.range = range;
|
|
36
|
+
//# sourceMappingURL=out.js.map
|
|
37
|
+
//# sourceMappingURL=range.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/range.ts"],"names":[],"mappings":";;;;AAAA,SAAS,uBAAuB;AAgCzB,UAAU,MAAM,OAAe,KAAa,MAAqD;AACvG,UAAQ,gBAAgB,KAAK;AAC7B,QAAM,gBAAgB,GAAG;AAEzB,MAAI,SAAS,QAAW;AACvB,WAAO,QAAQ,MAAM,IAAI;AAAA,EAC1B,OAAO;AACN,WAAO,gBAAgB,IAAI;AAG3B,QAAI,SAAS,GAAG;AACf,YAAM,IAAI,WAAW,qBAAqB;AAAA,IAC3C;AAGA,QAAI,OAAO,KAAK,QAAQ,KAAK;AAC5B,YAAM,IAAI,WAAW,mDAAmD;AAAA,IACzE,WAAW,OAAO,KAAK,QAAQ,KAAK;AACnC,YAAM,IAAI,WAAW,sDAAsD;AAAA,IAC5E;AAAA,EACD;AAEA,MAAI,QAAQ,KAAK;AAChB,aAAS,IAAI,OAAO,IAAI,KAAK,KAAK,MAAM;AACvC,YAAM;AAAA,IACP;AAAA,EACD,OAAO;AACN,aAAS,IAAI,OAAO,IAAI,KAAK,KAAK,MAAM;AACvC,YAAM;AAAA,IACP;AAAA,EACD;AACD;AA/BiB","sourcesContent":["import { toNumberOrThrow } from './shared/_toNumberOrThrow';\n\n/**\n * Creates an iterable with the numbers from `start` to `stop` (exclusive) with an optional step.\n *\n * @param start The value of the first number in the range.\n * @param end The end value of the range.\n * @param step The amount to increment the range by.\n *\n * @example\n * ```typescript\n * import { range } from '@sapphire/iterator-utilities';\n *\n * const iterable = range(0, 5);\n * console.log([...iterable]);\n * // Output: [0, 1, 2, 3, 4]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = range(5, 0);\n * console.log([...iterable]);\n * // Output: [5, 4, 3, 2, 1]\n * ```\n *\n * @example\n * ```typescript\n * const iterable = range(0, 5, 2);\n * console.log([...iterable]);\n * // Output: [0, 2, 4]\n * ```\n */\nexport function* range(start: number, end: number, step?: number | undefined): IterableIterator<number> {\n\tstart = toNumberOrThrow(start);\n\tend = toNumberOrThrow(end);\n\n\tif (step === undefined) {\n\t\tstep = start < end ? 1 : -1;\n\t} else {\n\t\tstep = toNumberOrThrow(step);\n\n\t\t// Prevent infinite loops.\n\t\tif (step === 0) {\n\t\t\tthrow new RangeError('Step cannot be zero');\n\t\t}\n\n\t\t// If the step is positive, the start must be less than the end.\n\t\tif (step > 0 && start > end) {\n\t\t\tthrow new RangeError('Start must be less than end when step is positive');\n\t\t} else if (step < 0 && start < end) {\n\t\t\tthrow new RangeError('Start must be greater than end when step is negative');\n\t\t}\n\t}\n\n\tif (start < end) {\n\t\tfor (let i = start; i < end; i += step) {\n\t\t\tyield i;\n\t\t}\n\t} else {\n\t\tfor (let i = start; i > end; i += step) {\n\t\t\tyield i;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an iterable with the numbers from `start` to `stop` (exclusive) with an optional step.
|
|
3
|
+
*
|
|
4
|
+
* @param start The value of the first number in the range.
|
|
5
|
+
* @param end The end value of the range.
|
|
6
|
+
* @param step The amount to increment the range by.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { range } from '@sapphire/iterator-utilities';
|
|
11
|
+
*
|
|
12
|
+
* const iterable = range(0, 5);
|
|
13
|
+
* console.log([...iterable]);
|
|
14
|
+
* // Output: [0, 1, 2, 3, 4]
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const iterable = range(5, 0);
|
|
20
|
+
* console.log([...iterable]);
|
|
21
|
+
* // Output: [5, 4, 3, 2, 1]
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const iterable = range(0, 5, 2);
|
|
27
|
+
* console.log([...iterable]);
|
|
28
|
+
* // Output: [0, 2, 4]
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function range(start: number, end: number, step?: number | undefined): IterableIterator<number>;
|
|
32
|
+
|
|
33
|
+
export { range };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _assertFunction_cjs = require('./shared/_assertFunction.cjs');
|
|
4
|
+
var toIterableIterator_cjs = require('./toIterableIterator.cjs');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
function reduce(iterable, callbackFn, initialValue) {
|
|
9
|
+
callbackFn = _assertFunction_cjs.assertFunction(callbackFn);
|
|
10
|
+
let index;
|
|
11
|
+
let accumulator;
|
|
12
|
+
const resolvedIterable = toIterableIterator_cjs.toIterableIterator(iterable);
|
|
13
|
+
if (arguments.length < 3) {
|
|
14
|
+
const firstValue = resolvedIterable.next();
|
|
15
|
+
if (firstValue.done)
|
|
16
|
+
throw new TypeError("Reduce of empty iterator with no initial value");
|
|
17
|
+
index = 1;
|
|
18
|
+
accumulator = firstValue.value;
|
|
19
|
+
} else {
|
|
20
|
+
index = 0;
|
|
21
|
+
accumulator = initialValue;
|
|
22
|
+
}
|
|
23
|
+
for (const value of resolvedIterable) {
|
|
24
|
+
accumulator = callbackFn(accumulator, value, index++);
|
|
25
|
+
}
|
|
26
|
+
return accumulator;
|
|
27
|
+
}
|
|
28
|
+
__name(reduce, "reduce");
|
|
29
|
+
|
|
30
|
+
exports.reduce = reduce;
|
|
31
|
+
//# sourceMappingURL=out.js.map
|
|
32
|
+
//# sourceMappingURL=reduce.cjs.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,33 @@
|
|
|
1
|
+
import { IterableResolvable } from './from.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Consumes the iterable and reduces it to the reducer function's result.
|
|
5
|
+
*
|
|
6
|
+
* @param iterable An iterator to reduce.
|
|
7
|
+
* @param callbackFn A function to execute for each element produced by the iterator. Its return value becomes the value
|
|
8
|
+
* of the `accumulator` parameter on the next invocation of `callbackFn`. For the last invocation, the return value
|
|
9
|
+
* becomes the return value of `reduce()`.
|
|
10
|
+
* @param initialValue A value to which `accumulator` is initialized the first time the callback is called. If
|
|
11
|
+
* `initialValue` is specified, `callbackFn` starts executing with the first element as `currentValue`. If
|
|
12
|
+
* `initialValue` is not specified, `accumulator` is initialized to the first element, and `callbackFn` starts executing
|
|
13
|
+
* with the second element as `currentValue`. In this case, if the iterator is empty (so that there's no first value to
|
|
14
|
+
* return as `accumulator`), an error is thrown.
|
|
15
|
+
* @returns
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { reduce } from '@sapphire/iterator-utilities';
|
|
20
|
+
*
|
|
21
|
+
* const iterable = [1, 2, 3, 4, 5];
|
|
22
|
+
* console.log(reduce(iterable, (accumulator, currentValue) => accumulator + currentValue));
|
|
23
|
+
* // Output: 15
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
*
|
|
28
|
+
* If `initialValue` is not provided, the first element of the iterator is used as the initial value of `accumulator`,
|
|
29
|
+
* consuming the first element.
|
|
30
|
+
*/
|
|
31
|
+
declare function reduce<const ElementType, const MappedType>(iterable: IterableResolvable<ElementType>, callbackFn: (accumulator: MappedType, currentValue: ElementType, currentIndex: number) => MappedType, initialValue?: MappedType): MappedType;
|
|
32
|
+
|
|
33
|
+
export { reduce };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _assertNotNegative_cjs = require('./shared/_assertNotNegative.cjs');
|
|
4
|
+
var _makeIterableIterator_cjs = require('./shared/_makeIterableIterator.cjs');
|
|
5
|
+
var _toNumberOrThrow_cjs = require('./shared/_toNumberOrThrow.cjs');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
function repeat(value, count) {
|
|
10
|
+
count = _assertNotNegative_cjs.assertNotNegative(_toNumberOrThrow_cjs.toNumberOrThrow(count), count);
|
|
11
|
+
let i = 0;
|
|
12
|
+
return _makeIterableIterator_cjs.makeIterableIterator(
|
|
13
|
+
() => i >= count ? { done: true, value: void 0 } : (i++, { done: false, value })
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
__name(repeat, "repeat");
|
|
17
|
+
|
|
18
|
+
exports.repeat = repeat;
|
|
19
|
+
//# sourceMappingURL=out.js.map
|
|
20
|
+
//# sourceMappingURL=repeat.cjs.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,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,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var toIterableIterator_cjs = require('./toIterableIterator.cjs');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
function* reverse(iterable) {
|
|
8
|
+
const items = [];
|
|
9
|
+
for (const item of toIterableIterator_cjs.toIterableIterator(iterable)) {
|
|
10
|
+
items.push(item);
|
|
11
|
+
}
|
|
12
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
13
|
+
yield items[i];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
__name(reverse, "reverse");
|
|
17
|
+
|
|
18
|
+
exports.reverse = reverse;
|
|
19
|
+
//# sourceMappingURL=out.js.map
|
|
20
|
+
//# sourceMappingURL=reverse.cjs.map
|