zeed 1.3.0 → 1.4.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/AGENTS.md +50 -211
- package/README.md +16 -0
- package/dist/_experiments/bitcask.cjs +243 -1
- package/dist/_experiments/bitcask.cjs.map +1 -1
- package/dist/_experiments/bitcask.mjs +230 -1
- package/dist/_experiments/bitcask.mjs.map +1 -1
- package/dist/bin-BAoS4qtm.mjs +593 -0
- package/dist/{bin-SPdenYkw.mjs.map → bin-BAoS4qtm.mjs.map} +1 -1
- package/dist/bin-Ddaz2lxM.cjs +862 -0
- package/dist/{bin-Ce3i6ABn.cjs.map → bin-Ddaz2lxM.cjs.map} +1 -1
- package/dist/browser/base64.cjs +14 -1
- package/dist/browser/base64.cjs.map +1 -1
- package/dist/browser/base64.mjs +12 -1
- package/dist/browser/base64.mjs.map +1 -1
- package/dist/browser/gravatar.cjs +186 -1
- package/dist/browser/gravatar.cjs.map +1 -1
- package/dist/browser/gravatar.mjs +184 -1
- package/dist/browser/gravatar.mjs.map +1 -1
- package/dist/browser/index.cjs +14 -1
- package/dist/browser/index.mjs +8 -1
- package/dist/browser/localstorage.cjs +46 -1
- package/dist/browser/localstorage.cjs.map +1 -1
- package/dist/browser/localstorage.mjs +45 -1
- package/dist/browser/localstorage.mjs.map +1 -1
- package/dist/browser/log/index.cjs +8 -1
- package/dist/browser/log/index.mjs +5 -1
- package/dist/browser/log/log-browser-factory.cjs +65 -1
- package/dist/browser/log/log-browser-factory.cjs.map +1 -1
- package/dist/browser/log/log-browser-factory.mjs +64 -1
- package/dist/browser/log/log-browser-factory.mjs.map +1 -1
- package/dist/browser/log/log-browser.cjs +72 -1
- package/dist/browser/log/log-browser.cjs.map +1 -1
- package/dist/browser/log/log-browser.mjs +71 -1
- package/dist/browser/log/log-browser.mjs.map +1 -1
- package/dist/browser/log/log-colors.cjs +11 -1
- package/dist/browser/log/log-colors.cjs.map +1 -1
- package/dist/browser/log/log-colors.mjs +9 -1
- package/dist/browser/log/log-colors.mjs.map +1 -1
- package/dist/browser/log/log-context-browser.cjs +25 -1
- package/dist/browser/log/log-context-browser.cjs.map +1 -1
- package/dist/browser/log/log-context-browser.mjs +23 -1
- package/dist/browser/log/log-context-browser.mjs.map +1 -1
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/chunk-uaV2rQ02.cjs +53 -0
- package/dist/common/assert.cjs +22 -1
- package/dist/common/assert.cjs.map +1 -1
- package/dist/common/assert.mjs +19 -1
- package/dist/common/assert.mjs.map +1 -1
- package/dist/common/bin/index.cjs +106 -1
- package/dist/common/bin/index.cjs.map +1 -1
- package/dist/common/bin/index.mjs +98 -1
- package/dist/common/bin/index.mjs.map +1 -1
- package/dist/common/bin/lib0/binary.cjs +146 -1
- package/dist/common/bin/lib0/binary.cjs.map +1 -1
- package/dist/common/bin/lib0/binary.mjs +80 -1
- package/dist/common/bin/lib0/binary.mjs.map +1 -1
- package/dist/common/bin/lib0/buffer.cjs +42 -1
- package/dist/common/bin/lib0/buffer.cjs.map +1 -1
- package/dist/common/bin/lib0/buffer.mjs +38 -1
- package/dist/common/bin/lib0/buffer.mjs.map +1 -1
- package/dist/common/bin/lib0/create.cjs +24 -1
- package/dist/common/bin/lib0/create.cjs.map +1 -1
- package/dist/common/bin/lib0/create.mjs +21 -1
- package/dist/common/bin/lib0/create.mjs.map +1 -1
- package/dist/common/bin/lib0/decoding.cjs +325 -1
- package/dist/common/bin/lib0/decoding.cjs.map +1 -1
- package/dist/common/bin/lib0/decoding.mjs +298 -1
- package/dist/common/bin/lib0/decoding.mjs.map +1 -1
- package/dist/common/bin/lib0/encoding.cjs +404 -1
- package/dist/common/bin/lib0/encoding.cjs.map +1 -1
- package/dist/common/bin/lib0/encoding.mjs +377 -1
- package/dist/common/bin/lib0/encoding.mjs.map +1 -1
- package/dist/common/bin/lib0/string.cjs +81 -1
- package/dist/common/bin/lib0/string.cjs.map +1 -1
- package/dist/common/bin/lib0/string.mjs +71 -1
- package/dist/common/bin/lib0/string.mjs.map +1 -1
- package/dist/common/crypto/aes-sealed.cjs +34 -1
- package/dist/common/crypto/aes-sealed.cjs.map +1 -1
- package/dist/common/crypto/aes-sealed.mjs +32 -1
- package/dist/common/crypto/aes-sealed.mjs.map +1 -1
- package/dist/common/crypto/crypto.cjs +91 -1
- package/dist/common/crypto/crypto.cjs.map +1 -1
- package/dist/common/crypto/crypto.mjs +80 -1
- package/dist/common/crypto/crypto.mjs.map +1 -1
- package/dist/common/crypto/index.cjs +23 -1
- package/dist/common/crypto/index.mjs +5 -1
- package/dist/common/crypto/xaes.cjs +128 -1
- package/dist/common/crypto/xaes.cjs.map +1 -1
- package/dist/common/crypto/xaes.mjs +123 -1
- package/dist/common/crypto/xaes.mjs.map +1 -1
- package/dist/common/csv.cjs +49 -4
- package/dist/common/csv.cjs.map +1 -1
- package/dist/common/csv.mjs +46 -4
- package/dist/common/csv.mjs.map +1 -1
- package/dist/common/data/array.cjs +299 -1
- package/dist/common/data/array.cjs.map +1 -1
- package/dist/common/data/array.mjs +274 -1
- package/dist/common/data/array.mjs.map +1 -1
- package/dist/common/data/basex-secure.cjs +30 -1
- package/dist/common/data/basex-secure.mjs +3 -1
- package/dist/common/data/basex.cjs +163 -1
- package/dist/common/data/basex.cjs.map +1 -1
- package/dist/common/data/basex.mjs +152 -1
- package/dist/common/data/basex.mjs.map +1 -1
- package/dist/common/data/bin-types.mjs +1 -1
- package/dist/common/data/bin.cjs +21 -1
- package/dist/common/data/bin.mjs +3 -1
- package/dist/common/data/camelcase.cjs +27 -1
- package/dist/common/data/camelcase.cjs.map +1 -1
- package/dist/common/data/camelcase.mjs +22 -1
- package/dist/common/data/camelcase.mjs.map +1 -1
- package/dist/common/data/convert.cjs +104 -1
- package/dist/common/data/convert.cjs.map +1 -1
- package/dist/common/data/convert.mjs +88 -1
- package/dist/common/data/convert.mjs.map +1 -1
- package/dist/common/data/datauri.cjs +32 -1
- package/dist/common/data/datauri.cjs.map +1 -1
- package/dist/common/data/datauri.mjs +27 -1
- package/dist/common/data/datauri.mjs.map +1 -1
- package/dist/common/data/day-legacy.cjs +148 -1
- package/dist/common/data/day-legacy.cjs.map +1 -1
- package/dist/common/data/day-legacy.mjs +143 -1
- package/dist/common/data/day-legacy.mjs.map +1 -1
- package/dist/common/data/day.cjs +335 -1
- package/dist/common/data/day.cjs.map +1 -1
- package/dist/common/data/day.mjs +305 -1
- package/dist/common/data/day.mjs.map +1 -1
- package/dist/common/data/decimal.cjs +28 -1
- package/dist/common/data/decimal.cjs.map +1 -1
- package/dist/common/data/decimal.mjs +23 -1
- package/dist/common/data/decimal.mjs.map +1 -1
- package/dist/common/data/deep.cjs +57 -1
- package/dist/common/data/deep.cjs.map +1 -1
- package/dist/common/data/deep.mjs +54 -1
- package/dist/common/data/deep.mjs.map +1 -1
- package/dist/common/data/diff.cjs +62 -1
- package/dist/common/data/diff.cjs.map +1 -1
- package/dist/common/data/diff.mjs +60 -1
- package/dist/common/data/diff.mjs.map +1 -1
- package/dist/common/data/distributed.cjs +24 -1
- package/dist/common/data/distributed.cjs.map +1 -1
- package/dist/common/data/distributed.mjs +22 -1
- package/dist/common/data/distributed.mjs.map +1 -1
- package/dist/common/data/format.cjs +63 -1
- package/dist/common/data/format.cjs.map +1 -1
- package/dist/common/data/format.mjs +59 -1
- package/dist/common/data/format.mjs.map +1 -1
- package/dist/common/data/html.cjs +13 -1
- package/dist/common/data/html.cjs.map +1 -1
- package/dist/common/data/html.mjs +10 -1
- package/dist/common/data/html.mjs.map +1 -1
- package/dist/common/data/index.cjs +296 -1
- package/dist/common/data/index.mjs +37 -1
- package/dist/common/data/is.cjs +106 -1
- package/dist/common/data/is.cjs.map +1 -1
- package/dist/common/data/is.mjs +85 -1
- package/dist/common/data/is.mjs.map +1 -1
- package/dist/common/data/json.cjs +70 -1
- package/dist/common/data/json.cjs.map +1 -1
- package/dist/common/data/json.mjs +65 -1
- package/dist/common/data/json.mjs.map +1 -1
- package/dist/common/data/list.cjs +32 -1
- package/dist/common/data/list.cjs.map +1 -1
- package/dist/common/data/list.mjs +27 -1
- package/dist/common/data/list.mjs.map +1 -1
- package/dist/common/data/lru.mjs +1 -1
- package/dist/common/data/math.cjs +79 -1
- package/dist/common/data/math.cjs.map +1 -1
- package/dist/common/data/math.mjs +65 -1
- package/dist/common/data/math.mjs.map +1 -1
- package/dist/common/data/message.cjs +30 -1
- package/dist/common/data/message.cjs.map +1 -1
- package/dist/common/data/message.mjs +28 -1
- package/dist/common/data/message.mjs.map +1 -1
- package/dist/common/data/object-changes.cjs +66 -1
- package/dist/common/data/object-changes.cjs.map +1 -1
- package/dist/common/data/object-changes.mjs +63 -1
- package/dist/common/data/object-changes.mjs.map +1 -1
- package/dist/common/data/object.cjs +112 -1
- package/dist/common/data/object.cjs.map +1 -1
- package/dist/common/data/object.mjs +104 -1
- package/dist/common/data/object.mjs.map +1 -1
- package/dist/common/data/orderby.cjs +42 -1
- package/dist/common/data/orderby.cjs.map +1 -1
- package/dist/common/data/orderby.mjs +37 -1
- package/dist/common/data/orderby.mjs.map +1 -1
- package/dist/common/data/path.cjs +26 -1
- package/dist/common/data/path.cjs.map +1 -1
- package/dist/common/data/path.mjs +25 -1
- package/dist/common/data/path.mjs.map +1 -1
- package/dist/common/data/regexp.cjs +12 -1
- package/dist/common/data/regexp.cjs.map +1 -1
- package/dist/common/data/regexp.mjs +10 -1
- package/dist/common/data/regexp.mjs.map +1 -1
- package/dist/common/data/rounding.cjs +107 -1
- package/dist/common/data/rounding.cjs.map +1 -1
- package/dist/common/data/rounding.mjs +95 -1
- package/dist/common/data/rounding.mjs.map +1 -1
- package/dist/common/data/signal.cjs +39 -1
- package/dist/common/data/signal.cjs.map +1 -1
- package/dist/common/data/signal.mjs +38 -1
- package/dist/common/data/signal.mjs.map +1 -1
- package/dist/common/data/sortable.cjs +35 -1
- package/dist/common/data/sortable.cjs.map +1 -1
- package/dist/common/data/sortable.mjs +31 -1
- package/dist/common/data/sortable.mjs.map +1 -1
- package/dist/common/data/sorted.cjs +54 -1
- package/dist/common/data/sorted.cjs.map +1 -1
- package/dist/common/data/sorted.mjs +53 -1
- package/dist/common/data/sorted.mjs.map +1 -1
- package/dist/common/data/string-deburr.cjs +240 -1
- package/dist/common/data/string-deburr.cjs.map +1 -1
- package/dist/common/data/string-deburr.mjs +238 -1
- package/dist/common/data/string-deburr.mjs.map +1 -1
- package/dist/common/data/string-hash-fnv.cjs +69 -1
- package/dist/common/data/string-hash-fnv.cjs.map +1 -1
- package/dist/common/data/string-hash-fnv.mjs +67 -1
- package/dist/common/data/string-hash-fnv.mjs.map +1 -1
- package/dist/common/data/string-hash-pool.cjs +28 -1
- package/dist/common/data/string-hash-pool.cjs.map +1 -1
- package/dist/common/data/string-hash-pool.mjs +27 -1
- package/dist/common/data/string-hash-pool.mjs.map +1 -1
- package/dist/common/data/url.cjs +98 -2
- package/dist/common/data/url.cjs.map +1 -1
- package/dist/common/data/url.mjs +91 -2
- package/dist/common/data/url.mjs.map +1 -1
- package/dist/common/data/utils.cjs +118 -1
- package/dist/common/data/utils.cjs.map +1 -1
- package/dist/common/data/utils.mjs +107 -1
- package/dist/common/data/utils.mjs.map +1 -1
- package/dist/common/data/wordlist.cjs +531 -1
- package/dist/common/data/wordlist.cjs.map +1 -1
- package/dist/common/data/wordlist.mjs +529 -1
- package/dist/common/data/wordlist.mjs.map +1 -1
- package/dist/common/data/xrx.cjs +96 -1
- package/dist/common/data/xrx.cjs.map +1 -1
- package/dist/common/data/xrx.mjs +92 -1
- package/dist/common/data/xrx.mjs.map +1 -1
- package/dist/common/dispose-defer.cjs +133 -1
- package/dist/common/dispose-defer.cjs.map +1 -1
- package/dist/common/dispose-defer.mjs +130 -1
- package/dist/common/dispose-defer.mjs.map +1 -1
- package/dist/common/dispose-types.mjs +1 -1
- package/dist/common/dispose-utils.cjs +113 -1
- package/dist/common/dispose-utils.cjs.map +1 -1
- package/dist/common/dispose-utils.mjs +106 -1
- package/dist/common/dispose-utils.mjs.map +1 -1
- package/dist/common/exec/index.cjs +24 -1
- package/dist/common/exec/index.d.cts +1 -1
- package/dist/common/exec/index.d.mts +1 -1
- package/dist/common/exec/index.mjs +8 -1
- package/dist/common/exec/mutex.cjs +44 -1
- package/dist/common/exec/mutex.cjs.map +1 -1
- package/dist/common/exec/mutex.mjs +42 -1
- package/dist/common/exec/mutex.mjs.map +1 -1
- package/dist/common/exec/pool.cjs +181 -1
- package/dist/common/exec/pool.cjs.map +1 -1
- package/dist/common/exec/pool.d.cts +1 -1
- package/dist/common/exec/pool.d.mts +1 -1
- package/dist/common/exec/pool.mjs +180 -1
- package/dist/common/exec/pool.mjs.map +1 -1
- package/dist/common/exec/progress.cjs +149 -1
- package/dist/common/exec/progress.cjs.map +1 -1
- package/dist/common/exec/progress.d.cts +1 -1
- package/dist/common/exec/progress.d.mts +1 -1
- package/dist/common/exec/progress.mjs +148 -1
- package/dist/common/exec/progress.mjs.map +1 -1
- package/dist/common/exec/promise.cjs +113 -1
- package/dist/common/exec/promise.cjs.map +1 -1
- package/dist/common/exec/promise.mjs +103 -1
- package/dist/common/exec/promise.mjs.map +1 -1
- package/dist/common/exec/queue.cjs +125 -1
- package/dist/common/exec/queue.cjs.map +1 -1
- package/dist/common/exec/queue.d.cts +1 -1
- package/dist/common/exec/queue.d.mts +1 -1
- package/dist/common/exec/queue.mjs +124 -1
- package/dist/common/exec/queue.mjs.map +1 -1
- package/dist/common/exec/throttle-debounce.cjs +114 -1
- package/dist/common/exec/throttle-debounce.cjs.map +1 -1
- package/dist/common/exec/throttle-debounce.mjs +112 -1
- package/dist/common/exec/throttle-debounce.mjs.map +1 -1
- package/dist/common/global.cjs +22 -1
- package/dist/common/global.cjs.map +1 -1
- package/dist/common/global.mjs +19 -1
- package/dist/common/global.mjs.map +1 -1
- package/dist/common/index.cjs +559 -1
- package/dist/common/index.d.cts +1 -1
- package/dist/common/index.d.mts +1 -1
- package/dist/common/index.mjs +89 -1
- package/dist/common/localhost.cjs +16 -1
- package/dist/common/localhost.cjs.map +1 -1
- package/dist/common/localhost.mjs +14 -1
- package/dist/common/localhost.mjs.map +1 -1
- package/dist/common/log/index.cjs +34 -1
- package/dist/common/log/index.mjs +11 -1
- package/dist/common/log/log-base.cjs +40 -1
- package/dist/common/log/log-base.cjs.map +1 -1
- package/dist/common/log/log-base.mjs +31 -1
- package/dist/common/log/log-base.mjs.map +1 -1
- package/dist/common/log/log-colors.cjs +92 -1
- package/dist/common/log/log-colors.cjs.map +1 -1
- package/dist/common/log/log-colors.mjs +90 -1
- package/dist/common/log/log-colors.mjs.map +1 -1
- package/dist/common/log/log-config.cjs +15 -1
- package/dist/common/log/log-config.cjs.map +1 -1
- package/dist/common/log/log-config.mjs +14 -1
- package/dist/common/log/log-config.mjs.map +1 -1
- package/dist/common/log/log-console-capture.cjs +33 -1
- package/dist/common/log/log-console-capture.cjs.map +1 -1
- package/dist/common/log/log-console-capture.mjs +32 -1
- package/dist/common/log/log-console-capture.mjs.map +1 -1
- package/dist/common/log/log-console-original.cjs +27 -1
- package/dist/common/log/log-console-original.cjs.map +1 -1
- package/dist/common/log/log-console-original.mjs +26 -1
- package/dist/common/log/log-console-original.mjs.map +1 -1
- package/dist/common/log/log-console.cjs +39 -1
- package/dist/common/log/log-console.cjs.map +1 -1
- package/dist/common/log/log-console.mjs +38 -1
- package/dist/common/log/log-console.mjs.map +1 -1
- package/dist/common/log/log-context.cjs +109 -1
- package/dist/common/log/log-context.cjs.map +1 -1
- package/dist/common/log/log-context.mjs +108 -1
- package/dist/common/log/log-context.mjs.map +1 -1
- package/dist/common/log/log-filter.cjs +80 -1
- package/dist/common/log/log-filter.cjs.map +1 -1
- package/dist/common/log/log-filter.mjs +75 -1
- package/dist/common/log/log-filter.mjs.map +1 -1
- package/dist/common/log/log-memory.cjs +45 -1
- package/dist/common/log/log-memory.cjs.map +1 -1
- package/dist/common/log/log-memory.mjs +43 -1
- package/dist/common/log/log-memory.mjs.map +1 -1
- package/dist/common/log/log-noop.cjs +17 -1
- package/dist/common/log/log-noop.cjs.map +1 -1
- package/dist/common/log/log-noop.mjs +15 -1
- package/dist/common/log/log-noop.mjs.map +1 -1
- package/dist/common/log/log.cjs +46 -1
- package/dist/common/log/log.cjs.map +1 -1
- package/dist/common/log/log.mjs +43 -1
- package/dist/common/log/log.mjs.map +1 -1
- package/dist/common/msg/channel-debug.cjs +17 -1
- package/dist/common/msg/channel-debug.cjs.map +1 -1
- package/dist/common/msg/channel-debug.d.cts +1 -1
- package/dist/common/msg/channel-debug.d.mts +1 -1
- package/dist/common/msg/channel-debug.mjs +16 -1
- package/dist/common/msg/channel-debug.mjs.map +1 -1
- package/dist/common/msg/channel-local.cjs +28 -1
- package/dist/common/msg/channel-local.cjs.map +1 -1
- package/dist/common/msg/channel-local.d.cts +1 -1
- package/dist/common/msg/channel-local.d.mts +1 -1
- package/dist/common/msg/channel-local.mjs +26 -1
- package/dist/common/msg/channel-local.mjs.map +1 -1
- package/dist/common/msg/channel-resilient.cjs +63 -1
- package/dist/common/msg/channel-resilient.cjs.map +1 -1
- package/dist/common/msg/channel-resilient.d.cts +1 -1
- package/dist/common/msg/channel-resilient.d.mts +1 -1
- package/dist/common/msg/channel-resilient.mjs +62 -1
- package/dist/common/msg/channel-resilient.mjs.map +1 -1
- package/dist/common/msg/channel-wkwebview.cjs +35 -1
- package/dist/common/msg/channel-wkwebview.cjs.map +1 -1
- package/dist/common/msg/channel-wkwebview.d.cts +2 -1
- package/dist/common/msg/channel-wkwebview.d.mts +2 -1
- package/dist/common/msg/channel-wkwebview.mjs +34 -1
- package/dist/common/msg/channel-wkwebview.mjs.map +1 -1
- package/dist/common/msg/channel.cjs +23 -1
- package/dist/common/msg/channel.cjs.map +1 -1
- package/dist/common/msg/channel.d.cts +1 -1
- package/dist/common/msg/channel.d.mts +1 -1
- package/dist/common/msg/channel.mjs +22 -1
- package/dist/common/msg/channel.mjs.map +1 -1
- package/dist/common/msg/emitter.cjs +141 -1
- package/dist/common/msg/emitter.cjs.map +1 -1
- package/dist/common/msg/emitter.d.cts +1 -1
- package/dist/common/msg/emitter.d.mts +1 -1
- package/dist/common/msg/emitter.mjs +139 -1
- package/dist/common/msg/emitter.mjs.map +1 -1
- package/dist/common/msg/encoder.cjs +38 -1
- package/dist/common/msg/encoder.cjs.map +1 -1
- package/dist/common/msg/encoder.mjs +35 -1
- package/dist/common/msg/encoder.mjs.map +1 -1
- package/dist/common/msg/index.cjs +28 -1
- package/dist/common/msg/index.d.cts +1 -1
- package/dist/common/msg/index.d.mts +1 -1
- package/dist/common/msg/index.mjs +11 -1
- package/dist/common/msg/messages.cjs +135 -1
- package/dist/common/msg/messages.cjs.map +1 -1
- package/dist/common/msg/messages.d.cts +1 -1
- package/dist/common/msg/messages.d.mts +1 -1
- package/dist/common/msg/messages.mjs +133 -1
- package/dist/common/msg/messages.mjs.map +1 -1
- package/dist/common/msg/pipe.mjs +1 -1
- package/dist/common/msg/pubsub.cjs +78 -1
- package/dist/common/msg/pubsub.cjs.map +1 -1
- package/dist/common/msg/pubsub.d.cts +1 -1
- package/dist/common/msg/pubsub.d.mts +1 -1
- package/dist/common/msg/pubsub.mjs +76 -1
- package/dist/common/msg/pubsub.mjs.map +1 -1
- package/dist/common/msg/rpc.cjs +142 -1
- package/dist/common/msg/rpc.cjs.map +1 -1
- package/dist/common/msg/rpc.mjs +139 -1
- package/dist/common/msg/rpc.mjs.map +1 -1
- package/dist/common/network.cjs +129 -1
- package/dist/common/network.cjs.map +1 -1
- package/dist/common/network.mjs +122 -1
- package/dist/common/network.mjs.map +1 -1
- package/dist/common/platform.cjs +92 -1
- package/dist/common/platform.cjs.map +1 -1
- package/dist/common/platform.mjs +84 -1
- package/dist/common/platform.mjs.map +1 -1
- package/dist/common/schema/_sandbox/sandbox-inherit.mjs +1 -1
- package/dist/common/schema/_sandbox/sandbox.mjs +1 -1
- package/dist/common/schema/_sandbox/sandbox.xspec.mjs +1 -1
- package/dist/common/schema/export-json-schema.cjs +54 -1
- package/dist/common/schema/export-json-schema.cjs.map +1 -1
- package/dist/common/schema/export-json-schema.mjs +52 -1
- package/dist/common/schema/export-json-schema.mjs.map +1 -1
- package/dist/common/schema/export-swift.cjs +30 -2
- package/dist/common/schema/export-swift.cjs.map +1 -1
- package/dist/common/schema/export-swift.mjs +29 -2
- package/dist/common/schema/export-swift.mjs.map +1 -1
- package/dist/common/schema/export-typescript.cjs +20 -2
- package/dist/common/schema/export-typescript.cjs.map +1 -1
- package/dist/common/schema/export-typescript.mjs +19 -2
- package/dist/common/schema/export-typescript.mjs.map +1 -1
- package/dist/common/schema/index.cjs +55 -1
- package/dist/common/schema/index.mjs +12 -1
- package/dist/common/schema/parse-args.cjs +62 -2
- package/dist/common/schema/parse-args.cjs.map +1 -1
- package/dist/common/schema/parse-args.mjs +60 -2
- package/dist/common/schema/parse-args.mjs.map +1 -1
- package/dist/common/schema/parse-env.cjs +48 -3
- package/dist/common/schema/parse-env.cjs.map +1 -1
- package/dist/common/schema/parse-env.mjs +46 -3
- package/dist/common/schema/parse-env.mjs.map +1 -1
- package/dist/common/schema/parse-object.cjs +122 -1
- package/dist/common/schema/parse-object.cjs.map +1 -1
- package/dist/common/schema/parse-object.mjs +119 -1
- package/dist/common/schema/parse-object.mjs.map +1 -1
- package/dist/common/schema/schema-standard.mjs +1 -1
- package/dist/common/schema/schema.cjs +423 -1
- package/dist/common/schema/schema.cjs.map +1 -1
- package/dist/common/schema/schema.mjs +404 -1
- package/dist/common/schema/schema.mjs.map +1 -1
- package/dist/common/schema/serialize.cjs +109 -1
- package/dist/common/schema/serialize.cjs.map +1 -1
- package/dist/common/schema/serialize.mjs +107 -1
- package/dist/common/schema/serialize.mjs.map +1 -1
- package/dist/common/schema/type-test.mjs +1 -1
- package/dist/common/schema/utils.cjs +25 -1
- package/dist/common/schema/utils.cjs.map +1 -1
- package/dist/common/schema/utils.mjs +19 -1
- package/dist/common/schema/utils.mjs.map +1 -1
- package/dist/common/schema/z-collection.cjs +51 -1
- package/dist/common/schema/z-collection.mjs +27 -1
- package/dist/common/schema/z.cjs +9 -1
- package/dist/common/schema/z.mjs +3 -1
- package/dist/common/storage/index.cjs +4 -1
- package/dist/common/storage/index.mjs +3 -1
- package/dist/common/storage/memstorage.cjs +26 -1
- package/dist/common/storage/memstorage.cjs.map +1 -1
- package/dist/common/storage/memstorage.mjs +25 -1
- package/dist/common/storage/memstorage.mjs.map +1 -1
- package/dist/common/test.cjs +14 -1
- package/dist/common/test.cjs.map +1 -1
- package/dist/common/test.mjs +13 -1
- package/dist/common/test.mjs.map +1 -1
- package/dist/common/time.cjs +220 -1
- package/dist/common/time.cjs.map +1 -1
- package/dist/common/time.mjs +194 -1
- package/dist/common/time.mjs.map +1 -1
- package/dist/common/timeout.cjs +27 -1
- package/dist/common/timeout.cjs.map +1 -1
- package/dist/common/timeout.mjs +25 -1
- package/dist/common/timeout.mjs.map +1 -1
- package/dist/common/types.mjs +1 -1
- package/dist/common/utils.cjs +7 -1
- package/dist/common/utils.cjs.map +1 -1
- package/dist/common/utils.mjs +5 -1
- package/dist/common/utils.mjs.map +1 -1
- package/dist/common/uuid.cjs +307 -1
- package/dist/common/uuid.cjs.map +1 -1
- package/dist/common/uuid.mjs +284 -1
- package/dist/common/uuid.mjs.map +1 -1
- package/dist/{index-DHXVOH8h.d.cts → index-CFkMqHvX.d.cts} +1 -2
- package/dist/{index-DMaPyx9O.d.mts → index-C_3Y_s6f.d.mts} +1 -2
- package/dist/index.all.cjs +641 -1
- package/dist/index.all.d.cts +1 -1
- package/dist/index.all.d.mts +1 -1
- package/dist/index.all.mjs +113 -1
- package/dist/index.browser.cjs +576 -1
- package/dist/index.browser.d.cts +1 -1
- package/dist/index.browser.d.mts +1 -1
- package/dist/index.browser.mjs +98 -1
- package/dist/index.jsr.cjs +57 -1
- package/dist/index.jsr.mjs +6 -1
- package/dist/index.node.cjs +628 -1
- package/dist/index.node.d.cts +1 -1
- package/dist/index.node.d.mts +1 -1
- package/dist/index.node.mjs +106 -1
- package/dist/node/args.cjs +56 -1
- package/dist/node/args.cjs.map +1 -1
- package/dist/node/args.mjs +53 -1
- package/dist/node/args.mjs.map +1 -1
- package/dist/node/clipboard.cjs +18 -1
- package/dist/node/clipboard.cjs.map +1 -1
- package/dist/node/clipboard.mjs +16 -1
- package/dist/node/clipboard.mjs.map +1 -1
- package/dist/node/crypto.cjs +28 -1
- package/dist/node/crypto.cjs.map +1 -1
- package/dist/node/crypto.mjs +24 -1
- package/dist/node/crypto.mjs.map +1 -1
- package/dist/node/env.cjs +100 -4
- package/dist/node/env.cjs.map +1 -1
- package/dist/node/env.mjs +90 -4
- package/dist/node/env.mjs.map +1 -1
- package/dist/node/files-async.cjs +66 -1
- package/dist/node/files-async.cjs.map +1 -1
- package/dist/node/files-async.mjs +60 -1
- package/dist/node/files-async.mjs.map +1 -1
- package/dist/node/files.cjs +52 -1
- package/dist/node/files.cjs.map +1 -1
- package/dist/node/files.mjs +46 -1
- package/dist/node/files.mjs.map +1 -1
- package/dist/node/filestorage.cjs +100 -1
- package/dist/node/filestorage.cjs.map +1 -1
- package/dist/node/filestorage.mjs +97 -1
- package/dist/node/filestorage.mjs.map +1 -1
- package/dist/node/fs.cjs +119 -1
- package/dist/node/fs.cjs.map +1 -1
- package/dist/node/fs.mjs +101 -1
- package/dist/node/fs.mjs.map +1 -1
- package/dist/node/glob.cjs +75 -1
- package/dist/node/glob.cjs.map +1 -1
- package/dist/node/glob.mjs +73 -1
- package/dist/node/glob.mjs.map +1 -1
- package/dist/node/index.cjs +66 -1
- package/dist/node/index.mjs +16 -1
- package/dist/node/log/index.cjs +20 -1
- package/dist/node/log/index.mjs +7 -1
- package/dist/node/log/log-context-node.cjs +39 -1
- package/dist/node/log/log-context-node.cjs.map +1 -1
- package/dist/node/log/log-context-node.mjs +35 -1
- package/dist/node/log/log-context-node.mjs.map +1 -1
- package/dist/node/log/log-file-rotation.cjs +71 -1
- package/dist/node/log/log-file-rotation.cjs.map +1 -1
- package/dist/node/log/log-file-rotation.mjs +68 -1
- package/dist/node/log/log-file-rotation.mjs.map +1 -1
- package/dist/node/log/log-file.cjs +57 -1
- package/dist/node/log/log-file.cjs.map +1 -1
- package/dist/node/log/log-file.mjs +54 -1
- package/dist/node/log/log-file.mjs.map +1 -1
- package/dist/node/log/log-node.cjs +162 -1
- package/dist/node/log/log-node.cjs.map +1 -1
- package/dist/node/log/log-node.mjs +155 -1
- package/dist/node/log/log-node.mjs.map +1 -1
- package/dist/node/log/log-rotation.cjs +543 -3
- package/dist/node/log/log-rotation.cjs.map +1 -1
- package/dist/node/log/log-rotation.mjs +538 -3
- package/dist/node/log/log-rotation.mjs.map +1 -1
- package/dist/node/log/log-util.cjs +69 -3
- package/dist/node/log/log-util.cjs.map +1 -1
- package/dist/node/log/log-util.mjs +63 -3
- package/dist/node/log/log-util.mjs.map +1 -1
- package/dist/node/open-browser.cjs +20 -1
- package/dist/node/open-browser.cjs.map +1 -1
- package/dist/node/open-browser.mjs +18 -1
- package/dist/node/open-browser.mjs.map +1 -1
- package/package.json +15 -15
- package/src/common/schema/README.md +247 -66
- package/src/eslint-defaults.js +4 -0
- package/src/index.spec.ts +6 -6
- package/dist/bin-Ce3i6ABn.cjs +0 -3
- package/dist/bin-SPdenYkw.mjs +0 -3
- package/dist/chunk-0Lt9GpW0.mjs +0 -1
- package/dist/chunk-D-qHiVGv.cjs +0 -1
- package/src/common/schema/README-SCHEMA.md +0 -0
|
@@ -1,2 +1,300 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_common_data_math = require('./math.cjs');
|
|
3
|
+
const require_common_data_orderby = require('./orderby.cjs');
|
|
4
|
+
|
|
5
|
+
//#region src/common/data/array.ts
|
|
6
|
+
/**
|
|
7
|
+
* Return a new array with duplicate values removed. Maintains first occurrence order.
|
|
8
|
+
* @typeParam T - element type
|
|
9
|
+
* @param arr - input array
|
|
10
|
+
* @returns new array containing unique elements from `arr`
|
|
11
|
+
*/
|
|
12
|
+
function arrayUnique(arr) {
|
|
13
|
+
return arr.filter((n, index) => arr.indexOf(n) === index);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Return elements present in `x` but not in `y`.
|
|
17
|
+
* @typeParam T - element type
|
|
18
|
+
* @param left - left-hand array
|
|
19
|
+
* @param right - array of elements to exclude
|
|
20
|
+
* @returns new array with elements from `left` that are not included in `right`
|
|
21
|
+
*/
|
|
22
|
+
function arrayMinus(left, right) {
|
|
23
|
+
return arrayUnique(left.filter((n) => !right.includes(n)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Return the union of multiple arrays (unique elements across all inputs).
|
|
27
|
+
* @typeParam T - element type
|
|
28
|
+
* @param arrays - arrays to union
|
|
29
|
+
* @returns new array with unique elements from all provided arrays
|
|
30
|
+
*/
|
|
31
|
+
function arrayUnion(...arrays) {
|
|
32
|
+
return arrayUnique(arrays.reduce((acc = [], value) => acc.concat(value), []));
|
|
33
|
+
}
|
|
34
|
+
/** `[1,[2,3]]` becomes `[1,2,3]` */
|
|
35
|
+
/**
|
|
36
|
+
* Flatten nested arrays to a single-level array.
|
|
37
|
+
* Example: `[1, [2, 3]]` becomes `[1, 2, 3]`.
|
|
38
|
+
* @typeParam T - element type
|
|
39
|
+
* @param arrays - one or more nested arrays to flatten
|
|
40
|
+
* @returns flattened array containing all elements
|
|
41
|
+
*/
|
|
42
|
+
function arrayFlatten(...arrays) {
|
|
43
|
+
return arrays.flat(Number.POSITIVE_INFINITY);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Return the intersection of two arrays (elements present in both).
|
|
47
|
+
* @typeParam T - element type
|
|
48
|
+
* @param left - first array
|
|
49
|
+
* @param right - second array
|
|
50
|
+
* @returns new array with elements present in both `left` and `right`
|
|
51
|
+
*/
|
|
52
|
+
function arrayIntersection(left, right) {
|
|
53
|
+
return arrayUnique(left).filter((n) => right.includes(n));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Return the symmetric difference between two arrays (elements in either array but not both).
|
|
57
|
+
* @typeParam T - element type
|
|
58
|
+
*/
|
|
59
|
+
function arraySymmetricDifference(left, right) {
|
|
60
|
+
return arrayMinus(arrayUnion(left, right), arrayIntersection(left, right));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Remove all occurrences of `el` from `arr` in-place and return the mutated array.
|
|
64
|
+
* If `arr` is not an array, returns an empty array.
|
|
65
|
+
* @typeParam T - element type
|
|
66
|
+
* @param arr - array to modify
|
|
67
|
+
* @param el - element to remove
|
|
68
|
+
* @returns the same array instance with `el` removed
|
|
69
|
+
*/
|
|
70
|
+
function arrayRemoveElement(arr, el) {
|
|
71
|
+
if (arr && Array.isArray(arr)) {
|
|
72
|
+
let index;
|
|
73
|
+
while ((index = arr.indexOf(el)) !== -1) arr.splice(index, 1);
|
|
74
|
+
return arr;
|
|
75
|
+
}
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
/** Only have it once in the set */
|
|
79
|
+
/**
|
|
80
|
+
* Ensure `el` exists in `arr`. If not present, push it and return the array.
|
|
81
|
+
* @typeParam T - element type
|
|
82
|
+
* @param arr - target array
|
|
83
|
+
* @param el - element to ensure
|
|
84
|
+
* @returns the same array instance (modified if `el` was added)
|
|
85
|
+
*/
|
|
86
|
+
function arraySetElement(arr, el) {
|
|
87
|
+
if (!arr.includes(el)) arr.push(el);
|
|
88
|
+
return arr;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Filter an array in-place using `fn` and return the same array instance.
|
|
92
|
+
* This replaces the array contents with the filtered result.
|
|
93
|
+
* @typeParam T - element type
|
|
94
|
+
* @param arr - array to filter in-place
|
|
95
|
+
* @param fn - predicate to determine which elements to keep
|
|
96
|
+
* @returns the same array instance after filtering
|
|
97
|
+
*/
|
|
98
|
+
function arrayFilterInPlace(arr, fn) {
|
|
99
|
+
arr.splice(0, arr.length, ...arr.filter(fn));
|
|
100
|
+
return arr;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Toggle presence of `el` in `array` in-place: remove if present, add if missing.
|
|
104
|
+
* @typeParam T - element type
|
|
105
|
+
* @param arr - array to modify
|
|
106
|
+
* @param el - element to toggle
|
|
107
|
+
* @returns the same array instance after the toggle
|
|
108
|
+
*/
|
|
109
|
+
function arrayToggleInPlace(arr, el) {
|
|
110
|
+
const index = arr.findIndex((e) => e === el);
|
|
111
|
+
if (index >= 0) arr.splice(index, 1);
|
|
112
|
+
else arr.push(el);
|
|
113
|
+
return arr;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Empty an array in-place (remove all elements) and return it.
|
|
117
|
+
* @typeParam T - element type
|
|
118
|
+
*/
|
|
119
|
+
function arrayEmptyInPlace(arr) {
|
|
120
|
+
arr.splice(0, arr.length);
|
|
121
|
+
return arr;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Replace the contents of `array` in-place with `newContent` and return it.
|
|
125
|
+
* @typeParam T - element type
|
|
126
|
+
* @param arr - target array to overwrite
|
|
127
|
+
* @param newContent - new contents to set
|
|
128
|
+
* @returns the same array instance after replacement
|
|
129
|
+
*/
|
|
130
|
+
function arraySetArrayInPlace(arr, newContent) {
|
|
131
|
+
arr.splice(0, arr.length, ...newContent);
|
|
132
|
+
return arr;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Return a sorted copy of the provided iterable or array-like object.
|
|
136
|
+
* @typeParam T - element type
|
|
137
|
+
* @param arr - iterable or array-like input
|
|
138
|
+
* @param compareFn - optional compare function (defaults to `cmp`)
|
|
139
|
+
* @returns a new array sorted according to `compareFn`
|
|
140
|
+
*/
|
|
141
|
+
function arraySorted(arr, compareFn = require_common_data_orderby.cmp) {
|
|
142
|
+
return Array.from(arr).sort(compareFn);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Return a new array with numbers sorted in ascending order.
|
|
146
|
+
* @param arr - array of numbers
|
|
147
|
+
* @returns sorted array of numbers
|
|
148
|
+
*/
|
|
149
|
+
function arraySortedNumbers(arr) {
|
|
150
|
+
return arraySorted(arr, (l, r) => l - r);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Check strict equality of two arrays by length and element-wise === comparison.
|
|
154
|
+
* @typeParam T - element type
|
|
155
|
+
* @param array1 - first array
|
|
156
|
+
* @param array2 - second array
|
|
157
|
+
* @returns `true` if arrays are same length and all elements strictly equal
|
|
158
|
+
*/
|
|
159
|
+
function arrayIsEqual(array1, array2) {
|
|
160
|
+
return array1.length === array2.length && array1.every((value, index) => value === array2[index]);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Shuffle an array in-place using a secure random source if available.
|
|
164
|
+
* Note: uses Array.sort with random comparator which is sufficient for many cases but
|
|
165
|
+
* not perfectly uniform. Returns the same mutated array.
|
|
166
|
+
* @typeParam T - element type
|
|
167
|
+
* @param array - array to shuffle in-place
|
|
168
|
+
* @returns the shuffled array (same instance)
|
|
169
|
+
*/
|
|
170
|
+
function arrayShuffleInPlace(arr) {
|
|
171
|
+
arr.sort(() => require_common_data_math.getSecureRandomIfPossible() > .5 ? 1 : -1);
|
|
172
|
+
return arr;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Return a shuffled copy of `array` (original array is not modified).
|
|
176
|
+
* @typeParam T - element type
|
|
177
|
+
* @param array - input array
|
|
178
|
+
* @returns a new shuffled array
|
|
179
|
+
*/
|
|
180
|
+
function arrayShuffle(arr) {
|
|
181
|
+
return arrayShuffleInPlace(Array.from(arr));
|
|
182
|
+
}
|
|
183
|
+
/** Randomly shuffle the order of the array's elements. Force to have a different order if array has more than one element. */
|
|
184
|
+
/**
|
|
185
|
+
* Shuffle `array` and ensure the returned order differs from the original when possible.
|
|
186
|
+
* If array length is 0 or 1 it is returned unchanged.
|
|
187
|
+
* @typeParam T - element type
|
|
188
|
+
* @param array - input array
|
|
189
|
+
* @returns a shuffled array that's different from the input when feasible
|
|
190
|
+
*/
|
|
191
|
+
function arrayShuffleForce(arr) {
|
|
192
|
+
while (arr.length > 1) {
|
|
193
|
+
const copy = Array.from(arr);
|
|
194
|
+
arrayShuffleInPlace(copy);
|
|
195
|
+
if (!arrayIsEqual(arr, copy)) return copy;
|
|
196
|
+
}
|
|
197
|
+
return arr;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Return a random element from `array` using a secure random source if available.
|
|
201
|
+
* @typeParam T - element type
|
|
202
|
+
* @param array - input array (must be non-empty)
|
|
203
|
+
* @returns a randomly selected element
|
|
204
|
+
*/
|
|
205
|
+
function arrayRandomElement(arr) {
|
|
206
|
+
return arr[Math.floor(require_common_data_math.getSecureRandomIfPossible() * arr.length)];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Return the maximum value from one or more nested arrays.
|
|
210
|
+
* Uses the `>` operator for comparison.
|
|
211
|
+
* @typeParam T - element type (should support `>` comparison)
|
|
212
|
+
* @param arrays - nested arrays to search
|
|
213
|
+
* @returns the maximum value or `undefined` if no elements present
|
|
214
|
+
*/
|
|
215
|
+
function arrayMax(...arrays) {
|
|
216
|
+
return arrayFlatten(...arrays).reduce((acc, value) => acc != null ? value > acc ? value : acc : value, void 0);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Return the minimum value from one or more nested arrays.
|
|
220
|
+
* Uses the `<` operator for comparison.
|
|
221
|
+
* @typeParam T - element type (should support `<` comparison)
|
|
222
|
+
* @param arrays - nested arrays to search
|
|
223
|
+
* @returns the minimum value or `undefined` if no elements present
|
|
224
|
+
*/
|
|
225
|
+
function arrayMin(...arrays) {
|
|
226
|
+
return arrayFlatten(...arrays).reduce((acc, value) => acc != null ? value < acc ? value : acc : value, void 0);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Sum all numbers in one or more nested arrays.
|
|
230
|
+
* @param arrays - nested arrays of numbers
|
|
231
|
+
* @returns the numeric sum (0 for empty input)
|
|
232
|
+
*/
|
|
233
|
+
function arraySum(...arrays) {
|
|
234
|
+
return arrayFlatten(...arrays).reduce((acc, value) => acc + value, 0);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Compute the average of numbers across one or more nested arrays.
|
|
238
|
+
* @param arrays - nested arrays of numbers
|
|
239
|
+
* @returns arithmetic mean (NaN if there are no elements)
|
|
240
|
+
*/
|
|
241
|
+
function arrayAvg(...arrays) {
|
|
242
|
+
const flatArray = arrayFlatten(...arrays);
|
|
243
|
+
return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Split an array into chunks of `chunkLength` (last chunk may be smaller).
|
|
247
|
+
* @typeParam T - element type
|
|
248
|
+
* @param arr - input array
|
|
249
|
+
* @param chunkLength - chunk size (positive integer)
|
|
250
|
+
* @returns array of chunk arrays
|
|
251
|
+
*/
|
|
252
|
+
function arrayBatches(arr, chunkLength) {
|
|
253
|
+
const chunks = [];
|
|
254
|
+
let i = 0;
|
|
255
|
+
const n = arr.length;
|
|
256
|
+
while (i < n) chunks.push(arr.slice(i, i += chunkLength));
|
|
257
|
+
return chunks;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Create an array of given `length` filled with `item` or the result of `item(index)`.
|
|
261
|
+
* If `length` is <= 0 an empty array is returned.
|
|
262
|
+
* @typeParam T - element type
|
|
263
|
+
* @param length - desired length of the array
|
|
264
|
+
* @param item - value to fill or a function producing a value per index
|
|
265
|
+
* @returns newly created array of length `length`
|
|
266
|
+
*/
|
|
267
|
+
function createArray(length = 0, item) {
|
|
268
|
+
if (length <= 0) return [];
|
|
269
|
+
const arr = Array.from({ length });
|
|
270
|
+
for (let i = 0; i < length; i++) arr[i] = item instanceof Function ? item(i) : item;
|
|
271
|
+
return arr;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
//#endregion
|
|
275
|
+
exports.arrayAvg = arrayAvg;
|
|
276
|
+
exports.arrayBatches = arrayBatches;
|
|
277
|
+
exports.arrayEmptyInPlace = arrayEmptyInPlace;
|
|
278
|
+
exports.arrayFilterInPlace = arrayFilterInPlace;
|
|
279
|
+
exports.arrayFlatten = arrayFlatten;
|
|
280
|
+
exports.arrayIntersection = arrayIntersection;
|
|
281
|
+
exports.arrayIsEqual = arrayIsEqual;
|
|
282
|
+
exports.arrayMax = arrayMax;
|
|
283
|
+
exports.arrayMin = arrayMin;
|
|
284
|
+
exports.arrayMinus = arrayMinus;
|
|
285
|
+
exports.arrayRandomElement = arrayRandomElement;
|
|
286
|
+
exports.arrayRemoveElement = arrayRemoveElement;
|
|
287
|
+
exports.arraySetArrayInPlace = arraySetArrayInPlace;
|
|
288
|
+
exports.arraySetElement = arraySetElement;
|
|
289
|
+
exports.arrayShuffle = arrayShuffle;
|
|
290
|
+
exports.arrayShuffleForce = arrayShuffleForce;
|
|
291
|
+
exports.arrayShuffleInPlace = arrayShuffleInPlace;
|
|
292
|
+
exports.arraySorted = arraySorted;
|
|
293
|
+
exports.arraySortedNumbers = arraySortedNumbers;
|
|
294
|
+
exports.arraySum = arraySum;
|
|
295
|
+
exports.arraySymmetricDifference = arraySymmetricDifference;
|
|
296
|
+
exports.arrayToggleInPlace = arrayToggleInPlace;
|
|
297
|
+
exports.arrayUnion = arrayUnion;
|
|
298
|
+
exports.arrayUnique = arrayUnique;
|
|
299
|
+
exports.createArray = createArray;
|
|
2
300
|
//# sourceMappingURL=array.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.cjs","names":["cmp","getSecureRandomIfPossible"],"sources":["../../../src/common/data/array.ts"],"sourcesContent":["/* eslint-disable no-cond-assign */\n\nimport type { NestedArray } from '../types'\nimport { getSecureRandomIfPossible } from './math'\nimport { cmp } from './orderby'\n\n/**\n * Return a new array with duplicate values removed. Maintains first occurrence order.\n * @typeParam T - element type\n * @param arr - input array\n * @returns new array containing unique elements from `arr`\n */\nexport function arrayUnique<T>(arr: T[]): T[] {\n return arr.filter((n: any, index: any) => arr.indexOf(n) === index)\n}\n\n/**\n * Return elements present in `x` but not in `y`.\n * @typeParam T - element type\n * @param left - left-hand array\n * @param right - array of elements to exclude\n * @returns new array with elements from `left` that are not included in `right`\n */\nexport function arrayMinus<T>(left: T[], right: T[]): T[] {\n return arrayUnique(left.filter((n: any) => !right.includes(n)))\n}\n\n/**\n * Return the union of multiple arrays (unique elements across all inputs).\n * @typeParam T - element type\n * @param arrays - arrays to union\n * @returns new array with unique elements from all provided arrays\n */\nexport function arrayUnion<T>(...arrays: T[][]): T[] {\n return arrayUnique(arrays.reduce((acc: T[] = [], value) => acc.concat(value), []))\n}\n\n/** `[1,[2,3]]` becomes `[1,2,3]` */\n/**\n * Flatten nested arrays to a single-level array.\n * Example: `[1, [2, 3]]` becomes `[1, 2, 3]`.\n * @typeParam T - element type\n * @param arrays - one or more nested arrays to flatten\n * @returns flattened array containing all elements\n */\nexport function arrayFlatten<T>(...arrays: NestedArray<T>[]): T[] {\n return (arrays as any).flat(Number.POSITIVE_INFINITY)\n}\n\n/**\n * Return the intersection of two arrays (elements present in both).\n * @typeParam T - element type\n * @param left - first array\n * @param right - second array\n * @returns new array with elements present in both `left` and `right`\n */\nexport function arrayIntersection<T>(left: T[], right: T[]): T[] {\n return arrayUnique<T>(left).filter((n: any) => right.includes(n))\n}\n\n/**\n * Return the symmetric difference between two arrays (elements in either array but not both).\n * @typeParam T - element type\n */\nexport function arraySymmetricDifference<T>(left: T[], right: T[]): T[] {\n return arrayMinus(arrayUnion(left, right), arrayIntersection(left, right))\n // return arrayUnique(x.filter(n => !y.includes(n)).concat(y.filter(n => !x.includes(n))))\n}\n\n// export function arrayApply<T>(fn: any, a: T[]): T[] {\n// return a.reduce(fn, [])\n// }\n\n/**\n * Remove all occurrences of `el` from `arr` in-place and return the mutated array.\n * If `arr` is not an array, returns an empty array.\n * @typeParam T - element type\n * @param arr - array to modify\n * @param el - element to remove\n * @returns the same array instance with `el` removed\n */\nexport function arrayRemoveElement<T>(arr: T[], el: T): T[] {\n if (arr && Array.isArray(arr)) {\n let index\n while ((index = arr.indexOf(el)) !== -1)\n arr.splice(index, 1)\n return arr\n }\n return []\n}\n\n/** Only have it once in the set */\n/**\n * Ensure `el` exists in `arr`. If not present, push it and return the array.\n * @typeParam T - element type\n * @param arr - target array\n * @param el - element to ensure\n * @returns the same array instance (modified if `el` was added)\n */\nexport function arraySetElement<T>(arr: T[], el: T): T[] {\n if (!arr.includes(el))\n arr.push(el)\n return arr\n}\n\n// via https://stackoverflow.com/a/49587869 and Erwin\n/**\n * Filter an array in-place using `fn` and return the same array instance.\n * This replaces the array contents with the filtered result.\n * @typeParam T - element type\n * @param arr - array to filter in-place\n * @param fn - predicate to determine which elements to keep\n * @returns the same array instance after filtering\n */\nexport function arrayFilterInPlace<T>(arr: T[], fn: (el: T) => boolean): T[] {\n arr.splice(0, arr.length, ...arr.filter(fn))\n return arr\n}\n\n// via https://stackoverflow.com/a/49587869 and Erwin\n/**\n * Toggle presence of `el` in `array` in-place: remove if present, add if missing.\n * @typeParam T - element type\n * @param arr - array to modify\n * @param el - element to toggle\n * @returns the same array instance after the toggle\n */\nexport function arrayToggleInPlace<T>(arr: T[], el: T): T[] {\n const index = arr.findIndex(e => e === el)\n if (index >= 0)\n arr.splice(index, 1)\n else arr.push(el)\n return arr\n}\n\n/**\n * Empty an array in-place (remove all elements) and return it.\n * @typeParam T - element type\n */\nexport function arrayEmptyInPlace<T>(arr: T[]): T[] {\n arr.splice(0, arr.length)\n return arr\n}\n\n/**\n * Replace the contents of `array` in-place with `newContent` and return it.\n * @typeParam T - element type\n * @param arr - target array to overwrite\n * @param newContent - new contents to set\n * @returns the same array instance after replacement\n */\nexport function arraySetArrayInPlace<T>(arr: T[], newContent: T[]): T[] {\n arr.splice(0, arr.length, ...newContent)\n return arr\n}\n\n/**\n * Return a sorted copy of the provided iterable or array-like object.\n * @typeParam T - element type\n * @param arr - iterable or array-like input\n * @param compareFn - optional compare function (defaults to `cmp`)\n * @returns a new array sorted according to `compareFn`\n */\nexport function arraySorted<T>(\n arr: Iterable<T> | ArrayLike<T>,\n compareFn: ((a: T, b: T) => number) | undefined = cmp,\n): T[] {\n return Array.from(arr).sort(compareFn)\n}\n\n/**\n * Return a new array with numbers sorted in ascending order.\n * @param arr - array of numbers\n * @returns sorted array of numbers\n */\nexport function arraySortedNumbers(arr: number[]): number[] {\n return arraySorted(arr, (l: number, r: number) => l - r)\n}\n\n/**\n * Check strict equality of two arrays by length and element-wise === comparison.\n * @typeParam T - element type\n * @param array1 - first array\n * @param array2 - second array\n * @returns `true` if arrays are same length and all elements strictly equal\n */\nexport function arrayIsEqual<T>(array1: T[], array2: T[]): boolean {\n return (\n array1.length === array2.length\n && array1.every((value, index) => value === array2[index])\n )\n}\n\n/**\n * Shuffle an array in-place using a secure random source if available.\n * Note: uses Array.sort with random comparator which is sufficient for many cases but\n * not perfectly uniform. Returns the same mutated array.\n * @typeParam T - element type\n * @param array - array to shuffle in-place\n * @returns the shuffled array (same instance)\n */\nexport function arrayShuffleInPlace<T>(arr: T[]): T[] {\n arr.sort(() => (getSecureRandomIfPossible() > 0.5 ? 1 : -1))\n\n // Alternative https://github.com/sindresorhus/array-shuffle/blob/main/index.js#L8\n // for (let index = array.length - 1; index > 0; index--) {\n // const newIndex = Math.floor(Math.random() * (index + 1));\n // [array[index], array[newIndex]] = [array[newIndex], array[index]];\n // }\n\n return arr\n}\n\n/**\n * Return a shuffled copy of `array` (original array is not modified).\n * @typeParam T - element type\n * @param array - input array\n * @returns a new shuffled array\n */\nexport function arrayShuffle<T>(arr: T[]): T[] {\n return arrayShuffleInPlace(Array.from(arr))\n}\n\n/** Randomly shuffle the order of the array's elements. Force to have a different order if array has more than one element. */\n/**\n * Shuffle `array` and ensure the returned order differs from the original when possible.\n * If array length is 0 or 1 it is returned unchanged.\n * @typeParam T - element type\n * @param array - input array\n * @returns a shuffled array that's different from the input when feasible\n */\nexport function arrayShuffleForce<T>(arr: T[]): T[] {\n while (arr.length > 1) {\n const copy = Array.from(arr)\n arrayShuffleInPlace(copy)\n if (!arrayIsEqual(arr, copy))\n return copy\n }\n return arr\n}\n\n/**\n * Return a random element from `array` using a secure random source if available.\n * @typeParam T - element type\n * @param array - input array (must be non-empty)\n * @returns a randomly selected element\n */\nexport function arrayRandomElement<T>(arr: T[]): T {\n return arr[Math.floor(getSecureRandomIfPossible() * arr.length)]\n}\n\n/**\n * Return the maximum value from one or more nested arrays.\n * Uses the `>` operator for comparison.\n * @typeParam T - element type (should support `>` comparison)\n * @param arrays - nested arrays to search\n * @returns the maximum value or `undefined` if no elements present\n */\nexport function arrayMax<T>(...arrays: NestedArray<T>[]): T {\n return arrayFlatten(...arrays).reduce(\n (acc: T, value: T) => (acc != null ? (value > acc ? value : acc) : value),\n undefined as T,\n )\n}\n\n/**\n * Return the minimum value from one or more nested arrays.\n * Uses the `<` operator for comparison.\n * @typeParam T - element type (should support `<` comparison)\n * @param arrays - nested arrays to search\n * @returns the minimum value or `undefined` if no elements present\n */\nexport function arrayMin<T>(...arrays: NestedArray<T>[]): T {\n return arrayFlatten(...arrays).reduce(\n (acc: T, value: T) => (acc != null ? (value < acc ? value : acc) : value),\n undefined as T,\n )\n}\n\n/**\n * Sum all numbers in one or more nested arrays.\n * @param arrays - nested arrays of numbers\n * @returns the numeric sum (0 for empty input)\n */\nexport function arraySum(...arrays: NestedArray<number>[]): number {\n return arrayFlatten(...arrays).reduce((acc, value) => acc + value, 0)\n}\n\n/**\n * Compute the average of numbers across one or more nested arrays.\n * @param arrays - nested arrays of numbers\n * @returns arithmetic mean (NaN if there are no elements)\n */\nexport function arrayAvg(...arrays: NestedArray<number>[]): number {\n const flatArray = arrayFlatten(...arrays)\n return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length\n}\n\n/**\n * Split an array into chunks of `chunkLength` (last chunk may be smaller).\n * @typeParam T - element type\n * @param arr - input array\n * @param chunkLength - chunk size (positive integer)\n * @returns array of chunk arrays\n */\nexport function arrayBatches<T>(arr: T[], chunkLength: number): T[][] {\n const chunks = []\n let i = 0\n const n = arr.length\n while (i < n)\n chunks.push(arr.slice(i, (i += chunkLength)))\n return chunks\n}\n\n/**\n * Create an array of given `length` filled with `item` or the result of `item(index)`.\n * If `length` is <= 0 an empty array is returned.\n * @typeParam T - element type\n * @param length - desired length of the array\n * @param item - value to fill or a function producing a value per index\n * @returns newly created array of length `length`\n */\nexport function createArray<T>(\n length = 0,\n item?: T | ((index: number) => T), // todo remove optional\n): T[] {\n if (length <= 0)\n return []\n const arr: T[] = Array.from({ length })\n for (let i = 0; i < length; i++)\n // @ts-expect-error xxx\n arr[i] = item instanceof Function ? item(i) : item\n return arr\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"array.cjs","names":["cmp","getSecureRandomIfPossible"],"sources":["../../../src/common/data/array.ts"],"sourcesContent":["/* eslint-disable no-cond-assign */\n\nimport type { NestedArray } from '../types'\nimport { getSecureRandomIfPossible } from './math'\nimport { cmp } from './orderby'\n\n/**\n * Return a new array with duplicate values removed. Maintains first occurrence order.\n * @typeParam T - element type\n * @param arr - input array\n * @returns new array containing unique elements from `arr`\n */\nexport function arrayUnique<T>(arr: T[]): T[] {\n return arr.filter((n: any, index: any) => arr.indexOf(n) === index)\n}\n\n/**\n * Return elements present in `x` but not in `y`.\n * @typeParam T - element type\n * @param left - left-hand array\n * @param right - array of elements to exclude\n * @returns new array with elements from `left` that are not included in `right`\n */\nexport function arrayMinus<T>(left: T[], right: T[]): T[] {\n return arrayUnique(left.filter((n: any) => !right.includes(n)))\n}\n\n/**\n * Return the union of multiple arrays (unique elements across all inputs).\n * @typeParam T - element type\n * @param arrays - arrays to union\n * @returns new array with unique elements from all provided arrays\n */\nexport function arrayUnion<T>(...arrays: T[][]): T[] {\n return arrayUnique(arrays.reduce((acc: T[] = [], value) => acc.concat(value), []))\n}\n\n/** `[1,[2,3]]` becomes `[1,2,3]` */\n/**\n * Flatten nested arrays to a single-level array.\n * Example: `[1, [2, 3]]` becomes `[1, 2, 3]`.\n * @typeParam T - element type\n * @param arrays - one or more nested arrays to flatten\n * @returns flattened array containing all elements\n */\nexport function arrayFlatten<T>(...arrays: NestedArray<T>[]): T[] {\n return (arrays as any).flat(Number.POSITIVE_INFINITY)\n}\n\n/**\n * Return the intersection of two arrays (elements present in both).\n * @typeParam T - element type\n * @param left - first array\n * @param right - second array\n * @returns new array with elements present in both `left` and `right`\n */\nexport function arrayIntersection<T>(left: T[], right: T[]): T[] {\n return arrayUnique<T>(left).filter((n: any) => right.includes(n))\n}\n\n/**\n * Return the symmetric difference between two arrays (elements in either array but not both).\n * @typeParam T - element type\n */\nexport function arraySymmetricDifference<T>(left: T[], right: T[]): T[] {\n return arrayMinus(arrayUnion(left, right), arrayIntersection(left, right))\n // return arrayUnique(x.filter(n => !y.includes(n)).concat(y.filter(n => !x.includes(n))))\n}\n\n// export function arrayApply<T>(fn: any, a: T[]): T[] {\n// return a.reduce(fn, [])\n// }\n\n/**\n * Remove all occurrences of `el` from `arr` in-place and return the mutated array.\n * If `arr` is not an array, returns an empty array.\n * @typeParam T - element type\n * @param arr - array to modify\n * @param el - element to remove\n * @returns the same array instance with `el` removed\n */\nexport function arrayRemoveElement<T>(arr: T[], el: T): T[] {\n if (arr && Array.isArray(arr)) {\n let index\n while ((index = arr.indexOf(el)) !== -1)\n arr.splice(index, 1)\n return arr\n }\n return []\n}\n\n/** Only have it once in the set */\n/**\n * Ensure `el` exists in `arr`. If not present, push it and return the array.\n * @typeParam T - element type\n * @param arr - target array\n * @param el - element to ensure\n * @returns the same array instance (modified if `el` was added)\n */\nexport function arraySetElement<T>(arr: T[], el: T): T[] {\n if (!arr.includes(el))\n arr.push(el)\n return arr\n}\n\n// via https://stackoverflow.com/a/49587869 and Erwin\n/**\n * Filter an array in-place using `fn` and return the same array instance.\n * This replaces the array contents with the filtered result.\n * @typeParam T - element type\n * @param arr - array to filter in-place\n * @param fn - predicate to determine which elements to keep\n * @returns the same array instance after filtering\n */\nexport function arrayFilterInPlace<T>(arr: T[], fn: (el: T) => boolean): T[] {\n arr.splice(0, arr.length, ...arr.filter(fn))\n return arr\n}\n\n// via https://stackoverflow.com/a/49587869 and Erwin\n/**\n * Toggle presence of `el` in `array` in-place: remove if present, add if missing.\n * @typeParam T - element type\n * @param arr - array to modify\n * @param el - element to toggle\n * @returns the same array instance after the toggle\n */\nexport function arrayToggleInPlace<T>(arr: T[], el: T): T[] {\n const index = arr.findIndex(e => e === el)\n if (index >= 0)\n arr.splice(index, 1)\n else arr.push(el)\n return arr\n}\n\n/**\n * Empty an array in-place (remove all elements) and return it.\n * @typeParam T - element type\n */\nexport function arrayEmptyInPlace<T>(arr: T[]): T[] {\n arr.splice(0, arr.length)\n return arr\n}\n\n/**\n * Replace the contents of `array` in-place with `newContent` and return it.\n * @typeParam T - element type\n * @param arr - target array to overwrite\n * @param newContent - new contents to set\n * @returns the same array instance after replacement\n */\nexport function arraySetArrayInPlace<T>(arr: T[], newContent: T[]): T[] {\n arr.splice(0, arr.length, ...newContent)\n return arr\n}\n\n/**\n * Return a sorted copy of the provided iterable or array-like object.\n * @typeParam T - element type\n * @param arr - iterable or array-like input\n * @param compareFn - optional compare function (defaults to `cmp`)\n * @returns a new array sorted according to `compareFn`\n */\nexport function arraySorted<T>(\n arr: Iterable<T> | ArrayLike<T>,\n compareFn: ((a: T, b: T) => number) | undefined = cmp,\n): T[] {\n return Array.from(arr).sort(compareFn)\n}\n\n/**\n * Return a new array with numbers sorted in ascending order.\n * @param arr - array of numbers\n * @returns sorted array of numbers\n */\nexport function arraySortedNumbers(arr: number[]): number[] {\n return arraySorted(arr, (l: number, r: number) => l - r)\n}\n\n/**\n * Check strict equality of two arrays by length and element-wise === comparison.\n * @typeParam T - element type\n * @param array1 - first array\n * @param array2 - second array\n * @returns `true` if arrays are same length and all elements strictly equal\n */\nexport function arrayIsEqual<T>(array1: T[], array2: T[]): boolean {\n return (\n array1.length === array2.length\n && array1.every((value, index) => value === array2[index])\n )\n}\n\n/**\n * Shuffle an array in-place using a secure random source if available.\n * Note: uses Array.sort with random comparator which is sufficient for many cases but\n * not perfectly uniform. Returns the same mutated array.\n * @typeParam T - element type\n * @param array - array to shuffle in-place\n * @returns the shuffled array (same instance)\n */\nexport function arrayShuffleInPlace<T>(arr: T[]): T[] {\n arr.sort(() => (getSecureRandomIfPossible() > 0.5 ? 1 : -1))\n\n // Alternative https://github.com/sindresorhus/array-shuffle/blob/main/index.js#L8\n // for (let index = array.length - 1; index > 0; index--) {\n // const newIndex = Math.floor(Math.random() * (index + 1));\n // [array[index], array[newIndex]] = [array[newIndex], array[index]];\n // }\n\n return arr\n}\n\n/**\n * Return a shuffled copy of `array` (original array is not modified).\n * @typeParam T - element type\n * @param array - input array\n * @returns a new shuffled array\n */\nexport function arrayShuffle<T>(arr: T[]): T[] {\n return arrayShuffleInPlace(Array.from(arr))\n}\n\n/** Randomly shuffle the order of the array's elements. Force to have a different order if array has more than one element. */\n/**\n * Shuffle `array` and ensure the returned order differs from the original when possible.\n * If array length is 0 or 1 it is returned unchanged.\n * @typeParam T - element type\n * @param array - input array\n * @returns a shuffled array that's different from the input when feasible\n */\nexport function arrayShuffleForce<T>(arr: T[]): T[] {\n while (arr.length > 1) {\n const copy = Array.from(arr)\n arrayShuffleInPlace(copy)\n if (!arrayIsEqual(arr, copy))\n return copy\n }\n return arr\n}\n\n/**\n * Return a random element from `array` using a secure random source if available.\n * @typeParam T - element type\n * @param array - input array (must be non-empty)\n * @returns a randomly selected element\n */\nexport function arrayRandomElement<T>(arr: T[]): T {\n return arr[Math.floor(getSecureRandomIfPossible() * arr.length)]\n}\n\n/**\n * Return the maximum value from one or more nested arrays.\n * Uses the `>` operator for comparison.\n * @typeParam T - element type (should support `>` comparison)\n * @param arrays - nested arrays to search\n * @returns the maximum value or `undefined` if no elements present\n */\nexport function arrayMax<T>(...arrays: NestedArray<T>[]): T {\n return arrayFlatten(...arrays).reduce(\n (acc: T, value: T) => (acc != null ? (value > acc ? value : acc) : value),\n undefined as T,\n )\n}\n\n/**\n * Return the minimum value from one or more nested arrays.\n * Uses the `<` operator for comparison.\n * @typeParam T - element type (should support `<` comparison)\n * @param arrays - nested arrays to search\n * @returns the minimum value or `undefined` if no elements present\n */\nexport function arrayMin<T>(...arrays: NestedArray<T>[]): T {\n return arrayFlatten(...arrays).reduce(\n (acc: T, value: T) => (acc != null ? (value < acc ? value : acc) : value),\n undefined as T,\n )\n}\n\n/**\n * Sum all numbers in one or more nested arrays.\n * @param arrays - nested arrays of numbers\n * @returns the numeric sum (0 for empty input)\n */\nexport function arraySum(...arrays: NestedArray<number>[]): number {\n return arrayFlatten(...arrays).reduce((acc, value) => acc + value, 0)\n}\n\n/**\n * Compute the average of numbers across one or more nested arrays.\n * @param arrays - nested arrays of numbers\n * @returns arithmetic mean (NaN if there are no elements)\n */\nexport function arrayAvg(...arrays: NestedArray<number>[]): number {\n const flatArray = arrayFlatten(...arrays)\n return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length\n}\n\n/**\n * Split an array into chunks of `chunkLength` (last chunk may be smaller).\n * @typeParam T - element type\n * @param arr - input array\n * @param chunkLength - chunk size (positive integer)\n * @returns array of chunk arrays\n */\nexport function arrayBatches<T>(arr: T[], chunkLength: number): T[][] {\n const chunks = []\n let i = 0\n const n = arr.length\n while (i < n)\n chunks.push(arr.slice(i, (i += chunkLength)))\n return chunks\n}\n\n/**\n * Create an array of given `length` filled with `item` or the result of `item(index)`.\n * If `length` is <= 0 an empty array is returned.\n * @typeParam T - element type\n * @param length - desired length of the array\n * @param item - value to fill or a function producing a value per index\n * @returns newly created array of length `length`\n */\nexport function createArray<T>(\n length = 0,\n item?: T | ((index: number) => T), // todo remove optional\n): T[] {\n if (length <= 0)\n return []\n const arr: T[] = Array.from({ length })\n for (let i = 0; i < length; i++)\n // @ts-expect-error xxx\n arr[i] = item instanceof Function ? item(i) : item\n return arr\n}\n"],"mappings":"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"}
|
|
@@ -1,2 +1,275 @@
|
|
|
1
|
-
import{getSecureRandomIfPossible
|
|
1
|
+
import { getSecureRandomIfPossible } from "./math.mjs";
|
|
2
|
+
import { cmp } from "./orderby.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/common/data/array.ts
|
|
5
|
+
/**
|
|
6
|
+
* Return a new array with duplicate values removed. Maintains first occurrence order.
|
|
7
|
+
* @typeParam T - element type
|
|
8
|
+
* @param arr - input array
|
|
9
|
+
* @returns new array containing unique elements from `arr`
|
|
10
|
+
*/
|
|
11
|
+
function arrayUnique(arr) {
|
|
12
|
+
return arr.filter((n, index) => arr.indexOf(n) === index);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Return elements present in `x` but not in `y`.
|
|
16
|
+
* @typeParam T - element type
|
|
17
|
+
* @param left - left-hand array
|
|
18
|
+
* @param right - array of elements to exclude
|
|
19
|
+
* @returns new array with elements from `left` that are not included in `right`
|
|
20
|
+
*/
|
|
21
|
+
function arrayMinus(left, right) {
|
|
22
|
+
return arrayUnique(left.filter((n) => !right.includes(n)));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Return the union of multiple arrays (unique elements across all inputs).
|
|
26
|
+
* @typeParam T - element type
|
|
27
|
+
* @param arrays - arrays to union
|
|
28
|
+
* @returns new array with unique elements from all provided arrays
|
|
29
|
+
*/
|
|
30
|
+
function arrayUnion(...arrays) {
|
|
31
|
+
return arrayUnique(arrays.reduce((acc = [], value) => acc.concat(value), []));
|
|
32
|
+
}
|
|
33
|
+
/** `[1,[2,3]]` becomes `[1,2,3]` */
|
|
34
|
+
/**
|
|
35
|
+
* Flatten nested arrays to a single-level array.
|
|
36
|
+
* Example: `[1, [2, 3]]` becomes `[1, 2, 3]`.
|
|
37
|
+
* @typeParam T - element type
|
|
38
|
+
* @param arrays - one or more nested arrays to flatten
|
|
39
|
+
* @returns flattened array containing all elements
|
|
40
|
+
*/
|
|
41
|
+
function arrayFlatten(...arrays) {
|
|
42
|
+
return arrays.flat(Number.POSITIVE_INFINITY);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Return the intersection of two arrays (elements present in both).
|
|
46
|
+
* @typeParam T - element type
|
|
47
|
+
* @param left - first array
|
|
48
|
+
* @param right - second array
|
|
49
|
+
* @returns new array with elements present in both `left` and `right`
|
|
50
|
+
*/
|
|
51
|
+
function arrayIntersection(left, right) {
|
|
52
|
+
return arrayUnique(left).filter((n) => right.includes(n));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Return the symmetric difference between two arrays (elements in either array but not both).
|
|
56
|
+
* @typeParam T - element type
|
|
57
|
+
*/
|
|
58
|
+
function arraySymmetricDifference(left, right) {
|
|
59
|
+
return arrayMinus(arrayUnion(left, right), arrayIntersection(left, right));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Remove all occurrences of `el` from `arr` in-place and return the mutated array.
|
|
63
|
+
* If `arr` is not an array, returns an empty array.
|
|
64
|
+
* @typeParam T - element type
|
|
65
|
+
* @param arr - array to modify
|
|
66
|
+
* @param el - element to remove
|
|
67
|
+
* @returns the same array instance with `el` removed
|
|
68
|
+
*/
|
|
69
|
+
function arrayRemoveElement(arr, el) {
|
|
70
|
+
if (arr && Array.isArray(arr)) {
|
|
71
|
+
let index;
|
|
72
|
+
while ((index = arr.indexOf(el)) !== -1) arr.splice(index, 1);
|
|
73
|
+
return arr;
|
|
74
|
+
}
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
/** Only have it once in the set */
|
|
78
|
+
/**
|
|
79
|
+
* Ensure `el` exists in `arr`. If not present, push it and return the array.
|
|
80
|
+
* @typeParam T - element type
|
|
81
|
+
* @param arr - target array
|
|
82
|
+
* @param el - element to ensure
|
|
83
|
+
* @returns the same array instance (modified if `el` was added)
|
|
84
|
+
*/
|
|
85
|
+
function arraySetElement(arr, el) {
|
|
86
|
+
if (!arr.includes(el)) arr.push(el);
|
|
87
|
+
return arr;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Filter an array in-place using `fn` and return the same array instance.
|
|
91
|
+
* This replaces the array contents with the filtered result.
|
|
92
|
+
* @typeParam T - element type
|
|
93
|
+
* @param arr - array to filter in-place
|
|
94
|
+
* @param fn - predicate to determine which elements to keep
|
|
95
|
+
* @returns the same array instance after filtering
|
|
96
|
+
*/
|
|
97
|
+
function arrayFilterInPlace(arr, fn) {
|
|
98
|
+
arr.splice(0, arr.length, ...arr.filter(fn));
|
|
99
|
+
return arr;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Toggle presence of `el` in `array` in-place: remove if present, add if missing.
|
|
103
|
+
* @typeParam T - element type
|
|
104
|
+
* @param arr - array to modify
|
|
105
|
+
* @param el - element to toggle
|
|
106
|
+
* @returns the same array instance after the toggle
|
|
107
|
+
*/
|
|
108
|
+
function arrayToggleInPlace(arr, el) {
|
|
109
|
+
const index = arr.findIndex((e) => e === el);
|
|
110
|
+
if (index >= 0) arr.splice(index, 1);
|
|
111
|
+
else arr.push(el);
|
|
112
|
+
return arr;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Empty an array in-place (remove all elements) and return it.
|
|
116
|
+
* @typeParam T - element type
|
|
117
|
+
*/
|
|
118
|
+
function arrayEmptyInPlace(arr) {
|
|
119
|
+
arr.splice(0, arr.length);
|
|
120
|
+
return arr;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Replace the contents of `array` in-place with `newContent` and return it.
|
|
124
|
+
* @typeParam T - element type
|
|
125
|
+
* @param arr - target array to overwrite
|
|
126
|
+
* @param newContent - new contents to set
|
|
127
|
+
* @returns the same array instance after replacement
|
|
128
|
+
*/
|
|
129
|
+
function arraySetArrayInPlace(arr, newContent) {
|
|
130
|
+
arr.splice(0, arr.length, ...newContent);
|
|
131
|
+
return arr;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Return a sorted copy of the provided iterable or array-like object.
|
|
135
|
+
* @typeParam T - element type
|
|
136
|
+
* @param arr - iterable or array-like input
|
|
137
|
+
* @param compareFn - optional compare function (defaults to `cmp`)
|
|
138
|
+
* @returns a new array sorted according to `compareFn`
|
|
139
|
+
*/
|
|
140
|
+
function arraySorted(arr, compareFn = cmp) {
|
|
141
|
+
return Array.from(arr).sort(compareFn);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Return a new array with numbers sorted in ascending order.
|
|
145
|
+
* @param arr - array of numbers
|
|
146
|
+
* @returns sorted array of numbers
|
|
147
|
+
*/
|
|
148
|
+
function arraySortedNumbers(arr) {
|
|
149
|
+
return arraySorted(arr, (l, r) => l - r);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Check strict equality of two arrays by length and element-wise === comparison.
|
|
153
|
+
* @typeParam T - element type
|
|
154
|
+
* @param array1 - first array
|
|
155
|
+
* @param array2 - second array
|
|
156
|
+
* @returns `true` if arrays are same length and all elements strictly equal
|
|
157
|
+
*/
|
|
158
|
+
function arrayIsEqual(array1, array2) {
|
|
159
|
+
return array1.length === array2.length && array1.every((value, index) => value === array2[index]);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Shuffle an array in-place using a secure random source if available.
|
|
163
|
+
* Note: uses Array.sort with random comparator which is sufficient for many cases but
|
|
164
|
+
* not perfectly uniform. Returns the same mutated array.
|
|
165
|
+
* @typeParam T - element type
|
|
166
|
+
* @param array - array to shuffle in-place
|
|
167
|
+
* @returns the shuffled array (same instance)
|
|
168
|
+
*/
|
|
169
|
+
function arrayShuffleInPlace(arr) {
|
|
170
|
+
arr.sort(() => getSecureRandomIfPossible() > .5 ? 1 : -1);
|
|
171
|
+
return arr;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Return a shuffled copy of `array` (original array is not modified).
|
|
175
|
+
* @typeParam T - element type
|
|
176
|
+
* @param array - input array
|
|
177
|
+
* @returns a new shuffled array
|
|
178
|
+
*/
|
|
179
|
+
function arrayShuffle(arr) {
|
|
180
|
+
return arrayShuffleInPlace(Array.from(arr));
|
|
181
|
+
}
|
|
182
|
+
/** Randomly shuffle the order of the array's elements. Force to have a different order if array has more than one element. */
|
|
183
|
+
/**
|
|
184
|
+
* Shuffle `array` and ensure the returned order differs from the original when possible.
|
|
185
|
+
* If array length is 0 or 1 it is returned unchanged.
|
|
186
|
+
* @typeParam T - element type
|
|
187
|
+
* @param array - input array
|
|
188
|
+
* @returns a shuffled array that's different from the input when feasible
|
|
189
|
+
*/
|
|
190
|
+
function arrayShuffleForce(arr) {
|
|
191
|
+
while (arr.length > 1) {
|
|
192
|
+
const copy = Array.from(arr);
|
|
193
|
+
arrayShuffleInPlace(copy);
|
|
194
|
+
if (!arrayIsEqual(arr, copy)) return copy;
|
|
195
|
+
}
|
|
196
|
+
return arr;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Return a random element from `array` using a secure random source if available.
|
|
200
|
+
* @typeParam T - element type
|
|
201
|
+
* @param array - input array (must be non-empty)
|
|
202
|
+
* @returns a randomly selected element
|
|
203
|
+
*/
|
|
204
|
+
function arrayRandomElement(arr) {
|
|
205
|
+
return arr[Math.floor(getSecureRandomIfPossible() * arr.length)];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Return the maximum value from one or more nested arrays.
|
|
209
|
+
* Uses the `>` operator for comparison.
|
|
210
|
+
* @typeParam T - element type (should support `>` comparison)
|
|
211
|
+
* @param arrays - nested arrays to search
|
|
212
|
+
* @returns the maximum value or `undefined` if no elements present
|
|
213
|
+
*/
|
|
214
|
+
function arrayMax(...arrays) {
|
|
215
|
+
return arrayFlatten(...arrays).reduce((acc, value) => acc != null ? value > acc ? value : acc : value, void 0);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Return the minimum value from one or more nested arrays.
|
|
219
|
+
* Uses the `<` operator for comparison.
|
|
220
|
+
* @typeParam T - element type (should support `<` comparison)
|
|
221
|
+
* @param arrays - nested arrays to search
|
|
222
|
+
* @returns the minimum value or `undefined` if no elements present
|
|
223
|
+
*/
|
|
224
|
+
function arrayMin(...arrays) {
|
|
225
|
+
return arrayFlatten(...arrays).reduce((acc, value) => acc != null ? value < acc ? value : acc : value, void 0);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Sum all numbers in one or more nested arrays.
|
|
229
|
+
* @param arrays - nested arrays of numbers
|
|
230
|
+
* @returns the numeric sum (0 for empty input)
|
|
231
|
+
*/
|
|
232
|
+
function arraySum(...arrays) {
|
|
233
|
+
return arrayFlatten(...arrays).reduce((acc, value) => acc + value, 0);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Compute the average of numbers across one or more nested arrays.
|
|
237
|
+
* @param arrays - nested arrays of numbers
|
|
238
|
+
* @returns arithmetic mean (NaN if there are no elements)
|
|
239
|
+
*/
|
|
240
|
+
function arrayAvg(...arrays) {
|
|
241
|
+
const flatArray = arrayFlatten(...arrays);
|
|
242
|
+
return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Split an array into chunks of `chunkLength` (last chunk may be smaller).
|
|
246
|
+
* @typeParam T - element type
|
|
247
|
+
* @param arr - input array
|
|
248
|
+
* @param chunkLength - chunk size (positive integer)
|
|
249
|
+
* @returns array of chunk arrays
|
|
250
|
+
*/
|
|
251
|
+
function arrayBatches(arr, chunkLength) {
|
|
252
|
+
const chunks = [];
|
|
253
|
+
let i = 0;
|
|
254
|
+
const n = arr.length;
|
|
255
|
+
while (i < n) chunks.push(arr.slice(i, i += chunkLength));
|
|
256
|
+
return chunks;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Create an array of given `length` filled with `item` or the result of `item(index)`.
|
|
260
|
+
* If `length` is <= 0 an empty array is returned.
|
|
261
|
+
* @typeParam T - element type
|
|
262
|
+
* @param length - desired length of the array
|
|
263
|
+
* @param item - value to fill or a function producing a value per index
|
|
264
|
+
* @returns newly created array of length `length`
|
|
265
|
+
*/
|
|
266
|
+
function createArray(length = 0, item) {
|
|
267
|
+
if (length <= 0) return [];
|
|
268
|
+
const arr = Array.from({ length });
|
|
269
|
+
for (let i = 0; i < length; i++) arr[i] = item instanceof Function ? item(i) : item;
|
|
270
|
+
return arr;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
export { arrayAvg, arrayBatches, arrayEmptyInPlace, arrayFilterInPlace, arrayFlatten, arrayIntersection, arrayIsEqual, arrayMax, arrayMin, arrayMinus, arrayRandomElement, arrayRemoveElement, arraySetArrayInPlace, arraySetElement, arrayShuffle, arrayShuffleForce, arrayShuffleInPlace, arraySorted, arraySortedNumbers, arraySum, arraySymmetricDifference, arrayToggleInPlace, arrayUnion, arrayUnique, createArray };
|
|
2
275
|
//# sourceMappingURL=array.mjs.map
|