@kdtlabs/utils 0.0.4 → 0.0.5
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/SKILL.md +7 -9
- package/{common → dist/common}/assertions.d.ts +1 -1
- package/{common → dist/common}/assertions.d.ts.map +1 -1
- package/{common → dist/common}/types.d.ts +1 -1
- package/{common → dist/common}/types.d.ts.map +1 -1
- package/{functions → dist/functions}/executions.d.ts +1 -1
- package/{functions → dist/functions}/executions.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +99 -0
- package/{objects → dist/objects}/transformations.d.ts +1 -1
- package/{objects → dist/objects}/transformations.d.ts.map +1 -1
- package/{objects → dist/objects}/types.d.ts +1 -1
- package/{objects → dist/objects}/types.d.ts.map +1 -1
- package/{promises → dist/promises}/deferred.d.ts +1 -1
- package/{promises → dist/promises}/deferred.d.ts.map +1 -1
- package/{promises → dist/promises}/timers.d.ts +1 -1
- package/{promises → dist/promises}/timers.d.ts.map +1 -1
- package/{serializer → dist/serializer}/context.d.ts +1 -1
- package/{serializer → dist/serializer}/context.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serialize.d.ts +1 -1
- package/{serializer → dist/serializer}/serialize.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serializers/array.d.ts +1 -1
- package/{serializer → dist/serializer}/serializers/array.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serializers/binary.d.ts +1 -1
- package/dist/serializer/serializers/binary.d.ts.map +1 -0
- package/{serializer → dist/serializer}/serializers/blob.d.ts +1 -1
- package/dist/serializer/serializers/blob.d.ts.map +1 -0
- package/{serializer → dist/serializer}/serializers/collection.d.ts +1 -1
- package/{serializer → dist/serializer}/serializers/collection.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serializers/compound.d.ts +1 -1
- package/{serializer → dist/serializer}/serializers/compound.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serializers/error.d.ts +1 -1
- package/{serializer → dist/serializer}/serializers/error.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serializers/function.d.ts +1 -1
- package/{serializer → dist/serializer}/serializers/function.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serializers/leaf-object.d.ts +1 -1
- package/{serializer → dist/serializer}/serializers/leaf-object.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serializers/number.d.ts +1 -1
- package/dist/serializer/serializers/number.d.ts.map +1 -0
- package/{serializer → dist/serializer}/serializers/object.d.ts +1 -1
- package/{serializer → dist/serializer}/serializers/object.d.ts.map +1 -1
- package/{serializer → dist/serializer}/serializers/opaque.d.ts +1 -1
- package/dist/serializer/serializers/opaque.d.ts.map +1 -0
- package/{serializer → dist/serializer}/serializers/primitive.d.ts +1 -1
- package/{serializer → dist/serializer}/serializers/primitive.d.ts.map +1 -1
- package/{serializer → dist/serializer}/types.d.ts +1 -1
- package/{serializer → dist/serializer}/types.d.ts.map +1 -1
- package/{serializer → dist/serializer}/utils.d.ts +1 -1
- package/{serializer → dist/serializer}/utils.d.ts.map +1 -1
- package/{system → dist/system}/fetch.d.ts +2 -2
- package/{system → dist/system}/fetch.d.ts.map +1 -1
- package/dist/system/types.d.ts +3 -0
- package/{system → dist/system}/types.d.ts.map +1 -1
- package/{times → dist/times}/conversions.d.ts +1 -1
- package/{times → dist/times}/conversions.d.ts.map +1 -1
- package/package.json +11 -73
- package/src/arrays/accessors.ts +25 -0
- package/src/arrays/conversions.ts +16 -0
- package/src/arrays/factories.ts +13 -0
- package/src/arrays/guards.ts +7 -0
- package/src/arrays/index.ts +8 -0
- package/src/arrays/operations.ts +103 -0
- package/src/arrays/set-operations.ts +11 -0
- package/src/arrays/types.ts +21 -0
- package/src/buffers/conversions.ts +26 -0
- package/src/buffers/guards.ts +13 -0
- package/src/buffers/index.ts +5 -0
- package/src/buffers/operations.ts +44 -0
- package/src/buffers/types.ts +1 -0
- package/src/collections/fifo-map.ts +33 -0
- package/src/collections/fifo-set.ts +29 -0
- package/src/collections/guards.ts +11 -0
- package/src/collections/index.ts +10 -0
- package/src/collections/linked-base.ts +117 -0
- package/src/collections/linked-map.ts +82 -0
- package/src/collections/linked-set.ts +69 -0
- package/src/collections/lru-map.ts +36 -0
- package/src/collections/lru-set.ts +25 -0
- package/src/collections/types.ts +12 -0
- package/src/common/assertions.ts +11 -0
- package/src/common/guards.ts +58 -0
- package/src/common/index.ts +5 -0
- package/src/common/transformations.ts +20 -0
- package/src/common/types.ts +3 -0
- package/src/core/constants.ts +1 -0
- package/src/core/conversions.ts +9 -0
- package/src/core/guards.ts +57 -0
- package/src/core/index.ts +5 -0
- package/src/core/types.ts +15 -0
- package/src/errors/base-error.ts +48 -0
- package/src/errors/factories.ts +74 -0
- package/src/errors/guards.ts +12 -0
- package/src/errors/index.ts +7 -0
- package/src/errors/operations.ts +15 -0
- package/src/errors/stringify.ts +131 -0
- package/src/errors/types.ts +11 -0
- package/src/events/emitter.ts +117 -0
- package/src/events/index.ts +2 -0
- package/src/events/types.ts +11 -0
- package/src/functions/compositions.ts +17 -0
- package/src/functions/debounce.ts +34 -0
- package/src/functions/executions.ts +12 -0
- package/src/functions/guards.ts +5 -0
- package/src/functions/index.ts +11 -0
- package/src/functions/memoize.ts +33 -0
- package/src/functions/once.ts +33 -0
- package/src/functions/pipe.ts +39 -0
- package/src/functions/throttle.ts +59 -0
- package/src/functions/timer-state.ts +33 -0
- package/src/functions/types.ts +8 -0
- package/src/index.ts +16 -0
- package/src/json-rpc/constants.ts +15 -0
- package/src/json-rpc/factories.ts +22 -0
- package/src/json-rpc/guards.ts +58 -0
- package/src/json-rpc/index.ts +5 -0
- package/src/json-rpc/types.ts +48 -0
- package/src/numbers/bigint-math.ts +163 -0
- package/src/numbers/constants.ts +14 -0
- package/src/numbers/conversions.ts +83 -0
- package/src/numbers/factories.ts +6 -0
- package/src/numbers/formats.ts +52 -0
- package/src/numbers/guards.ts +22 -0
- package/src/numbers/index.ts +10 -0
- package/src/numbers/maths.ts +28 -0
- package/src/numbers/ranges.ts +17 -0
- package/src/numbers/types.ts +7 -0
- package/src/objects/deep-merge.ts +76 -0
- package/src/objects/guards.ts +21 -0
- package/src/objects/index.ts +5 -0
- package/src/objects/transformations.ts +34 -0
- package/src/objects/types.ts +33 -0
- package/src/promises/abortable.ts +37 -0
- package/src/promises/compositions.ts +18 -0
- package/src/promises/deferred.ts +131 -0
- package/src/promises/guards.ts +8 -0
- package/src/promises/index.ts +10 -0
- package/src/promises/pipe.ts +39 -0
- package/src/promises/poll.ts +92 -0
- package/src/promises/retry.ts +138 -0
- package/src/promises/timers.ts +16 -0
- package/src/promises/types.ts +1 -0
- package/src/serializer/constants.ts +5 -0
- package/src/serializer/context.ts +24 -0
- package/src/serializer/index.ts +8 -0
- package/src/serializer/serialize.ts +51 -0
- package/src/serializer/serializers/array.ts +17 -0
- package/src/serializer/serializers/binary.ts +24 -0
- package/src/serializer/serializers/blob.ts +18 -0
- package/src/serializer/serializers/collection.ts +25 -0
- package/src/serializer/serializers/compound.ts +79 -0
- package/src/serializer/serializers/error.ts +75 -0
- package/src/serializer/serializers/function.ts +13 -0
- package/src/serializer/serializers/index.ts +12 -0
- package/src/serializer/serializers/leaf-object.ts +18 -0
- package/src/serializer/serializers/number.ts +14 -0
- package/src/serializer/serializers/object.ts +62 -0
- package/src/serializer/serializers/opaque.ts +36 -0
- package/src/serializer/serializers/primitive.ts +32 -0
- package/src/serializer/symbol-registry.ts +28 -0
- package/src/serializer/types.ts +42 -0
- package/src/serializer/utils.ts +15 -0
- package/src/strings/constants.ts +1 -0
- package/src/strings/factories.ts +9 -0
- package/src/strings/guards.ts +51 -0
- package/src/strings/index.ts +6 -0
- package/src/strings/manipulations.ts +99 -0
- package/src/strings/types.ts +3 -0
- package/src/system/env.ts +32 -0
- package/src/system/fetch.ts +23 -0
- package/src/system/graceful-exit.ts +46 -0
- package/src/system/index.ts +6 -0
- package/src/system/path.ts +12 -0
- package/src/system/types.ts +3 -0
- package/src/times/constants.ts +6 -0
- package/src/times/conversions.ts +85 -0
- package/src/times/factories.ts +3 -0
- package/src/times/guards.ts +3 -0
- package/src/times/index.ts +5 -0
- package/src/times/operations.ts +9 -0
- package/CHANGELOG.md +0 -57
- package/arrays/index.js +0 -4
- package/arrays/index.js.map +0 -9
- package/buffers/index.js +0 -4
- package/buffers/index.js.map +0 -9
- package/chunk-25ja9350.js +0 -4
- package/chunk-25ja9350.js.map +0 -13
- package/chunk-3w6nt7kb.js +0 -4
- package/chunk-3w6nt7kb.js.map +0 -12
- package/chunk-5txwcr6j.js +0 -4
- package/chunk-5txwcr6j.js.map +0 -17
- package/chunk-6dxad51h.js +0 -4
- package/chunk-6dxad51h.js.map +0 -12
- package/chunk-6kdnnxe0.js +0 -4
- package/chunk-6kdnnxe0.js.map +0 -17
- package/chunk-7cndek91.js +0 -4
- package/chunk-7cndek91.js.map +0 -15
- package/chunk-bee0nxse.js +0 -6
- package/chunk-bee0nxse.js.map +0 -14
- package/chunk-bjmntg2y.js +0 -4
- package/chunk-bjmntg2y.js.map +0 -18
- package/chunk-d0d0d285.js +0 -4
- package/chunk-d0d0d285.js.map +0 -26
- package/chunk-jny2gdyy.js +0 -4
- package/chunk-jny2gdyy.js.map +0 -12
- package/chunk-kbzgn0z4.js +0 -4
- package/chunk-kbzgn0z4.js.map +0 -10
- package/chunk-qmbgp0vr.js +0 -4
- package/chunk-qmbgp0vr.js.map +0 -12
- package/chunk-qn6n0ff5.js +0 -4
- package/chunk-qn6n0ff5.js.map +0 -17
- package/chunk-r3maskdb.js +0 -5
- package/chunk-r3maskdb.js.map +0 -13
- package/chunk-st3dxvqt.js +0 -4
- package/chunk-st3dxvqt.js.map +0 -14
- package/chunk-xp18wdk6.js +0 -4
- package/chunk-xp18wdk6.js.map +0 -12
- package/collections/index.js +0 -4
- package/collections/index.js.map +0 -9
- package/common/index.js +0 -4
- package/common/index.js.map +0 -9
- package/core/index.js +0 -4
- package/core/index.js.map +0 -9
- package/errors/index.js +0 -4
- package/errors/index.js.map +0 -9
- package/events/index.js +0 -4
- package/events/index.js.map +0 -9
- package/functions/index.js +0 -4
- package/functions/index.js.map +0 -9
- package/index.js +0 -4
- package/index.js.map +0 -9
- package/json-rpc/index.js +0 -4
- package/json-rpc/index.js.map +0 -9
- package/meta.json +0 -2998
- package/meta.md +0 -1816
- package/numbers/index.js +0 -4
- package/numbers/index.js.map +0 -9
- package/objects/index.js +0 -4
- package/objects/index.js.map +0 -9
- package/promises/index.js +0 -4
- package/promises/index.js.map +0 -9
- package/serializer/index.js +0 -4
- package/serializer/index.js.map +0 -9
- package/serializer/serializers/binary.d.ts.map +0 -1
- package/serializer/serializers/blob.d.ts.map +0 -1
- package/serializer/serializers/number.d.ts.map +0 -1
- package/serializer/serializers/opaque.d.ts.map +0 -1
- package/strings/index.js +0 -4
- package/strings/index.js.map +0 -9
- package/system/index.js +0 -4
- package/system/index.js.map +0 -9
- package/system/types.d.ts +0 -3
- package/times/index.js +0 -4
- package/times/index.js.map +0 -9
- /package/{arrays → dist/arrays}/accessors.d.ts +0 -0
- /package/{arrays → dist/arrays}/accessors.d.ts.map +0 -0
- /package/{arrays → dist/arrays}/conversions.d.ts +0 -0
- /package/{arrays → dist/arrays}/conversions.d.ts.map +0 -0
- /package/{arrays → dist/arrays}/factories.d.ts +0 -0
- /package/{arrays → dist/arrays}/factories.d.ts.map +0 -0
- /package/{arrays → dist/arrays}/guards.d.ts +0 -0
- /package/{arrays → dist/arrays}/guards.d.ts.map +0 -0
- /package/{arrays → dist/arrays}/index.d.ts +0 -0
- /package/{arrays → dist/arrays}/index.d.ts.map +0 -0
- /package/{arrays → dist/arrays}/operations.d.ts +0 -0
- /package/{arrays → dist/arrays}/operations.d.ts.map +0 -0
- /package/{arrays → dist/arrays}/set-operations.d.ts +0 -0
- /package/{arrays → dist/arrays}/set-operations.d.ts.map +0 -0
- /package/{arrays → dist/arrays}/types.d.ts +0 -0
- /package/{arrays → dist/arrays}/types.d.ts.map +0 -0
- /package/{buffers → dist/buffers}/conversions.d.ts +0 -0
- /package/{buffers → dist/buffers}/conversions.d.ts.map +0 -0
- /package/{buffers → dist/buffers}/guards.d.ts +0 -0
- /package/{buffers → dist/buffers}/guards.d.ts.map +0 -0
- /package/{buffers → dist/buffers}/index.d.ts +0 -0
- /package/{buffers → dist/buffers}/index.d.ts.map +0 -0
- /package/{buffers → dist/buffers}/operations.d.ts +0 -0
- /package/{buffers → dist/buffers}/operations.d.ts.map +0 -0
- /package/{buffers → dist/buffers}/types.d.ts +0 -0
- /package/{buffers → dist/buffers}/types.d.ts.map +0 -0
- /package/{collections → dist/collections}/fifo-map.d.ts +0 -0
- /package/{collections → dist/collections}/fifo-map.d.ts.map +0 -0
- /package/{collections → dist/collections}/fifo-set.d.ts +0 -0
- /package/{collections → dist/collections}/fifo-set.d.ts.map +0 -0
- /package/{collections → dist/collections}/guards.d.ts +0 -0
- /package/{collections → dist/collections}/guards.d.ts.map +0 -0
- /package/{collections → dist/collections}/index.d.ts +0 -0
- /package/{collections → dist/collections}/index.d.ts.map +0 -0
- /package/{collections → dist/collections}/linked-base.d.ts +0 -0
- /package/{collections → dist/collections}/linked-base.d.ts.map +0 -0
- /package/{collections → dist/collections}/linked-map.d.ts +0 -0
- /package/{collections → dist/collections}/linked-map.d.ts.map +0 -0
- /package/{collections → dist/collections}/linked-set.d.ts +0 -0
- /package/{collections → dist/collections}/linked-set.d.ts.map +0 -0
- /package/{collections → dist/collections}/lru-map.d.ts +0 -0
- /package/{collections → dist/collections}/lru-map.d.ts.map +0 -0
- /package/{collections → dist/collections}/lru-set.d.ts +0 -0
- /package/{collections → dist/collections}/lru-set.d.ts.map +0 -0
- /package/{collections → dist/collections}/types.d.ts +0 -0
- /package/{collections → dist/collections}/types.d.ts.map +0 -0
- /package/{common → dist/common}/guards.d.ts +0 -0
- /package/{common → dist/common}/guards.d.ts.map +0 -0
- /package/{common → dist/common}/index.d.ts +0 -0
- /package/{common → dist/common}/index.d.ts.map +0 -0
- /package/{common → dist/common}/transformations.d.ts +0 -0
- /package/{common → dist/common}/transformations.d.ts.map +0 -0
- /package/{core → dist/core}/constants.d.ts +0 -0
- /package/{core → dist/core}/constants.d.ts.map +0 -0
- /package/{core → dist/core}/conversions.d.ts +0 -0
- /package/{core → dist/core}/conversions.d.ts.map +0 -0
- /package/{core → dist/core}/guards.d.ts +0 -0
- /package/{core → dist/core}/guards.d.ts.map +0 -0
- /package/{core → dist/core}/index.d.ts +0 -0
- /package/{core → dist/core}/index.d.ts.map +0 -0
- /package/{core → dist/core}/types.d.ts +0 -0
- /package/{core → dist/core}/types.d.ts.map +0 -0
- /package/{errors → dist/errors}/base-error.d.ts +0 -0
- /package/{errors → dist/errors}/base-error.d.ts.map +0 -0
- /package/{errors → dist/errors}/factories.d.ts +0 -0
- /package/{errors → dist/errors}/factories.d.ts.map +0 -0
- /package/{errors → dist/errors}/guards.d.ts +0 -0
- /package/{errors → dist/errors}/guards.d.ts.map +0 -0
- /package/{errors → dist/errors}/index.d.ts +0 -0
- /package/{errors → dist/errors}/index.d.ts.map +0 -0
- /package/{errors → dist/errors}/operations.d.ts +0 -0
- /package/{errors → dist/errors}/operations.d.ts.map +0 -0
- /package/{errors → dist/errors}/stringify.d.ts +0 -0
- /package/{errors → dist/errors}/stringify.d.ts.map +0 -0
- /package/{errors → dist/errors}/types.d.ts +0 -0
- /package/{errors → dist/errors}/types.d.ts.map +0 -0
- /package/{events → dist/events}/emitter.d.ts +0 -0
- /package/{events → dist/events}/emitter.d.ts.map +0 -0
- /package/{events → dist/events}/index.d.ts +0 -0
- /package/{events → dist/events}/index.d.ts.map +0 -0
- /package/{events → dist/events}/types.d.ts +0 -0
- /package/{events → dist/events}/types.d.ts.map +0 -0
- /package/{functions → dist/functions}/compositions.d.ts +0 -0
- /package/{functions → dist/functions}/compositions.d.ts.map +0 -0
- /package/{functions → dist/functions}/debounce.d.ts +0 -0
- /package/{functions → dist/functions}/debounce.d.ts.map +0 -0
- /package/{functions → dist/functions}/guards.d.ts +0 -0
- /package/{functions → dist/functions}/guards.d.ts.map +0 -0
- /package/{functions → dist/functions}/index.d.ts +0 -0
- /package/{functions → dist/functions}/index.d.ts.map +0 -0
- /package/{functions → dist/functions}/memoize.d.ts +0 -0
- /package/{functions → dist/functions}/memoize.d.ts.map +0 -0
- /package/{functions → dist/functions}/once.d.ts +0 -0
- /package/{functions → dist/functions}/once.d.ts.map +0 -0
- /package/{functions → dist/functions}/pipe.d.ts +0 -0
- /package/{functions → dist/functions}/pipe.d.ts.map +0 -0
- /package/{functions → dist/functions}/throttle.d.ts +0 -0
- /package/{functions → dist/functions}/throttle.d.ts.map +0 -0
- /package/{functions → dist/functions}/timer-state.d.ts +0 -0
- /package/{functions → dist/functions}/timer-state.d.ts.map +0 -0
- /package/{functions → dist/functions}/types.d.ts +0 -0
- /package/{functions → dist/functions}/types.d.ts.map +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.d.ts.map → dist/index.d.ts.map} +0 -0
- /package/{json-rpc → dist/json-rpc}/constants.d.ts +0 -0
- /package/{json-rpc → dist/json-rpc}/constants.d.ts.map +0 -0
- /package/{json-rpc → dist/json-rpc}/factories.d.ts +0 -0
- /package/{json-rpc → dist/json-rpc}/factories.d.ts.map +0 -0
- /package/{json-rpc → dist/json-rpc}/guards.d.ts +0 -0
- /package/{json-rpc → dist/json-rpc}/guards.d.ts.map +0 -0
- /package/{json-rpc → dist/json-rpc}/index.d.ts +0 -0
- /package/{json-rpc → dist/json-rpc}/index.d.ts.map +0 -0
- /package/{json-rpc → dist/json-rpc}/types.d.ts +0 -0
- /package/{json-rpc → dist/json-rpc}/types.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/bigint-math.d.ts +0 -0
- /package/{numbers → dist/numbers}/bigint-math.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/constants.d.ts +0 -0
- /package/{numbers → dist/numbers}/constants.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/conversions.d.ts +0 -0
- /package/{numbers → dist/numbers}/conversions.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/factories.d.ts +0 -0
- /package/{numbers → dist/numbers}/factories.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/formats.d.ts +0 -0
- /package/{numbers → dist/numbers}/formats.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/guards.d.ts +0 -0
- /package/{numbers → dist/numbers}/guards.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/index.d.ts +0 -0
- /package/{numbers → dist/numbers}/index.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/maths.d.ts +0 -0
- /package/{numbers → dist/numbers}/maths.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/ranges.d.ts +0 -0
- /package/{numbers → dist/numbers}/ranges.d.ts.map +0 -0
- /package/{numbers → dist/numbers}/types.d.ts +0 -0
- /package/{numbers → dist/numbers}/types.d.ts.map +0 -0
- /package/{objects → dist/objects}/deep-merge.d.ts +0 -0
- /package/{objects → dist/objects}/deep-merge.d.ts.map +0 -0
- /package/{objects → dist/objects}/guards.d.ts +0 -0
- /package/{objects → dist/objects}/guards.d.ts.map +0 -0
- /package/{objects → dist/objects}/index.d.ts +0 -0
- /package/{objects → dist/objects}/index.d.ts.map +0 -0
- /package/{promises → dist/promises}/abortable.d.ts +0 -0
- /package/{promises → dist/promises}/abortable.d.ts.map +0 -0
- /package/{promises → dist/promises}/compositions.d.ts +0 -0
- /package/{promises → dist/promises}/compositions.d.ts.map +0 -0
- /package/{promises → dist/promises}/guards.d.ts +0 -0
- /package/{promises → dist/promises}/guards.d.ts.map +0 -0
- /package/{promises → dist/promises}/index.d.ts +0 -0
- /package/{promises → dist/promises}/index.d.ts.map +0 -0
- /package/{promises → dist/promises}/pipe.d.ts +0 -0
- /package/{promises → dist/promises}/pipe.d.ts.map +0 -0
- /package/{promises → dist/promises}/poll.d.ts +0 -0
- /package/{promises → dist/promises}/poll.d.ts.map +0 -0
- /package/{promises → dist/promises}/retry.d.ts +0 -0
- /package/{promises → dist/promises}/retry.d.ts.map +0 -0
- /package/{promises → dist/promises}/types.d.ts +0 -0
- /package/{promises → dist/promises}/types.d.ts.map +0 -0
- /package/{serializer → dist/serializer}/constants.d.ts +0 -0
- /package/{serializer → dist/serializer}/constants.d.ts.map +0 -0
- /package/{serializer → dist/serializer}/index.d.ts +0 -0
- /package/{serializer → dist/serializer}/index.d.ts.map +0 -0
- /package/{serializer → dist/serializer}/serializers/index.d.ts +0 -0
- /package/{serializer → dist/serializer}/serializers/index.d.ts.map +0 -0
- /package/{serializer → dist/serializer}/symbol-registry.d.ts +0 -0
- /package/{serializer → dist/serializer}/symbol-registry.d.ts.map +0 -0
- /package/{strings → dist/strings}/constants.d.ts +0 -0
- /package/{strings → dist/strings}/constants.d.ts.map +0 -0
- /package/{strings → dist/strings}/factories.d.ts +0 -0
- /package/{strings → dist/strings}/factories.d.ts.map +0 -0
- /package/{strings → dist/strings}/guards.d.ts +0 -0
- /package/{strings → dist/strings}/guards.d.ts.map +0 -0
- /package/{strings → dist/strings}/index.d.ts +0 -0
- /package/{strings → dist/strings}/index.d.ts.map +0 -0
- /package/{strings → dist/strings}/manipulations.d.ts +0 -0
- /package/{strings → dist/strings}/manipulations.d.ts.map +0 -0
- /package/{strings → dist/strings}/types.d.ts +0 -0
- /package/{strings → dist/strings}/types.d.ts.map +0 -0
- /package/{system → dist/system}/env.d.ts +0 -0
- /package/{system → dist/system}/env.d.ts.map +0 -0
- /package/{system → dist/system}/graceful-exit.d.ts +0 -0
- /package/{system → dist/system}/graceful-exit.d.ts.map +0 -0
- /package/{system → dist/system}/index.d.ts +0 -0
- /package/{system → dist/system}/index.d.ts.map +0 -0
- /package/{system → dist/system}/path.d.ts +0 -0
- /package/{system → dist/system}/path.d.ts.map +0 -0
- /package/{times → dist/times}/constants.d.ts +0 -0
- /package/{times → dist/times}/constants.d.ts.map +0 -0
- /package/{times → dist/times}/factories.d.ts +0 -0
- /package/{times → dist/times}/factories.d.ts.map +0 -0
- /package/{times → dist/times}/guards.d.ts +0 -0
- /package/{times → dist/times}/guards.d.ts.map +0 -0
- /package/{times → dist/times}/index.d.ts +0 -0
- /package/{times → dist/times}/index.d.ts.map +0 -0
- /package/{times → dist/times}/operations.d.ts +0 -0
- /package/{times → dist/times}/operations.d.ts.map +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BufferLike } from './types'
|
|
2
|
+
|
|
3
|
+
export const isBuffer = (value: unknown): value is Buffer => Buffer.isBuffer(value)
|
|
4
|
+
|
|
5
|
+
export const isArrayBuffer = (value: unknown): value is ArrayBuffer => value instanceof ArrayBuffer
|
|
6
|
+
|
|
7
|
+
export const isSharedArrayBuffer = (value: unknown): value is SharedArrayBuffer => value instanceof SharedArrayBuffer
|
|
8
|
+
|
|
9
|
+
export const isArrayBufferView = (value: unknown): value is ArrayBufferView => ArrayBuffer.isView(value)
|
|
10
|
+
|
|
11
|
+
export const isBufferLike = (value: unknown): value is BufferLike => (
|
|
12
|
+
isBuffer(value) || isArrayBuffer(value) || isSharedArrayBuffer(value) || isArrayBufferView(value)
|
|
13
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { BufferLike } from './types'
|
|
2
|
+
import { toUint8Array } from './conversions'
|
|
3
|
+
|
|
4
|
+
export function concatBuffers(buffers: BufferLike[]) {
|
|
5
|
+
if (buffers.length === 0) {
|
|
6
|
+
return new Uint8Array(0)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const normalized = buffers.map(toUint8Array)
|
|
10
|
+
|
|
11
|
+
let totalLength = 0
|
|
12
|
+
let offset = 0
|
|
13
|
+
|
|
14
|
+
for (const buf of normalized) {
|
|
15
|
+
totalLength += buf.byteLength
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const result = new Uint8Array(totalLength)
|
|
19
|
+
|
|
20
|
+
for (const buf of normalized) {
|
|
21
|
+
result.set(buf, offset)
|
|
22
|
+
offset += buf.byteLength
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return result
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function bufferEquals(a: BufferLike, b: BufferLike) {
|
|
29
|
+
if (a === b) {
|
|
30
|
+
return true
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const u8a = toUint8Array(a)
|
|
34
|
+
const u8b = toUint8Array(b)
|
|
35
|
+
|
|
36
|
+
if (u8a.byteLength !== u8b.byteLength) {
|
|
37
|
+
return false
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const bufA = Buffer.from(u8a.buffer, u8a.byteOffset, u8a.byteLength)
|
|
41
|
+
const bufB = Buffer.from(u8b.buffer, u8b.byteOffset, u8b.byteLength)
|
|
42
|
+
|
|
43
|
+
return bufA.equals(bufB)
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type BufferLike = ArrayBuffer | ArrayBufferView | Buffer | SharedArrayBuffer
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LinkedMap } from './linked-map'
|
|
2
|
+
|
|
3
|
+
export class FifoMap<K, V> extends LinkedMap<K, V> {
|
|
4
|
+
public override peekNewest(): [K, V] | undefined {
|
|
5
|
+
return this.tail ? [this.tail.key, this.tail.value] : undefined
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
public override peekOldest(): [K, V] | undefined {
|
|
9
|
+
return this.head ? [this.head.key, this.head.value] : undefined
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public set(key: K, value: V): this {
|
|
13
|
+
const existingNode = this.nodeMap.get(key)
|
|
14
|
+
|
|
15
|
+
if (existingNode) {
|
|
16
|
+
existingNode.value = value
|
|
17
|
+
|
|
18
|
+
return this
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const newNode = this.createNode(key, value)
|
|
22
|
+
|
|
23
|
+
this.nodeMap.set(key, newNode)
|
|
24
|
+
this.addToTail(newNode)
|
|
25
|
+
this.currentSize++
|
|
26
|
+
|
|
27
|
+
if (this.maxSize && this.currentSize > this.maxSize) {
|
|
28
|
+
this.removeHead()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return this
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { LinkedSet } from './linked-set'
|
|
2
|
+
|
|
3
|
+
export class FifoSet<T> extends LinkedSet<T> {
|
|
4
|
+
public add(value: T): this {
|
|
5
|
+
if (this.nodeMap.has(value)) {
|
|
6
|
+
return this
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const newNode = this.createNode(value)
|
|
10
|
+
|
|
11
|
+
this.nodeMap.set(value, newNode)
|
|
12
|
+
this.addToTail(newNode)
|
|
13
|
+
this.currentSize++
|
|
14
|
+
|
|
15
|
+
if (this.maxSize && this.currentSize > this.maxSize) {
|
|
16
|
+
this.removeHead()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return this
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public override peekOldest(): T | undefined {
|
|
23
|
+
return this.head?.value
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public override peekNewest(): T | undefined {
|
|
27
|
+
return this.tail?.value
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CollectionLike, MapLike, SetLike } from './types'
|
|
2
|
+
|
|
3
|
+
export const isIterable = <T>(value: unknown): value is Iterable<T> => value != null && typeof value === 'object' && Symbol.iterator in value && typeof value[Symbol.iterator] === 'function'
|
|
4
|
+
|
|
5
|
+
export const isCollectionLike = <T>(value: unknown): value is CollectionLike<T> => isIterable(value) && 'size' in value && typeof value.size === 'number'
|
|
6
|
+
|
|
7
|
+
export const isEmptyCollection = (value: CollectionLike) => value.size === 0
|
|
8
|
+
|
|
9
|
+
export const isSetLike = <T>(value: unknown): value is SetLike<T> => isCollectionLike(value) && 'has' in value && typeof value.has === 'function'
|
|
10
|
+
|
|
11
|
+
export const isMapLike = <K, V>(value: unknown): value is MapLike<K, V> => isCollectionLike(value) && 'get' in value && typeof value.get === 'function' && 'entries' in value && typeof value.entries === 'function'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './fifo-map'
|
|
2
|
+
export * from './fifo-set'
|
|
3
|
+
export * from './guards'
|
|
4
|
+
export * from './linked-base'
|
|
5
|
+
export * from './linked-map'
|
|
6
|
+
export * from './linked-set'
|
|
7
|
+
export * from './lru-map'
|
|
8
|
+
export * from './lru-set'
|
|
9
|
+
|
|
10
|
+
export type * from './types'
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export interface LinkedBaseNode {
|
|
2
|
+
next: LinkedBaseNode | null
|
|
3
|
+
prev: LinkedBaseNode | null
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export abstract class LinkedBase<NodeKey, N extends LinkedBaseNode> {
|
|
7
|
+
protected readonly nodeMap = new Map<NodeKey, N>()
|
|
8
|
+
|
|
9
|
+
protected currentSize = 0
|
|
10
|
+
protected head: N | null = null
|
|
11
|
+
protected tail: N | null = null
|
|
12
|
+
|
|
13
|
+
public constructor(public readonly maxSize?: number) {
|
|
14
|
+
if (maxSize != null && (maxSize < 1 || !Number.isInteger(maxSize))) {
|
|
15
|
+
throw new RangeError('maxSize must be a positive integer')
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public get size() {
|
|
20
|
+
return this.currentSize
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public get [Symbol.toStringTag]() {
|
|
24
|
+
return this.constructor.name
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public clear() {
|
|
28
|
+
this.nodeMap.clear()
|
|
29
|
+
this.head = null
|
|
30
|
+
this.tail = null
|
|
31
|
+
this.currentSize = 0
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected abstract getNodeKey(node: N): NodeKey
|
|
35
|
+
|
|
36
|
+
protected addToHead(node: N) {
|
|
37
|
+
node.prev = null
|
|
38
|
+
node.next = this.head
|
|
39
|
+
|
|
40
|
+
if (this.head) {
|
|
41
|
+
this.head.prev = node
|
|
42
|
+
} else {
|
|
43
|
+
this.tail = node
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.head = node
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected addToTail(node: N) {
|
|
50
|
+
node.next = null
|
|
51
|
+
node.prev = this.tail
|
|
52
|
+
|
|
53
|
+
if (this.tail) {
|
|
54
|
+
this.tail.next = node
|
|
55
|
+
} else {
|
|
56
|
+
this.head = node
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.tail = node
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected deleteByKey(key: NodeKey) {
|
|
63
|
+
const node = this.nodeMap.get(key)
|
|
64
|
+
|
|
65
|
+
if (!node) {
|
|
66
|
+
return false
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
this.nodeMap.delete(key)
|
|
70
|
+
this.removeNode(node)
|
|
71
|
+
this.currentSize--
|
|
72
|
+
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
protected moveToHead(node: N) {
|
|
77
|
+
this.removeNode(node)
|
|
78
|
+
this.addToHead(node)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected removeHead() {
|
|
82
|
+
if (!this.head) {
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.nodeMap.delete(this.getNodeKey(this.head))
|
|
87
|
+
this.removeNode(this.head)
|
|
88
|
+
this.currentSize--
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected removeNode(node: N) {
|
|
92
|
+
if (node.prev) {
|
|
93
|
+
node.prev.next = node.next
|
|
94
|
+
} else {
|
|
95
|
+
this.head = node.next as N | null
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (node.next) {
|
|
99
|
+
node.next.prev = node.prev
|
|
100
|
+
} else {
|
|
101
|
+
this.tail = node.prev as N | null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
node.prev = null
|
|
105
|
+
node.next = null
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
protected removeTail() {
|
|
109
|
+
if (!this.tail) {
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.nodeMap.delete(this.getNodeKey(this.tail))
|
|
114
|
+
this.removeNode(this.tail)
|
|
115
|
+
this.currentSize--
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { MapLike } from './types'
|
|
2
|
+
import { LinkedBase, type LinkedBaseNode } from './linked-base'
|
|
3
|
+
|
|
4
|
+
export interface LinkedMapNode<K, V> extends LinkedBaseNode {
|
|
5
|
+
key: K
|
|
6
|
+
next: LinkedMapNode<K, V> | null
|
|
7
|
+
prev: LinkedMapNode<K, V> | null
|
|
8
|
+
value: V
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export abstract class LinkedMap<K, V> extends LinkedBase<K, LinkedMapNode<K, V>> implements MapLike<K, V> {
|
|
12
|
+
public delete(key: K) {
|
|
13
|
+
return this.deleteByKey(key)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public * entries(): IterableIterator<[K, V]> {
|
|
17
|
+
let current = this.head
|
|
18
|
+
|
|
19
|
+
while (current) {
|
|
20
|
+
yield [current.key, current.value]
|
|
21
|
+
current = current.next
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public forEach(callback: (value: V, key: K, map: this) => void) {
|
|
26
|
+
for (const [key, value] of this.entries()) {
|
|
27
|
+
callback(value, key, this)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public get(key: K) {
|
|
32
|
+
return this.nodeMap.get(key)?.value
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public has(key: K) {
|
|
36
|
+
return this.nodeMap.has(key)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public * keys(): IterableIterator<K> {
|
|
40
|
+
let current = this.head
|
|
41
|
+
|
|
42
|
+
while (current) {
|
|
43
|
+
yield current.key
|
|
44
|
+
current = current.next
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public peekNewest(): [K, V] | undefined {
|
|
49
|
+
return this.head ? [this.head.key, this.head.value] : undefined
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public peekOldest(): [K, V] | undefined {
|
|
53
|
+
return this.tail ? [this.tail.key, this.tail.value] : undefined
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public abstract set(key: K, value: V): this
|
|
57
|
+
|
|
58
|
+
public [Symbol.iterator](): IterableIterator<[K, V]> {
|
|
59
|
+
return this.entries()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public toJSON(): Array<[K, V]> {
|
|
63
|
+
return [...this.entries()]
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public * values(): IterableIterator<V> {
|
|
67
|
+
let current = this.head
|
|
68
|
+
|
|
69
|
+
while (current) {
|
|
70
|
+
yield current.value
|
|
71
|
+
current = current.next
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected createNode(key: K, value: V): LinkedMapNode<K, V> {
|
|
76
|
+
return { key, next: null, prev: null, value }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected getNodeKey(node: LinkedMapNode<K, V>) {
|
|
80
|
+
return node.key
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { SetLike } from './types'
|
|
2
|
+
import { LinkedBase, type LinkedBaseNode } from './linked-base'
|
|
3
|
+
|
|
4
|
+
export interface LinkedSetNode<T> extends LinkedBaseNode {
|
|
5
|
+
next: LinkedSetNode<T> | null
|
|
6
|
+
prev: LinkedSetNode<T> | null
|
|
7
|
+
value: T
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export abstract class LinkedSet<T> extends LinkedBase<T, LinkedSetNode<T>> implements SetLike<T> {
|
|
11
|
+
public abstract add(value: T): this
|
|
12
|
+
|
|
13
|
+
public delete(value: T) {
|
|
14
|
+
return this.deleteByKey(value)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public * entries(): IterableIterator<[T, T]> {
|
|
18
|
+
for (const value of this.values()) {
|
|
19
|
+
yield [value, value]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public forEach(callback: (value: T, value2: T, set: this) => void) {
|
|
24
|
+
for (const value of this.values()) {
|
|
25
|
+
callback(value, value, this)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public has(value: T) {
|
|
30
|
+
return this.nodeMap.has(value)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public keys() {
|
|
34
|
+
return this.values()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public peekNewest(): T | undefined {
|
|
38
|
+
return this.head?.value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public peekOldest(): T | undefined {
|
|
42
|
+
return this.tail?.value
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public [Symbol.iterator]() {
|
|
46
|
+
return this.values()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public toJSON(): T[] {
|
|
50
|
+
return [...this.values()]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public * values(): IterableIterator<T> {
|
|
54
|
+
let current = this.head
|
|
55
|
+
|
|
56
|
+
while (current) {
|
|
57
|
+
yield current.value
|
|
58
|
+
current = current.next
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
protected createNode(value: T): LinkedSetNode<T> {
|
|
63
|
+
return { next: null, prev: null, value }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
protected getNodeKey(node: LinkedSetNode<T>) {
|
|
67
|
+
return node.value
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { LinkedMap } from './linked-map'
|
|
2
|
+
|
|
3
|
+
export class LruMap<K, V> extends LinkedMap<K, V> {
|
|
4
|
+
public override get(key: K) {
|
|
5
|
+
const node = this.nodeMap.get(key)
|
|
6
|
+
|
|
7
|
+
if (node) {
|
|
8
|
+
this.moveToHead(node)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return node?.value
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public set(key: K, value: V): this {
|
|
15
|
+
const existingNode = this.nodeMap.get(key)
|
|
16
|
+
|
|
17
|
+
if (existingNode) {
|
|
18
|
+
existingNode.value = value
|
|
19
|
+
this.moveToHead(existingNode)
|
|
20
|
+
|
|
21
|
+
return this
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const newNode = this.createNode(key, value)
|
|
25
|
+
|
|
26
|
+
this.nodeMap.set(key, newNode)
|
|
27
|
+
this.addToHead(newNode)
|
|
28
|
+
this.currentSize++
|
|
29
|
+
|
|
30
|
+
if (this.maxSize && this.currentSize > this.maxSize) {
|
|
31
|
+
this.removeTail()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LinkedSet } from './linked-set'
|
|
2
|
+
|
|
3
|
+
export class LruSet<T> extends LinkedSet<T> {
|
|
4
|
+
public add(value: T): this {
|
|
5
|
+
const existingNode = this.nodeMap.get(value)
|
|
6
|
+
|
|
7
|
+
if (existingNode) {
|
|
8
|
+
this.moveToHead(existingNode)
|
|
9
|
+
|
|
10
|
+
return this
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const newNode = this.createNode(value)
|
|
14
|
+
|
|
15
|
+
this.nodeMap.set(value, newNode)
|
|
16
|
+
this.addToHead(newNode)
|
|
17
|
+
this.currentSize++
|
|
18
|
+
|
|
19
|
+
if (this.maxSize && this.currentSize > this.maxSize) {
|
|
20
|
+
this.removeTail()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type CollectionLike<T = unknown> = Iterable<T> & {
|
|
2
|
+
readonly size: number
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export type SetLike<T = unknown> = CollectionLike<T> & {
|
|
6
|
+
has(value: T): boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type MapLike<K = unknown, V = unknown> = CollectionLike<[K, V]> & {
|
|
10
|
+
entries(): Iterable<[K, V]>
|
|
11
|
+
get(key: K): V | undefined
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ensureError, type Errorable, type ErrorCtor } from '../errors'
|
|
2
|
+
|
|
3
|
+
export function assert(condition: unknown, message: Errorable, ctor?: ErrorCtor): asserts condition {
|
|
4
|
+
if (!condition) {
|
|
5
|
+
throw ensureError(message, ctor)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function assertParam(condition: unknown, message: Errorable, ctor?: ErrorCtor): asserts condition {
|
|
10
|
+
assert(condition, message, ctor ?? TypeError)
|
|
11
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isArray, isEmptyArray } from '../arrays'
|
|
2
|
+
import { isCollectionLike, isEmptyCollection } from '../collections'
|
|
3
|
+
import { isNullish, isPrimitive, isString } from '../core'
|
|
4
|
+
import { isEmptyObject, isPlainObject } from '../objects'
|
|
5
|
+
|
|
6
|
+
export function isEmpty(value: unknown) {
|
|
7
|
+
if (isNullish(value)) {
|
|
8
|
+
return true
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (isArray(value)) {
|
|
12
|
+
return isEmptyArray(value)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (isPrimitive(value)) {
|
|
16
|
+
if (isString(value)) {
|
|
17
|
+
return value.length === 0
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (isPlainObject(value)) {
|
|
24
|
+
return isEmptyObject(value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (isCollectionLike(value)) {
|
|
28
|
+
return isEmptyCollection(value)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isDeepEqual(a: unknown, b: unknown): boolean {
|
|
35
|
+
if (a === b) {
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isArray(a) && isArray(b)) {
|
|
40
|
+
if (a.length !== b.length) {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return a.every((item, i) => isDeepEqual(item, b[i]))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
48
|
+
const keysA = Object.keys(a)
|
|
49
|
+
|
|
50
|
+
if (keysA.length !== Object.keys(b).length) {
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return keysA.every((key) => isDeepEqual(a[key], b[key]))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return Object.is(a, b)
|
|
58
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { NullToUndefined } from './types'
|
|
2
|
+
import { isArray } from '../arrays'
|
|
3
|
+
import { isNullish } from '../core'
|
|
4
|
+
import { isPlainObject, map } from '../objects'
|
|
5
|
+
|
|
6
|
+
export function nullToUndefined<T>(value: T): NullToUndefined<T> {
|
|
7
|
+
if (isNullish(value)) {
|
|
8
|
+
return undefined as NullToUndefined<T>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (isArray(value)) {
|
|
12
|
+
return value.map(nullToUndefined) as NullToUndefined<T>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (isPlainObject(value)) {
|
|
16
|
+
return map(value, (k, v) => [k, nullToUndefined(v)]) as NullToUndefined<T>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return value as NullToUndefined<T>
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DEFAULT_TRUE_STRINGS = new Set(['1', 'on', 'true', 'yes'])
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const toString = (value: unknown) => Object.prototype.toString.call(value)
|
|
2
|
+
|
|
3
|
+
export function typeOf(value: unknown): string {
|
|
4
|
+
if (value === null) {
|
|
5
|
+
return 'null'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return typeof value === 'object' || typeof value === 'function' ? toString(value).slice(8, -1).toLowerCase() : typeof value
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { JsonablePrimitive, Primitive } from './types'
|
|
2
|
+
import { DEFAULT_TRUE_STRINGS } from './constants'
|
|
3
|
+
|
|
4
|
+
export const isNull = (value: unknown): value is null => value === null
|
|
5
|
+
export const isUndefined = (value: unknown): value is undefined => value === undefined
|
|
6
|
+
export const isNullish = (value: unknown): value is null | undefined => isNull(value) || isUndefined(value)
|
|
7
|
+
|
|
8
|
+
export const notNull = <T>(value: T): value is Exclude<T, null> => !isNull(value)
|
|
9
|
+
export const notUndefined = <T>(value: T): value is Exclude<T, undefined> => !isUndefined(value)
|
|
10
|
+
export const notNullish = <T>(value: T): value is NonNullable<T> => !isNullish(value)
|
|
11
|
+
|
|
12
|
+
export const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean'
|
|
13
|
+
export const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol'
|
|
14
|
+
export const isBigInt = (value: unknown): value is bigint => typeof value === 'bigint'
|
|
15
|
+
export const isNumber = (value: unknown): value is number => typeof value === 'number'
|
|
16
|
+
export const isString = (value: unknown): value is string => typeof value === 'string'
|
|
17
|
+
export const isDate = (value: unknown): value is Date => value instanceof Date
|
|
18
|
+
|
|
19
|
+
export const isPrimitive = (value: unknown): value is Primitive => value === null || (typeof value !== 'object' && typeof value !== 'function')
|
|
20
|
+
|
|
21
|
+
export const isJsonablePrimitive = (value: unknown): value is JsonablePrimitive => (
|
|
22
|
+
isNull(value) || isString(value) || isBoolean(value) || (isNumber(value) && Number.isFinite(value))
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
export interface IsTrueLikeOptions {
|
|
26
|
+
anyNonZeroNumber?: boolean
|
|
27
|
+
trueStrings?: Set<string>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isTrueLike(value: unknown, options: IsTrueLikeOptions = {}) {
|
|
31
|
+
const { anyNonZeroNumber = false, trueStrings = DEFAULT_TRUE_STRINGS } = options
|
|
32
|
+
|
|
33
|
+
if (isBoolean(value)) {
|
|
34
|
+
return value
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (isString(value)) {
|
|
38
|
+
return trueStrings.has(value.toLowerCase())
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (isNumber(value)) {
|
|
42
|
+
return anyNonZeroNumber ? value !== 0 && Number.isFinite(value) : value === 1
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (isBigInt(value)) {
|
|
46
|
+
return anyNonZeroNumber ? value !== 0n : value === 1n
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const isGenerator = (value: unknown): boolean => (
|
|
53
|
+
typeof value === 'object' &&
|
|
54
|
+
value !== null &&
|
|
55
|
+
typeof (value as Record<PropertyKey, unknown>).next === 'function' &&
|
|
56
|
+
typeof (value as Record<PropertyKey, unknown>)[Symbol.iterator] === 'function'
|
|
57
|
+
)
|