@kdtlabs/utils 0.0.4 → 0.0.6
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 +12 -9
- package/dist/arrays/comparators.d.ts +8 -0
- package/dist/arrays/comparators.d.ts.map +1 -0
- package/{arrays → dist/arrays}/index.d.ts +1 -0
- package/dist/arrays/index.d.ts.map +1 -0
- 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 +14 -0
- package/dist/index.js.map +101 -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/{strings → dist/strings}/index.d.ts +1 -0
- package/{strings → dist/strings}/index.d.ts.map +1 -1
- package/{strings → dist/strings}/manipulations.d.ts +2 -0
- package/{strings → dist/strings}/manipulations.d.ts.map +1 -1
- package/dist/strings/strip-ansi.d.ts +2 -0
- package/dist/strings/strip-ansi.d.ts.map +1 -0
- 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/comparators.ts +53 -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 +9 -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 +7 -0
- package/src/strings/manipulations.ts +145 -0
- package/src/strings/strip-ansi.ts +14 -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.d.ts.map +0 -1
- 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}/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}/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,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
|
+
)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Primitive = bigint | boolean | number | string | symbol | null | undefined
|
|
2
|
+
|
|
3
|
+
export type Optional<T> = T | undefined
|
|
4
|
+
|
|
5
|
+
export type Nullable<T> = T | null
|
|
6
|
+
|
|
7
|
+
export type Nullish<T> = T | null | undefined
|
|
8
|
+
|
|
9
|
+
export type Never<T extends never = never> = T
|
|
10
|
+
|
|
11
|
+
export type IsContainsType<T, U> = Extract<T, U> extends never ? false : true
|
|
12
|
+
|
|
13
|
+
export type JsonablePrimitive = boolean | number | string | null
|
|
14
|
+
|
|
15
|
+
export type Jsonable = Jsonable[] | JsonablePrimitive | { [key: string]: Jsonable }
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type BaseErrorCode = number | string
|
|
2
|
+
|
|
3
|
+
export interface BaseErrorOptions extends ErrorOptions {
|
|
4
|
+
cause?: unknown
|
|
5
|
+
code?: BaseErrorCode
|
|
6
|
+
details?: string
|
|
7
|
+
exitCode?: number
|
|
8
|
+
name?: string
|
|
9
|
+
retryable?: boolean
|
|
10
|
+
timestamp?: Date
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class BaseError extends Error {
|
|
14
|
+
public declare readonly timestamp: Date
|
|
15
|
+
public declare readonly code?: BaseErrorCode
|
|
16
|
+
public declare readonly cause?: unknown
|
|
17
|
+
public declare readonly details?: string
|
|
18
|
+
public declare readonly exitCode?: number
|
|
19
|
+
public declare readonly retryable?: boolean
|
|
20
|
+
|
|
21
|
+
public constructor(message: string, { code, details, exitCode, name, retryable, timestamp, ...options }: BaseErrorOptions = {}) {
|
|
22
|
+
super(message, options)
|
|
23
|
+
|
|
24
|
+
Object.setPrototypeOf(this, new.target.prototype)
|
|
25
|
+
|
|
26
|
+
this.defineValue('name', name ?? this.constructor.name)
|
|
27
|
+
this.defineValue('timestamp', timestamp ?? new Date())
|
|
28
|
+
this.defineValue('cause', options.cause)
|
|
29
|
+
this.defineValue('code', code)
|
|
30
|
+
this.defineValue('details', details)
|
|
31
|
+
this.defineValue('exitCode', exitCode)
|
|
32
|
+
this.defineValue('retryable', retryable)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public withValue<K extends string, V>(key: K, value: V): Record<K, V> & this {
|
|
36
|
+
if (Object.hasOwn(this, key)) {
|
|
37
|
+
throw new TypeError(`Cannot redefine property '${key}' on ${this.name}`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return this.defineValue(key, value) as Record<K, V> & this
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
protected defineValue(key: string, value: unknown) {
|
|
44
|
+
Object.defineProperty(this, key, { configurable: false, enumerable: true, value, writable: false })
|
|
45
|
+
|
|
46
|
+
return this
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { Errorable, ErrorCtor, ErrorLike } from './types'
|
|
2
|
+
import { isString, notNullish } from '../core'
|
|
3
|
+
import { isErrorLike } from './guards'
|
|
4
|
+
|
|
5
|
+
export const createAbortError = (message = 'This operation was aborted', name = 'AbortError') => new DOMException(message, name)
|
|
6
|
+
|
|
7
|
+
export const createTimeoutError = (message = 'The operation was aborted due to a timeout', name = 'TimeoutError') => createAbortError(message, name)
|
|
8
|
+
|
|
9
|
+
export function createAbortController(timeout?: number, timeoutError?: Errorable) {
|
|
10
|
+
const controller = new AbortController()
|
|
11
|
+
|
|
12
|
+
if (notNullish(timeout) && timeout > 0 && timeout <= Number.MAX_SAFE_INTEGER) {
|
|
13
|
+
let timeoutId: NodeJS.Timeout
|
|
14
|
+
|
|
15
|
+
const cleanup = () => {
|
|
16
|
+
clearTimeout(timeoutId)
|
|
17
|
+
controller.signal.removeEventListener('abort', cleanup)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
controller.signal.addEventListener('abort', cleanup)
|
|
21
|
+
timeoutId = setTimeout(() => controller.abort(ensureError(timeoutError ?? createTimeoutError())), timeout)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return controller
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function ensureError(input: Errorable, ctor?: ErrorCtor) {
|
|
28
|
+
if (typeof input === 'string') {
|
|
29
|
+
return ctor ? new ctor(input) : new Error(input)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof input === 'function') {
|
|
33
|
+
return ensureError(input(), ctor)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return input
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function fromErrorLike({ cause, message, name, stack, ...properties }: ErrorLike, ctor?: ErrorCtor) {
|
|
40
|
+
const errorClass = ctor ?? Error
|
|
41
|
+
const error = new errorClass(message, { cause })
|
|
42
|
+
|
|
43
|
+
Object.defineProperty(error, 'name', { configurable: true, enumerable: false, value: name, writable: true })
|
|
44
|
+
Object.defineProperty(error, 'stack', { configurable: true, enumerable: false, value: stack, writable: true })
|
|
45
|
+
|
|
46
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
47
|
+
Object.defineProperty(error, key, Object.getOwnPropertyDescriptor(properties, key) ?? { configurable: true, enumerable: true, value, writable: true })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return error
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface NormalizeErrorOptions {
|
|
54
|
+
defaultMessage?: string
|
|
55
|
+
errorConstructor?: ErrorCtor
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function normalizeError(error: unknown, { defaultMessage = 'Unknown error', errorConstructor }: NormalizeErrorOptions = {}) {
|
|
59
|
+
const errorClass = errorConstructor ?? Error
|
|
60
|
+
|
|
61
|
+
if (error instanceof errorClass) {
|
|
62
|
+
return error
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (isString(error)) {
|
|
66
|
+
return ensureError(error, errorConstructor)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (isErrorLike(error)) {
|
|
70
|
+
return fromErrorLike(error, errorConstructor)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return new errorClass(defaultMessage, { cause: error })
|
|
74
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ErrorLike } from './types'
|
|
2
|
+
import { isString } from '../core'
|
|
3
|
+
import { isKeysOf, isObject } from '../objects'
|
|
4
|
+
import { BaseError } from './base-error'
|
|
5
|
+
|
|
6
|
+
export const isError = (value: unknown): value is Error => value instanceof Error
|
|
7
|
+
|
|
8
|
+
export const isBaseError = (value: unknown): value is BaseError => value instanceof BaseError
|
|
9
|
+
|
|
10
|
+
export const isAbortError = (error: unknown): error is DOMException => error instanceof DOMException && error.name === 'AbortError'
|
|
11
|
+
|
|
12
|
+
export const isErrorLike = (value: unknown): value is ErrorLike => isObject(value) && isKeysOf(value, 'name') && isString(value.name)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { notNullish, type Nullish } from '../core'
|
|
2
|
+
|
|
3
|
+
export function combineSignals(...signals: Array<Nullish<AbortSignal>>) {
|
|
4
|
+
const validSignals = signals.filter(notNullish)
|
|
5
|
+
|
|
6
|
+
if (validSignals.length === 0) {
|
|
7
|
+
return new AbortController().signal
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (validSignals.length === 1) {
|
|
11
|
+
return validSignals[0]!
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return AbortSignal.any(validSignals)
|
|
15
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { isString, notNullish } from '../core'
|
|
2
|
+
import { isObject } from '../objects'
|
|
3
|
+
import { normalizeError, type NormalizeErrorOptions } from './factories'
|
|
4
|
+
|
|
5
|
+
export interface StringifyErrorFormatters {
|
|
6
|
+
code?: (code: string) => string
|
|
7
|
+
message?: (message: string) => string
|
|
8
|
+
name?: (name: string) => string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface StringifyErrorOptions extends NormalizeErrorOptions {
|
|
12
|
+
causeIndent?: number
|
|
13
|
+
causePrefix?: string
|
|
14
|
+
circularReferenceMessage?: string
|
|
15
|
+
formatters?: StringifyErrorFormatters
|
|
16
|
+
includeCause?: boolean
|
|
17
|
+
includeCode?: boolean
|
|
18
|
+
includeName?: boolean
|
|
19
|
+
maxCauseDepth?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_STRINGIFY_FORMATTERS: Required<StringifyErrorFormatters> = {
|
|
23
|
+
code: (value) => `[${value}]`,
|
|
24
|
+
message: (value) => value,
|
|
25
|
+
name: (value) => `${value}:`,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface StringifyErrorState {
|
|
29
|
+
causeIndent: number
|
|
30
|
+
causePrefix: string
|
|
31
|
+
circularReferenceMessage: string
|
|
32
|
+
defaultMessage: string
|
|
33
|
+
formatters: Required<StringifyErrorFormatters>
|
|
34
|
+
includeCause: boolean
|
|
35
|
+
includeCode: boolean
|
|
36
|
+
includeName: boolean
|
|
37
|
+
maxCauseDepth: number
|
|
38
|
+
normalizeOptions: NormalizeErrorOptions
|
|
39
|
+
visited: Set<unknown>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function collectCauses(error: Error, depth: number, indent: string, state: StringifyErrorState) {
|
|
43
|
+
const childIndent = indent + ' '.repeat(state.causeIndent)
|
|
44
|
+
const pointers: string[] = []
|
|
45
|
+
|
|
46
|
+
if (error instanceof AggregateError && error.errors.length > 0) {
|
|
47
|
+
for (const subError of error.errors) {
|
|
48
|
+
pointers.push(stringifyErrorNode(subError, depth - 1, childIndent, state.causePrefix, state))
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isObject(error.cause) || isString(error.cause)) {
|
|
53
|
+
pointers.push(stringifyErrorNode(error.cause, depth - 1, childIndent, state.causePrefix, state))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return pointers
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function appendCauses(parts: string[], error: Error, error_: unknown, depth: number, indent: string, state: StringifyErrorState) {
|
|
60
|
+
if (!state.includeCause || depth <= 0 || (error !== error_ && error.cause === error_)) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const pointers = collectCauses(error, depth, indent, state)
|
|
65
|
+
|
|
66
|
+
if (pointers.length > 0) {
|
|
67
|
+
parts.push(`\n${pointers.join('\n')}`)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function buildErrorParts(error: Error, state: StringifyErrorState) {
|
|
72
|
+
const parts: string[] = []
|
|
73
|
+
|
|
74
|
+
if (state.includeCode && 'code' in error && notNullish(error.code)) {
|
|
75
|
+
parts.push(state.formatters.code(String(error.code)))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (state.includeName) {
|
|
79
|
+
parts.push(state.formatters.name(error.name))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
parts.push(state.formatters.message(error.message || state.defaultMessage))
|
|
83
|
+
|
|
84
|
+
return parts
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function stringifyErrorNode(error_: unknown, depth: number, indent: string, prefix: string, state: StringifyErrorState): string {
|
|
88
|
+
if (state.visited.has(error_)) {
|
|
89
|
+
return `${indent}${prefix}${state.circularReferenceMessage}`
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (error_ instanceof Error) {
|
|
93
|
+
state.visited.add(error_)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (error_ instanceof Error && error_.toString !== Error.prototype.toString) {
|
|
97
|
+
const parts = [error_.toString()]
|
|
98
|
+
appendCauses(parts, error_, error_, depth, indent, state)
|
|
99
|
+
|
|
100
|
+
return indent + prefix + parts.join(' ')
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const error = normalizeError(error_, { ...state.normalizeOptions, defaultMessage: state.defaultMessage })
|
|
104
|
+
|
|
105
|
+
state.visited.add(error)
|
|
106
|
+
|
|
107
|
+
const parts = buildErrorParts(error, state)
|
|
108
|
+
appendCauses(parts, error, error_, depth, indent, state)
|
|
109
|
+
|
|
110
|
+
return indent + prefix + parts.join(' ')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function stringifyError(error: unknown, options: StringifyErrorOptions = {}) {
|
|
114
|
+
const { causeIndent = 2, causePrefix = '-> ', circularReferenceMessage = '[Circular Reference]', defaultMessage = 'Unknown error', formatters: formatters_ = {}, includeCause = true, includeCode = true, includeName = true, maxCauseDepth = Number.POSITIVE_INFINITY, ...normalizeOptions } = options
|
|
115
|
+
|
|
116
|
+
const state: StringifyErrorState = {
|
|
117
|
+
causeIndent,
|
|
118
|
+
causePrefix,
|
|
119
|
+
circularReferenceMessage,
|
|
120
|
+
defaultMessage,
|
|
121
|
+
formatters: { ...DEFAULT_STRINGIFY_FORMATTERS, ...formatters_ },
|
|
122
|
+
includeCause,
|
|
123
|
+
includeCode,
|
|
124
|
+
includeName,
|
|
125
|
+
maxCauseDepth,
|
|
126
|
+
normalizeOptions,
|
|
127
|
+
visited: new Set<unknown>(),
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return stringifyErrorNode(error, maxCauseDepth, '', '', state)
|
|
131
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Errorable = Error | (() => Error | string) | string
|
|
2
|
+
|
|
3
|
+
export type ErrorCtor = new (message?: string, options?: ErrorOptions) => Error
|
|
4
|
+
|
|
5
|
+
export interface ErrorLike {
|
|
6
|
+
[key: string]: unknown
|
|
7
|
+
cause?: unknown
|
|
8
|
+
message?: string
|
|
9
|
+
name: string
|
|
10
|
+
stack?: string
|
|
11
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { EventArgs, EventListener, EventListenerMap, EventMap, EventNames } from './types'
|
|
2
|
+
|
|
3
|
+
export class Emitter<TEventMap = EventMap, TStrict extends boolean = false> {
|
|
4
|
+
protected readonly eventListeners: EventListenerMap
|
|
5
|
+
protected readonly onceListeners: EventListenerMap
|
|
6
|
+
|
|
7
|
+
public constructor() {
|
|
8
|
+
this.eventListeners = new Map()
|
|
9
|
+
this.onceListeners = new Map()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public listeners<TEventName extends EventNames<TEventMap, TStrict>>(eventName: TEventName): Array<EventListener<EventArgs<TEventMap, TEventName, TStrict>>> {
|
|
13
|
+
const listeners = this.eventListeners.get(eventName) ?? []
|
|
14
|
+
const onceListeners = this.onceListeners.get(eventName) ?? []
|
|
15
|
+
|
|
16
|
+
return [...listeners, ...onceListeners]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public listenersCount<TEventName extends EventNames<TEventMap, TStrict>>(eventName: TEventName) {
|
|
20
|
+
const listeners = this.eventListeners.get(eventName)
|
|
21
|
+
const onceListeners = this.onceListeners.get(eventName)
|
|
22
|
+
|
|
23
|
+
return (listeners?.size ?? 0) + (onceListeners?.size ?? 0)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public eventNames(): Array<PropertyKey | keyof TEventMap> {
|
|
27
|
+
return [...new Set([...this.eventListeners.keys(), ...this.onceListeners.keys()])]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public on<TEventName extends EventNames<TEventMap, TStrict>>(eventName: TEventName, listener: EventListener<EventArgs<TEventMap, TEventName, TStrict>>): this {
|
|
31
|
+
this.#addTo(this.eventListeners, eventName, listener)
|
|
32
|
+
|
|
33
|
+
return this
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public once<TEventName extends EventNames<TEventMap, TStrict>>(eventName: TEventName, listener: EventListener<EventArgs<TEventMap, TEventName, TStrict>>): this {
|
|
37
|
+
this.#addTo(this.onceListeners, eventName, listener)
|
|
38
|
+
|
|
39
|
+
return this
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public off<TEventName extends EventNames<TEventMap, TStrict>>(eventName: TEventName, listener: EventListener<EventArgs<TEventMap, TEventName, TStrict>>): this {
|
|
43
|
+
this.#removeFrom(this.eventListeners, eventName, listener)
|
|
44
|
+
this.#removeFrom(this.onceListeners, eventName, listener)
|
|
45
|
+
|
|
46
|
+
return this
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public emit<TEventName extends EventNames<TEventMap, TStrict>>(eventName: TEventName, ...args: EventArgs<TEventMap, TEventName, TStrict>): boolean {
|
|
50
|
+
const regularSnapshot = this.#takeSnapshot(this.eventListeners.get(eventName))
|
|
51
|
+
const onceSnapshot = this.#takeSnapshot(this.onceListeners.get(eventName))
|
|
52
|
+
|
|
53
|
+
this.onceListeners.delete(eventName)
|
|
54
|
+
|
|
55
|
+
const fromRegular = this.#emitSnapshot(regularSnapshot, args)
|
|
56
|
+
const fromOnce = this.#emitSnapshot(onceSnapshot, args)
|
|
57
|
+
|
|
58
|
+
return fromRegular || fromOnce
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public removeAllListeners<TEventName extends EventNames<TEventMap, TStrict>>(eventName?: TEventName): this {
|
|
62
|
+
if (eventName === undefined) {
|
|
63
|
+
this.eventListeners.clear()
|
|
64
|
+
this.onceListeners.clear()
|
|
65
|
+
} else {
|
|
66
|
+
this.eventListeners.delete(eventName)
|
|
67
|
+
this.onceListeners.delete(eventName)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return this
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#addTo(map: EventListenerMap, eventName: PropertyKey, listener: EventListener) {
|
|
74
|
+
let set = map.get(eventName)
|
|
75
|
+
|
|
76
|
+
if (!set) {
|
|
77
|
+
set = new Set()
|
|
78
|
+
map.set(eventName, set)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
set.add(listener)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
#removeFrom(map: EventListenerMap, eventName: PropertyKey, listener: EventListener) {
|
|
85
|
+
const set = map.get(eventName)
|
|
86
|
+
|
|
87
|
+
if (!set) {
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
set.delete(listener)
|
|
92
|
+
|
|
93
|
+
if (set.size === 0) {
|
|
94
|
+
map.delete(eventName)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#takeSnapshot(set: Set<EventListener> | undefined) {
|
|
99
|
+
if (!set || set.size === 0) {
|
|
100
|
+
return []
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return [...set]
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#emitSnapshot(snapshot: EventListener[], args: any[]) {
|
|
107
|
+
if (snapshot.length === 0) {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
for (const listener of snapshot) {
|
|
112
|
+
listener(...args)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return true
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type EventMap = Record<PropertyKey, any[]>
|
|
2
|
+
|
|
3
|
+
export type EventNames<TEventMap, TStrict extends boolean> = TStrict extends true ? keyof TEventMap : keyof TEventMap | string
|
|
4
|
+
|
|
5
|
+
export type ResolveEventArgs<TEventMap, TEventName> = TEventName extends keyof TEventMap ? TEventMap[TEventName] extends any[] ? TEventMap[TEventName] : any[] : any[]
|
|
6
|
+
|
|
7
|
+
export type EventArgs<TEventMap, TEventName, TStrict extends boolean> = TStrict extends true ? TEventName extends keyof TEventMap ? ResolveEventArgs<TEventMap, TEventName> : never : ResolveEventArgs<TEventMap, TEventName>
|
|
8
|
+
|
|
9
|
+
export type EventListener<TArgs = any[]> = (...args: TArgs extends any[] ? TArgs : any[]) => void
|
|
10
|
+
|
|
11
|
+
export type EventListenerMap = Map<PropertyKey, Set<EventListener>>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isFunction } from './guards'
|
|
2
|
+
|
|
3
|
+
export function tap<T>(value: T, callback: (value: T) => void) {
|
|
4
|
+
callback(value)
|
|
5
|
+
|
|
6
|
+
return value
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const transform = <T, R>(value: T, callback: (value: T) => R) => callback(value)
|
|
10
|
+
|
|
11
|
+
export function tryCatch<T>(fn: () => T, fallback: T | ((error: unknown) => T)) {
|
|
12
|
+
try {
|
|
13
|
+
return fn()
|
|
14
|
+
} catch (error) {
|
|
15
|
+
return isFunction(fallback) ? fallback(error) : fallback
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Args, Fn, TimingControlled } from './types'
|
|
2
|
+
import { createTimerState, flushTimer, invokeTimer } from './timer-state'
|
|
3
|
+
|
|
4
|
+
export type Debounced<T extends Fn> = TimingControlled<T>
|
|
5
|
+
|
|
6
|
+
export function debounce<T extends Fn>(fn: T, wait: number): Debounced<T> {
|
|
7
|
+
const state = createTimerState<T>()
|
|
8
|
+
const invoke = () => invokeTimer(state, fn)
|
|
9
|
+
|
|
10
|
+
const debounced: Debounced<T> = function (this: unknown, ...args: Args<T>) {
|
|
11
|
+
state.lastArgs = args
|
|
12
|
+
state.lastThis = this
|
|
13
|
+
|
|
14
|
+
if (state.timeoutId !== undefined) {
|
|
15
|
+
clearTimeout(state.timeoutId)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
state.timeoutId = setTimeout(invoke, wait)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
debounced.cancel = () => {
|
|
22
|
+
if (state.timeoutId !== undefined) {
|
|
23
|
+
clearTimeout(state.timeoutId)
|
|
24
|
+
state.timeoutId = undefined
|
|
25
|
+
state.lastArgs = undefined
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
debounced.flush = () => {
|
|
30
|
+
return flushTimer(state, invoke)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return debounced
|
|
34
|
+
}
|