@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,51 @@
|
|
|
1
|
+
import type { Nullish } from '../core'
|
|
2
|
+
import type { HexString, UrlLike } from './types'
|
|
3
|
+
import { wrap } from '../arrays'
|
|
4
|
+
import { transform, tryCatch } from '../functions'
|
|
5
|
+
|
|
6
|
+
export const isEmptyString = (value: string) => value.length === 0
|
|
7
|
+
|
|
8
|
+
export function isValidProtocol({ protocol }: URL, protocols?: Nullish<string[]>) {
|
|
9
|
+
if (!protocols?.length) {
|
|
10
|
+
return true
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return protocols.some((x) => `${x.toLowerCase()}:` === protocol)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isValidUrl(url: UrlLike, protocols?: Nullish<string[]>) {
|
|
17
|
+
if (url instanceof URL) {
|
|
18
|
+
return isValidProtocol(url, protocols)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return tryCatch(() => isValidProtocol(new URL(url), protocols), false)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const isWebSocketUrl = (url: UrlLike, wsProtocols = ['ws', 'wss']) => isValidUrl(url, wsProtocols)
|
|
25
|
+
|
|
26
|
+
export const isHttpUrl = (url: UrlLike, httpProtocols = ['http', 'https']) => isValidUrl(url, httpProtocols)
|
|
27
|
+
|
|
28
|
+
export const isStringEquals = (str: string, ...others: string[]) => others.length > 0 && others.every((other) => str === other)
|
|
29
|
+
|
|
30
|
+
export const isStringEqualsIgnoreCase = (str: string, ...others: string[]) => (
|
|
31
|
+
others.length > 0 && transform(str.toLowerCase(), (x) => others.every((other) => x === other.toLowerCase()))
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
export const isIncludesAll = (str: string, search: string[]) => search.every((s) => str.includes(s))
|
|
35
|
+
|
|
36
|
+
export const isIncludesAny = (str: string, search: string[]) => search.some((s) => str.includes(s))
|
|
37
|
+
|
|
38
|
+
export const isIncludes = (str: string, search: string[] | string, type: 'all' | 'any' = 'all') => (
|
|
39
|
+
type === 'all' ? isIncludesAll(str, wrap(search)) : isIncludesAny(str, wrap(search))
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
export function isHexString(value: string, length?: number) {
|
|
43
|
+
const len = length ? `{${length * 2}}` : '+'
|
|
44
|
+
const regex = new RegExp(`^(?:0x)?[0-9a-f]${len}$`, 'iu')
|
|
45
|
+
|
|
46
|
+
return regex.test(value)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const isStrictHexString = (value: string, length?: number): value is HexString => (
|
|
50
|
+
value.startsWith('0x') && isHexString(value, length)
|
|
51
|
+
)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { Numberish } from '../numbers'
|
|
2
|
+
import { WHITESPACE_CHARACTERS } from './constants'
|
|
3
|
+
|
|
4
|
+
export const ensurePrefix = (str: string, prefix: string) => (str.startsWith(prefix) ? str : prefix + str)
|
|
5
|
+
|
|
6
|
+
export const ensureSuffix = (str: string, suffix: string) => (str.endsWith(suffix) ? str : str + suffix)
|
|
7
|
+
|
|
8
|
+
export const stripPrefix = (str: string, prefix: string) => (str.startsWith(prefix) ? str.slice(prefix.length) : str)
|
|
9
|
+
|
|
10
|
+
export const stripSuffix = (str: string, suffix: string) => (suffix.length > 0 && str.endsWith(suffix) ? str.slice(0, -suffix.length) : str)
|
|
11
|
+
|
|
12
|
+
export const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1)
|
|
13
|
+
|
|
14
|
+
export const escapeRegExp = (input: string) => (
|
|
15
|
+
input.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw`\$&`).replaceAll('-', String.raw`\x2d`)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
export function * chunkStr(str: string, size: number) {
|
|
19
|
+
if (size <= 0) {
|
|
20
|
+
throw new RangeError(`chunk size must be a positive number, got ${size}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const len = str.length
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < len; i += size) {
|
|
26
|
+
yield str.slice(i, i + size)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const padStart = (str: string, targetLength: number, padString = ' ') => (
|
|
31
|
+
str.padStart(targetLength, padString)
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
export const padZeroStart = (num: Numberish | string, targetLength: number) => padStart(num.toString(), targetLength, '0')
|
|
35
|
+
|
|
36
|
+
export function truncate(str: string, maxLength: number, omission = '...') {
|
|
37
|
+
if (str.length <= maxLength) {
|
|
38
|
+
return str
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (omission.length >= maxLength) {
|
|
42
|
+
return omission.slice(0, maxLength)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return str.slice(0, maxLength - omission.length) + omission
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function truncateMiddle(str: string, maxLength: number, omission = '...') {
|
|
49
|
+
if (str.length <= maxLength) {
|
|
50
|
+
return str
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (omission.length >= maxLength) {
|
|
54
|
+
return omission.slice(0, maxLength)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const left = Math.floor((maxLength - omission.length) / 2)
|
|
58
|
+
const right = maxLength - omission.length - left
|
|
59
|
+
|
|
60
|
+
return str.slice(0, left) + omission + str.slice(-right)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function ltrim(str: string, characters: Set<string> | string = WHITESPACE_CHARACTERS) {
|
|
64
|
+
if (typeof characters === 'string') {
|
|
65
|
+
characters = new Set(characters)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const end = str.length
|
|
69
|
+
|
|
70
|
+
let start = 0
|
|
71
|
+
|
|
72
|
+
while (start < end && characters.has(str[start]!)) {
|
|
73
|
+
start++
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return start > 0 ? str.slice(start, end) : str
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function rtrim(str: string, characters: Set<string> | string = WHITESPACE_CHARACTERS) {
|
|
80
|
+
if (typeof characters === 'string') {
|
|
81
|
+
characters = new Set(characters)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let end = str.length
|
|
85
|
+
|
|
86
|
+
while (end > 0 && characters.has(str[end - 1]!)) {
|
|
87
|
+
end--
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return end < str.length ? str.slice(0, end) : str
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const trim = (str: string, characters: Set<string> | string = WHITESPACE_CHARACTERS) => (
|
|
94
|
+
ltrim(rtrim(str, characters), characters)
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
export const trimRepeated = (input: string, target: string) => (
|
|
98
|
+
input.replaceAll(new RegExp(`(?:${escapeRegExp(target)}){2,}`, 'g'), target)
|
|
99
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isUndefined } from '../core'
|
|
2
|
+
|
|
3
|
+
export const isInMode = (key: string) => process.env.NODE_ENV === key
|
|
4
|
+
|
|
5
|
+
export const isInDevelopment = () => isInMode('development') || isInMode('dev')
|
|
6
|
+
export const isInDev = isInDevelopment
|
|
7
|
+
|
|
8
|
+
export const isInProduction = () => isInMode('production') || isInMode('prod')
|
|
9
|
+
export const isInProd = isInProduction
|
|
10
|
+
|
|
11
|
+
export const isInStaging = () => isInMode('staging') || isInMode('stage')
|
|
12
|
+
export const isInStage = isInStaging
|
|
13
|
+
|
|
14
|
+
export interface GetEnvOptions {
|
|
15
|
+
env?: NodeJS.ProcessEnv
|
|
16
|
+
includeNonePrefix?: boolean
|
|
17
|
+
prefix?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getEnv<T extends string>(key: T[], { env = process.env, includeNonePrefix = false, prefix }: GetEnvOptions = {}) {
|
|
21
|
+
const result: Record<string, string | undefined> = {}
|
|
22
|
+
|
|
23
|
+
for (const k of key) {
|
|
24
|
+
result[k] = env[prefix ? `${prefix}${k}` : k]
|
|
25
|
+
|
|
26
|
+
if (includeNonePrefix && isUndefined(result[k])) {
|
|
27
|
+
result[k] = env[k]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result as Record<T, string | undefined>
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { UrlLike } from '../strings'
|
|
2
|
+
import { combineSignals, createAbortController } from '../errors'
|
|
3
|
+
import { resolveOptions } from '../objects'
|
|
4
|
+
import { withRetry, type WithRetryOptions } from '../promises'
|
|
5
|
+
|
|
6
|
+
export interface FetchOptions extends Omit<RequestInit, 'signal'> {
|
|
7
|
+
retry?: Omit<WithRetryOptions<Response>, 'signal'> & { enabled?: boolean } | boolean
|
|
8
|
+
signal?: AbortSignal
|
|
9
|
+
timeout?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function fetch(request: RequestInfo | UrlLike, { retry = true, signal, timeout = 10_000, ...options }: FetchOptions = {}) {
|
|
13
|
+
const retryOptions = { enabled: true, ...(resolveOptions(retry, {}) || { enabled: false }) }
|
|
14
|
+
|
|
15
|
+
const execute = async (retrySignal?: AbortSignal) => {
|
|
16
|
+
const controller = createAbortController(timeout)
|
|
17
|
+
const fetchSignal = combineSignals(controller.signal, signal, retrySignal)
|
|
18
|
+
|
|
19
|
+
return globalThis.fetch(request, { ...options, signal: fetchSignal }).finally(() => controller.abort())
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return retryOptions.enabled ? await withRetry(execute, { ...retryOptions, signal }) : await execute()
|
|
23
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export type ExitHandler = (exitCode?: number) => Promise<void>
|
|
2
|
+
|
|
3
|
+
const exitTasks = new Map<ExitHandler, number>()
|
|
4
|
+
|
|
5
|
+
export function addExitHandler(handler: ExitHandler, maxWaitTime = 3000) {
|
|
6
|
+
exitTasks.set(handler, maxWaitTime)
|
|
7
|
+
|
|
8
|
+
return () => {
|
|
9
|
+
exitTasks.delete(handler)
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let _isExiting = false
|
|
14
|
+
let _exitPromise: Promise<never> | undefined
|
|
15
|
+
|
|
16
|
+
export const isExiting = () => {
|
|
17
|
+
return _isExiting
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function gracefulExit(exitCode = 0, maxWaitTime = 3000): Promise<never> {
|
|
21
|
+
if (_exitPromise) {
|
|
22
|
+
return _exitPromise
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_isExiting = true
|
|
26
|
+
|
|
27
|
+
if (exitTasks.size === 0) {
|
|
28
|
+
process.exit(exitCode)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const promises: Array<Promise<void>> = []
|
|
32
|
+
|
|
33
|
+
for (const [handler, wait] of exitTasks) {
|
|
34
|
+
promises.push(Promise.resolve().then(() => handler(exitCode)))
|
|
35
|
+
maxWaitTime = Math.max(maxWaitTime, wait)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const timer = setTimeout(() => process.exit(exitCode), maxWaitTime)
|
|
39
|
+
|
|
40
|
+
function finish(): never {
|
|
41
|
+
clearTimeout(timer)
|
|
42
|
+
process.exit(exitCode)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return _exitPromise = Promise.allSettled(promises).then(finish)
|
|
46
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PathLike } from './types'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
import { bufferToString, isBufferLike } from '../buffers'
|
|
5
|
+
|
|
6
|
+
export const pathToString = (path: PathLike) => (
|
|
7
|
+
isBufferLike(path) ? bufferToString(path) : path.toString()
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
export const pwd = (importMeta: ImportMeta, ...path: PathLike[]) => (
|
|
11
|
+
join(dirname(fileURLToPath(importMeta.url)), ...path.map(pathToString))
|
|
12
|
+
)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isString } from '../core'
|
|
2
|
+
import { BigIntMath, isSpecialNumberString, type Numberish } from '../numbers'
|
|
3
|
+
import { padZeroStart } from '../strings'
|
|
4
|
+
|
|
5
|
+
export const toUnixTimestamp = (date: Date) => Math.floor(date.getTime() / 1000)
|
|
6
|
+
|
|
7
|
+
export const fromUnixTimestamp = (timestamp: number) => new Date(timestamp * 1000)
|
|
8
|
+
|
|
9
|
+
const FORMAT_TOKEN_REGEX = /y{4}|S{3}|MM|dd|HH|mm|ss/gu
|
|
10
|
+
const pad2 = (n: number) => padZeroStart(n, 2)
|
|
11
|
+
|
|
12
|
+
export function formatDate(date: Date, format = 'HH:mm:ss.SSS dd/MM/yyyy') {
|
|
13
|
+
if (Number.isNaN(date.getTime())) {
|
|
14
|
+
throw new TypeError('Invalid Date')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const tokens: Record<string, () => string> = {
|
|
18
|
+
dd: () => pad2(date.getDate()),
|
|
19
|
+
HH: () => pad2(date.getHours()),
|
|
20
|
+
MM: () => pad2(date.getMonth() + 1),
|
|
21
|
+
mm: () => pad2(date.getMinutes()),
|
|
22
|
+
ss: () => pad2(date.getSeconds()),
|
|
23
|
+
SSS: () => padZeroStart(date.getMilliseconds(), 3),
|
|
24
|
+
yyyy: () => padZeroStart(date.getFullYear(), 4),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return format.replaceAll(FORMAT_TOKEN_REGEX, (match) => tokens[match]!())
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const NANOSECOND_UNITS: Array<[label: string, value: bigint]> = [
|
|
31
|
+
['h', 3_600_000_000_000n],
|
|
32
|
+
['m', 60_000_000_000n],
|
|
33
|
+
['s', 1_000_000_000n],
|
|
34
|
+
['ms', 1_000_000n],
|
|
35
|
+
['\u03BCs', 1000n],
|
|
36
|
+
['ns', 1n],
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
export function humanizeNanoseconds(ns: Numberish) {
|
|
40
|
+
if (isString(ns) && isSpecialNumberString(ns)) {
|
|
41
|
+
return ns
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let remaining: bigint
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
remaining = BigInt(ns)
|
|
48
|
+
} catch {
|
|
49
|
+
return ns.toString()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (remaining === 0n) {
|
|
53
|
+
return '0ns'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const sign = remaining < 0n ? '-' : ''
|
|
57
|
+
const parts: string[] = []
|
|
58
|
+
|
|
59
|
+
remaining = BigIntMath.abs(remaining)
|
|
60
|
+
|
|
61
|
+
for (const [label, value] of NANOSECOND_UNITS) {
|
|
62
|
+
if (remaining >= value) {
|
|
63
|
+
parts.push(`${remaining / value}${label}`)
|
|
64
|
+
remaining %= value
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return sign + parts.join(' ')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function humanizeWithMultiplier(value: Numberish, multiplier: bigint) {
|
|
72
|
+
if (isString(value) && isSpecialNumberString(value)) {
|
|
73
|
+
return value
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
return humanizeNanoseconds(BigInt(value) * multiplier)
|
|
78
|
+
} catch {
|
|
79
|
+
return value.toString()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const humanizeMilliseconds = (ms: Numberish) => humanizeWithMultiplier(ms, 1_000_000n)
|
|
84
|
+
|
|
85
|
+
export const humanizeSeconds = (s: Numberish) => humanizeWithMultiplier(s, 1_000_000_000n)
|
package/CHANGELOG.md
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
## v0.0.4
|
|
5
|
-
|
|
6
|
-
[compare changes](https://github.com/kdtlabs/utils/compare/v0.0.3...v0.0.4)
|
|
7
|
-
|
|
8
|
-
### 🚀 Enhancements
|
|
9
|
-
|
|
10
|
-
- **common:** Add nullToUndefined util and NullToUndefined type ([fe1f046](https://github.com/kdtlabs/utils/commit/fe1f046))
|
|
11
|
-
- **system:** Implement getEnv with prefix and includeNonePrefix fallback ([15d6da7](https://github.com/kdtlabs/utils/commit/15d6da7))
|
|
12
|
-
- **common:** Add isDeepEqual guard ([e79ac3d](https://github.com/kdtlabs/utils/commit/e79ac3d))
|
|
13
|
-
|
|
14
|
-
### 💅 Refactors
|
|
15
|
-
|
|
16
|
-
- **core:** Move toString and typeOf to core/conversions ([7f2bfa8](https://github.com/kdtlabs/utils/commit/7f2bfa8))
|
|
17
|
-
|
|
18
|
-
### ❤️ Contributors
|
|
19
|
-
|
|
20
|
-
- Diep Dang <kdt310722@gmail.com>
|
|
21
|
-
|
|
22
|
-
## v0.0.3
|
|
23
|
-
|
|
24
|
-
[compare changes](https://github.com/kdtlabs/utils/compare/v0.0.2...v0.0.3)
|
|
25
|
-
|
|
26
|
-
## v0.0.2
|
|
27
|
-
|
|
28
|
-
[compare changes](https://github.com/kdtlabs/utils/compare/v0.0.1...v0.0.2)
|
|
29
|
-
|
|
30
|
-
### 🩹 Fixes
|
|
31
|
-
|
|
32
|
-
- **release:** Build after changelog gen to prevent package.json version error ([459f06c](https://github.com/kdtlabs/utils/commit/459f06c))
|
|
33
|
-
|
|
34
|
-
### ❤️ Contributors
|
|
35
|
-
|
|
36
|
-
- Diep Dang <kdt310722@gmail.com>
|
|
37
|
-
|
|
38
|
-
## v0.0.1
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### 🚀 Enhancements
|
|
42
|
-
|
|
43
|
-
- Add SKILL.md for AI tool discovery of available utils ([e1dde1a](https://github.com/kdtlabs/utils/commit/e1dde1a))
|
|
44
|
-
|
|
45
|
-
### 🩹 Fixes
|
|
46
|
-
|
|
47
|
-
- **release:** Fix release script and add CHANGELOG.md to eslint ignore ([a72208c](https://github.com/kdtlabs/utils/commit/a72208c))
|
|
48
|
-
|
|
49
|
-
### 🏡 Chore
|
|
50
|
-
|
|
51
|
-
- Initial commit ([058e414](https://github.com/kdtlabs/utils/commit/058e414))
|
|
52
|
-
- Add gitnexus to ignore files ([88c2d38](https://github.com/kdtlabs/utils/commit/88c2d38))
|
|
53
|
-
|
|
54
|
-
### ❤️ Contributors
|
|
55
|
-
|
|
56
|
-
- Diep Dang <kdt310722@gmail.com>
|
|
57
|
-
|
package/arrays/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{$b as w,Fb as a,Gb as b,Hb as c,Ib as d,Jb as e,Kb as f,Lb as g,Mb as h,Nb as i,Ob as j,Pb as k,Qb as l,Rb as m,Sb as n,Tb as o,Ub as p,Vb as q,Wb as r,Xb as s,Yb as t,Zb as u,_b as v,ac as x,bc as y}from"../chunk-7cndek91.js";import"../chunk-qn6n0ff5.js";import"../chunk-3w6nt7kb.js";export{g as wrap,v as uniqueBy,u as unique,h as toArray,y as symmetricDiff,s as sortBy,o as shuffle,l as sample,k as range,t as partition,a as nth,m as merge,c as last,q as keyBy,f as isNonEmptyArray,e as isEmptyArray,d as isArray,w as intersection,p as groupBy,n as flatten,b as first,x as diff,j as createArray,i as compact,r as chunk};
|
|
2
|
-
|
|
3
|
-
//# debugId=7FF7885B231E2BF464756E2164756E21
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
package/arrays/index.js.map
DELETED
package/buffers/index.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{gb as a,hb as b,ib as c,jb as d,kb as e,lb as f,mb as g,nb as h,ob as i}from"../chunk-xp18wdk6.js";export{g as toUint8Array,c as isSharedArrayBuffer,e as isBufferLike,a as isBuffer,d as isArrayBufferView,b as isArrayBuffer,h as concatBuffers,f as bufferToString,i as bufferEquals};
|
|
2
|
-
|
|
3
|
-
//# debugId=58E6E050C983599364756E2164756E21
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
package/buffers/index.js.map
DELETED
package/chunk-25ja9350.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{isUndefined as d}from"@/core";var s=(e)=>e==="development",x=()=>s("development")||s("dev"),L=x,g=()=>s("production")||s("prod"),w=g,b=()=>s("staging")||s("stage"),A=b;function H(e,{env:t=process.env,includeNonePrefix:n=!1,prefix:i}={}){let r={};for(let o of e)if(r[o]=t[i?`${i}${o}`:o],n&&d(r[o]))r[o]=t[o];return r}import{combineSignals as h,createAbortController as v}from"@/errors";import{resolveOptions as y}from"@/objects";import{withRetry as P}from"@/promises";async function D(e,{retry:t=!0,signal:n,timeout:i=1e4,...r}={}){let o={enabled:!0,...y(t,{})||{enabled:!1}},p=async(m)=>{let f=v(i),u=h(f.signal,n,m);return globalThis.fetch(e,{...r,signal:u}).finally(()=>f.abort())};return o.enabled?await P(p,{...o,signal:n}):await p()}var a=new Map;function F(e,t=3000){return a.set(e,t),()=>{a.delete(e)}}var l=!1,c,G=()=>{return l};function $(e=0,t=3000){if(c)return c;if(l=!0,a.size===0)process.exit(e);let n=[];for(let[o,p]of a)n.push(Promise.resolve().then(()=>o(e))),t=Math.max(t,p);let i=setTimeout(()=>process.exit(e),t);function r(){clearTimeout(i),process.exit(e)}return c=Promise.allSettled(n).then(r)}import{dirname as E,join as O}from"node:path";import{fileURLToPath as S}from"node:url";import{bufferToString as I,isBufferLike as R}from"@/buffers";var k=(e)=>R(e)?I(e):e.toString(),V=(e,...t)=>O(E(S(e.url)),...t.map(k));export{s as tc,x as uc,L as vc,g as wc,w as xc,b as yc,A as zc,H as Ac,D as Bc,F as Cc,G as Dc,$ as Ec,k as Fc,V as Gc};
|
|
2
|
-
|
|
3
|
-
//# debugId=578EB85944C5459C64756E2164756E21
|
|
4
|
-
//# sourceMappingURL=chunk-25ja9350.js.map
|
package/chunk-25ja9350.js.map
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/system/env.ts", "../src/system/fetch.ts", "../src/system/graceful-exit.ts", "../src/system/path.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { isUndefined } from '@/core'\n\nexport const isInMode = (key: string) => process.env.NODE_ENV === key\n\nexport const isInDevelopment = () => isInMode('development') || isInMode('dev')\nexport const isInDev = isInDevelopment\n\nexport const isInProduction = () => isInMode('production') || isInMode('prod')\nexport const isInProd = isInProduction\n\nexport const isInStaging = () => isInMode('staging') || isInMode('stage')\nexport const isInStage = isInStaging\n\nexport interface GetEnvOptions {\n env?: NodeJS.ProcessEnv\n includeNonePrefix?: boolean\n prefix?: string\n}\n\nexport function getEnv<T extends string>(key: T[], { env = process.env, includeNonePrefix = false, prefix }: GetEnvOptions = {}) {\n const result: Record<string, string | undefined> = {}\n\n for (const k of key) {\n result[k] = env[prefix ? `${prefix}${k}` : k]\n\n if (includeNonePrefix && isUndefined(result[k])) {\n result[k] = env[k]\n }\n }\n\n return result as Record<T, string | undefined>\n}\n",
|
|
6
|
-
"import type { UrlLike } from '@/strings'\nimport { combineSignals, createAbortController } from '@/errors'\nimport { resolveOptions } from '@/objects'\nimport { withRetry, type WithRetryOptions } from '@/promises'\n\nexport interface FetchOptions extends Omit<RequestInit, 'signal'> {\n retry?: Omit<WithRetryOptions<Response>, 'signal'> & { enabled?: boolean } | boolean\n signal?: AbortSignal\n timeout?: number\n}\n\nexport async function fetch(request: RequestInfo | UrlLike, { retry = true, signal, timeout = 10_000, ...options }: FetchOptions = {}) {\n const retryOptions = { enabled: true, ...(resolveOptions(retry, {}) || { enabled: false }) }\n\n const execute = async (retrySignal?: AbortSignal) => {\n const controller = createAbortController(timeout)\n const fetchSignal = combineSignals(controller.signal, signal, retrySignal)\n\n return globalThis.fetch(request, { ...options, signal: fetchSignal }).finally(() => controller.abort())\n }\n\n return retryOptions.enabled ? await withRetry(execute, { ...retryOptions, signal }) : await execute()\n}\n",
|
|
7
|
-
"export type ExitHandler = (exitCode?: number) => Promise<void>\n\nconst exitTasks = new Map<ExitHandler, number>()\n\nexport function addExitHandler(handler: ExitHandler, maxWaitTime = 3000) {\n exitTasks.set(handler, maxWaitTime)\n\n return () => {\n exitTasks.delete(handler)\n }\n}\n\nlet _isExiting = false\nlet _exitPromise: Promise<never> | undefined\n\nexport const isExiting = () => {\n return _isExiting\n}\n\nexport function gracefulExit(exitCode = 0, maxWaitTime = 3000): Promise<never> {\n if (_exitPromise) {\n return _exitPromise\n }\n\n _isExiting = true\n\n if (exitTasks.size === 0) {\n process.exit(exitCode)\n }\n\n const promises: Array<Promise<void>> = []\n\n for (const [handler, wait] of exitTasks) {\n promises.push(Promise.resolve().then(() => handler(exitCode)))\n maxWaitTime = Math.max(maxWaitTime, wait)\n }\n\n const timer = setTimeout(() => process.exit(exitCode), maxWaitTime)\n\n function finish(): never {\n clearTimeout(timer)\n process.exit(exitCode)\n }\n\n return _exitPromise = Promise.allSettled(promises).then(finish)\n}\n",
|
|
8
|
-
"import type { PathLike } from './types'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { bufferToString, isBufferLike } from '@/buffers'\n\nexport const pathToString = (path: PathLike) => (\n isBufferLike(path) ? bufferToString(path) : path.toString()\n)\n\nexport const pwd = (importMeta: ImportMeta, ...path: PathLike[]) => (\n join(dirname(fileURLToPath(importMeta.url)), ...path.map(pathToString))\n)\n"
|
|
9
|
-
],
|
|
10
|
-
"mappings": "AAAA,sBAAS,eAEF,IAAM,EAAW,CAAC,IAAyC,IAAzB,cAE5B,EAAkB,IAAM,EAAS,aAAa,GAAK,EAAS,KAAK,EACjE,EAAU,EAEV,EAAiB,IAAM,EAAS,YAAY,GAAK,EAAS,MAAM,EAChE,EAAW,EAEX,EAAc,IAAM,EAAS,SAAS,GAAK,EAAS,OAAO,EAC3D,EAAY,EAQlB,SAAS,CAAwB,CAAC,GAAY,MAAM,QAAQ,IAAK,oBAAoB,GAAO,UAA0B,CAAC,EAAG,CAC7H,IAAM,EAA6C,CAAC,EAEpD,QAAW,KAAK,EAGZ,GAFA,EAAO,GAAK,EAAI,EAAS,GAAG,IAAS,IAAM,GAEvC,GAAqB,EAAY,EAAO,EAAE,EAC1C,EAAO,GAAK,EAAI,GAIxB,OAAO,EC7BX,yBAAS,2BAAgB,iBACzB,yBAAS,kBACT,oBAAS,mBAQT,eAAsB,CAAK,CAAC,GAAkC,QAAQ,GAAM,SAAQ,UAAU,OAAW,GAA0B,CAAC,EAAG,CACnI,IAAM,EAAe,CAAE,QAAS,MAAU,EAAe,EAAO,CAAC,CAAC,GAAK,CAAE,QAAS,EAAM,CAAG,EAErF,EAAU,MAAO,IAA8B,CACjD,IAAM,EAAa,EAAsB,CAAO,EAC1C,EAAc,EAAe,EAAW,OAAQ,EAAQ,CAAW,EAEzE,OAAO,WAAW,MAAM,EAAS,IAAK,EAAS,OAAQ,CAAY,CAAC,EAAE,QAAQ,IAAM,EAAW,MAAM,CAAC,GAG1G,OAAO,EAAa,QAAU,MAAM,EAAU,EAAS,IAAK,EAAc,QAAO,CAAC,EAAI,MAAM,EAAQ,ECnBxG,IAAM,EAAY,IAAI,IAEf,SAAS,CAAc,CAAC,EAAsB,EAAc,KAAM,CAGrE,OAFA,EAAU,IAAI,EAAS,CAAW,EAE3B,IAAM,CACT,EAAU,OAAO,CAAO,GAIhC,IAAI,EAAa,GACb,EAES,EAAY,IAAM,CAC3B,OAAO,GAGJ,SAAS,CAAY,CAAC,EAAW,EAAG,EAAc,KAAsB,CAC3E,GAAI,EACA,OAAO,EAKX,GAFA,EAAa,GAET,EAAU,OAAS,EACnB,QAAQ,KAAK,CAAQ,EAGzB,IAAM,EAAiC,CAAC,EAExC,QAAY,EAAS,KAAS,EAC1B,EAAS,KAAK,QAAQ,QAAQ,EAAE,KAAK,IAAM,EAAQ,CAAQ,CAAC,CAAC,EAC7D,EAAc,KAAK,IAAI,EAAa,CAAI,EAG5C,IAAM,EAAQ,WAAW,IAAM,QAAQ,KAAK,CAAQ,EAAG,CAAW,EAElE,SAAS,CAAM,EAAU,CACrB,aAAa,CAAK,EAClB,QAAQ,KAAK,CAAQ,EAGzB,OAAO,EAAe,QAAQ,WAAW,CAAQ,EAAE,KAAK,CAAM,EC3ClE,kBAAS,UAAS,kBAClB,wBAAS,iBACT,yBAAS,kBAAgB,kBAElB,IAAM,EAAe,CAAC,IACzB,EAAa,CAAI,EAAI,EAAe,CAAI,EAAI,EAAK,SAAS,EAGjD,EAAM,CAAC,KAA2B,IAC3C,EAAK,EAAQ,EAAc,EAAW,GAAG,CAAC,EAAG,GAAG,EAAK,IAAI,CAAY,CAAC",
|
|
11
|
-
"debugId": "578EB85944C5459C64756E2164756E21",
|
|
12
|
-
"names": []
|
|
13
|
-
}
|
package/chunk-3w6nt7kb.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
var e=new Set(["1","on","true","yes"]);var c=(n)=>Object.prototype.toString.call(n);function b(n){if(n===null)return"null";return typeof n==="object"||typeof n==="function"?c(n).slice(8,-1).toLowerCase():typeof n}var o=(n)=>n===null,i=(n)=>n===void 0,l=(n)=>o(n)||i(n),w=(n)=>!o(n),T=(n)=>!i(n),a=(n)=>!l(n),r=(n)=>typeof n==="boolean",d=(n)=>typeof n==="symbol",y=(n)=>typeof n==="bigint",s=(n)=>typeof n==="number",u=(n)=>typeof n==="string",N=(n)=>n instanceof Date,S=(n)=>n===null||typeof n!=="object"&&typeof n!=="function",g=(n)=>o(n)||u(n)||r(n)||s(n)&&Number.isFinite(n);function P(n,p={}){let{anyNonZeroNumber:t=!1,trueStrings:f=e}=p;if(r(n))return n;if(u(n))return f.has(n.toLowerCase());if(s(n))return t?n!==0&&Number.isFinite(n):n===1;if(y(n))return t?n!==0n:n===1n;return!1}var L=(n)=>typeof n==="object"&&n!==null&&typeof n.next==="function"&&typeof n[Symbol.iterator]==="function";export{e as Fd,c as Gd,b as Hd,o as Id,i as Jd,l as Kd,w as Ld,T as Md,a as Nd,r as Od,d as Pd,y as Qd,s as Rd,u as Sd,N as Td,S as Ud,g as Vd,P as Wd,L as Xd};
|
|
2
|
-
|
|
3
|
-
//# debugId=4BB7D5816C29805564756E2164756E21
|
|
4
|
-
//# sourceMappingURL=chunk-3w6nt7kb.js.map
|
package/chunk-3w6nt7kb.js.map
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/core/constants.ts", "../src/core/conversions.ts", "../src/core/guards.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"export const DEFAULT_TRUE_STRINGS = new Set(['1', 'on', 'true', 'yes'])\n",
|
|
6
|
-
"export const toString = (value: unknown) => Object.prototype.toString.call(value)\n\nexport function typeOf(value: unknown): string {\n if (value === null) {\n return 'null'\n }\n\n return typeof value === 'object' || typeof value === 'function' ? toString(value).slice(8, -1).toLowerCase() : typeof value\n}\n",
|
|
7
|
-
"import type { JsonablePrimitive, Primitive } from './types'\nimport { DEFAULT_TRUE_STRINGS } from './constants'\n\nexport const isNull = (value: unknown): value is null => value === null\nexport const isUndefined = (value: unknown): value is undefined => value === undefined\nexport const isNullish = (value: unknown): value is null | undefined => isNull(value) || isUndefined(value)\n\nexport const notNull = <T>(value: T): value is Exclude<T, null> => !isNull(value)\nexport const notUndefined = <T>(value: T): value is Exclude<T, undefined> => !isUndefined(value)\nexport const notNullish = <T>(value: T): value is NonNullable<T> => !isNullish(value)\n\nexport const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean'\nexport const isSymbol = (value: unknown): value is symbol => typeof value === 'symbol'\nexport const isBigInt = (value: unknown): value is bigint => typeof value === 'bigint'\nexport const isNumber = (value: unknown): value is number => typeof value === 'number'\nexport const isString = (value: unknown): value is string => typeof value === 'string'\nexport const isDate = (value: unknown): value is Date => value instanceof Date\n\nexport const isPrimitive = (value: unknown): value is Primitive => value === null || (typeof value !== 'object' && typeof value !== 'function')\n\nexport const isJsonablePrimitive = (value: unknown): value is JsonablePrimitive => (\n isNull(value) || isString(value) || isBoolean(value) || (isNumber(value) && Number.isFinite(value))\n)\n\nexport interface IsTrueLikeOptions {\n anyNonZeroNumber?: boolean\n trueStrings?: Set<string>\n}\n\nexport function isTrueLike(value: unknown, options: IsTrueLikeOptions = {}) {\n const { anyNonZeroNumber = false, trueStrings = DEFAULT_TRUE_STRINGS } = options\n\n if (isBoolean(value)) {\n return value\n }\n\n if (isString(value)) {\n return trueStrings.has(value.toLowerCase())\n }\n\n if (isNumber(value)) {\n return anyNonZeroNumber ? value !== 0 && Number.isFinite(value) : value === 1\n }\n\n if (isBigInt(value)) {\n return anyNonZeroNumber ? value !== 0n : value === 1n\n }\n\n return false\n}\n\nexport const isGenerator = (value: unknown): boolean => (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as Record<PropertyKey, unknown>).next === 'function' &&\n typeof (value as Record<PropertyKey, unknown>)[Symbol.iterator] === 'function'\n)\n"
|
|
8
|
-
],
|
|
9
|
-
"mappings": "AAAO,IAAM,EAAuB,IAAI,IAAI,CAAC,IAAK,KAAM,OAAQ,KAAK,CAAC,ECA/D,IAAM,EAAW,CAAC,IAAmB,OAAO,UAAU,SAAS,KAAK,CAAK,EAEzE,SAAS,CAAM,CAAC,EAAwB,CAC3C,GAAI,IAAU,KACV,MAAO,OAGX,OAAO,OAAO,IAAU,UAAY,OAAO,IAAU,WAAa,EAAS,CAAK,EAAE,MAAM,EAAG,EAAE,EAAE,YAAY,EAAI,OAAO,ECJnH,IAAM,EAAS,CAAC,IAAkC,IAAU,KACtD,EAAc,CAAC,IAAuC,IAAU,OAChE,EAAY,CAAC,IAA8C,EAAO,CAAK,GAAK,EAAY,CAAK,EAE7F,EAAU,CAAI,IAAwC,CAAC,EAAO,CAAK,EACnE,EAAe,CAAI,IAA6C,CAAC,EAAY,CAAK,EAClF,EAAa,CAAI,IAAsC,CAAC,EAAU,CAAK,EAEvE,EAAY,CAAC,IAAqC,OAAO,IAAU,UACnE,EAAW,CAAC,IAAoC,OAAO,IAAU,SACjE,EAAW,CAAC,IAAoC,OAAO,IAAU,SACjE,EAAW,CAAC,IAAoC,OAAO,IAAU,SACjE,EAAW,CAAC,IAAoC,OAAO,IAAU,SACjE,EAAS,CAAC,IAAkC,aAAiB,KAE7D,EAAc,CAAC,IAAuC,IAAU,MAAS,OAAO,IAAU,UAAY,OAAO,IAAU,WAEvH,EAAsB,CAAC,IAChC,EAAO,CAAK,GAAK,EAAS,CAAK,GAAK,EAAU,CAAK,GAAM,EAAS,CAAK,GAAK,OAAO,SAAS,CAAK,EAQ9F,SAAS,CAAU,CAAC,EAAgB,EAA6B,CAAC,EAAG,CACxE,IAAQ,mBAAmB,GAAO,cAAc,GAAyB,EAEzE,GAAI,EAAU,CAAK,EACf,OAAO,EAGX,GAAI,EAAS,CAAK,EACd,OAAO,EAAY,IAAI,EAAM,YAAY,CAAC,EAG9C,GAAI,EAAS,CAAK,EACd,OAAO,EAAmB,IAAU,GAAK,OAAO,SAAS,CAAK,EAAI,IAAU,EAGhF,GAAI,EAAS,CAAK,EACd,OAAO,EAAmB,IAAU,GAAK,IAAU,GAGvD,MAAO,GAGJ,IAAM,EAAc,CAAC,IACxB,OAAO,IAAU,UACjB,IAAU,MACV,OAAQ,EAAuC,OAAS,YACxD,OAAQ,EAAuC,OAAO,YAAc",
|
|
10
|
-
"debugId": "4BB7D5816C29805564756E2164756E21",
|
|
11
|
-
"names": []
|
|
12
|
-
}
|
package/chunk-5txwcr6j.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{fd as d,id as P}from"./chunk-bee0nxse.js";function p(e,a,t){if(!a)return e;let r=()=>t?P(t):a.reason??d();if(a.aborted)return Promise.reject(r());return new Promise((T,n)=>{let b=!1,o,f=(i)=>{if(!b)b=!0,a.removeEventListener("abort",o),i?.()};o=()=>{f(()=>n(r()))},a.addEventListener("abort",o),e.then((i)=>f(()=>T(i)),(i)=>f(()=>n(i)))})}var O=(e)=>async(a)=>{return Promise.resolve(e(a)).then(()=>a)};O.catch=(e)=>async(a)=>{throw await e(a),a};async function V(e,a){try{return await e()}catch(t){return await a(t)}}import{combineSignals as W,createAbortController as C,createAbortError as j}from"@/errors";function D(e,a){if(a)e?.removeEventListener("abort",a)}function F(e,a){let t=()=>a();if(e?.aborted)a();else e?.addEventListener("abort",t);return t}function L(e,a,t,r){let T=()=>{try{e()}catch(n){t?.(n)}try{a?.()}catch(n){t?.(n)}};if(r)T();else queueMicrotask(T)}function G({onCallbackError:e,onReject:a,onResolve:t,onSettle:r,signal:T,synchronousCallbacks:n=!1}={}){let b,o,f,i=!1,A=!1,s=!1,l=new Promise((w,y)=>{b=w,o=y}),g=(w)=>{D(T,f),L(w,r,e,n)};return Object.defineProperty(l,"isSettled",{enumerable:!0,get:()=>i}),Object.defineProperty(l,"isPending",{enumerable:!0,get:()=>!i}),Object.defineProperty(l,"isResolved",{enumerable:!0,get:()=>A}),Object.defineProperty(l,"isRejected",{enumerable:!0,get:()=>s}),l.resolve=(w)=>{if(i)return;i=!0,A=!0,b(w),g(()=>t?.(w))},l.reject=(w)=>{if(i)return;i=!0,s=!0,o(w),g(()=>a?.(w))},f=F(T,()=>{l.reject(T?.reason??j())}),l}var Z=(e,{error:a,signal:t,...r}={})=>{let T=C(e,a);return G({...r,onSettle(){T.abort(),r.onSettle?.()},signal:W(t,T.signal)})};import{isFunction as c}from"@/functions";import{isObject as x}from"@/objects";var te=(e)=>x(e)&&c(e.then),re=(e)=>x(e)&&c(e.then)&&c(e.catch)&&c(e.finally);import{isNonEmptyArray as N}from"@/arrays";async function ie(...e){if(!N(e))return;let a=await e[0]();for(let t=1;t<e.length;t++)a=await e[t](a);return a}import{assertParam as h}from"@/common";import{createAbortController as B,isAbortError as H}from"@/errors";import{isFunction as v}from"@/functions";import{isPlainObject as R}from"@/objects";import{combineSignals as I,createAbortController as M}from"@/errors";import{transform as q}from"@/functions";var u=async(e,{error:a,signal:t}={})=>p(new Promise((r)=>setTimeout(r,e)),t,a),we=(e,a,{error:t,signal:r}={})=>q(M(a,t),(T)=>p(e,I(r,T.signal)).finally(()=>T.abort()));function ye(e,a={}){let t,r;if(v(e)&&R(a))t=e,r=a;else h(R(e),"options must be an object"),h(v(a),"fn must be a function"),t=a,r=e;let{delay:T=0,immediately:n=!0,onError:b,stopOnError:o=!0}=r,f=B(),i=!0,A,s=()=>{return i=!1,f.abort(),A??Promise.resolve()},l,g=async()=>{if(!i)return;try{if(await p(Promise.resolve(t(f.signal)),f.signal),i)await u(T,{signal:f.signal})}catch(w){if(H(w)&&!i)return;if(b?.(w),o){s();return}}setTimeout(l,0)};if(l=()=>{A=g().finally(()=>{A=void 0})},n)Promise.resolve().then(l);else setTimeout(l,T);return s}import{isAbortError as E}from"@/errors";import{clamp as k}from"@/numbers";function _(e,{backoff:a=2,delay:t=1000,jitter:r=0.01,maxDelay:T=1e4}={}){let n=t*a**(e-1),b=k(n,0,T);if(r<=0)return b;let o=b*r,f=(Math.random()-0.5)*2*o;return k(b+f,0,T)}function m(e){if(e.length===1)return e[0];return AggregateError(e,"All retry attempts failed")}function z(e){if(!E(e))throw e}async function S(e,a,t,r,T){let n=_(e,a);await t?.(n,T),await u(n,{signal:r}).catch(z)}async function J(e,a,t,r,T,n){if(E(e))throw e;if(a.push(e),t<=0)throw m(a);if(r&&!await r(e,n))throw m(a);await T?.(e,n)}async function K(e,a,t,r,T,n){if(!r||!await r(e,n))return!0;if(t<=0)throw m(a);return await T?.(e,n),!1}async function Re(e,{maxAttempts:a=3,onBeforeWaitForNextAttempt:t,onFailedAttempt:r,onSuccessAttempt:T,shouldRetry:n,shouldRetryOnSuccess:b,signal:o,...f}={}){if(a<1)throw RangeError("maxAttempts must be at least 1");if(o)o.throwIfAborted();let i=0,A,s=[];while(i<a){let l=a-(i+++1),g={attempts:i,retriesLeft:l,signal:o};try{if(o)o.throwIfAborted();A=await p(Promise.resolve(e(o)),o)}catch(y){await J(y,s,l,n,r,g),await S(i,f,t,o,g);continue}if(await K(A,s,l,b,T,g))return A;await S(i,f,t,o,g)}throw m(s)}export{p as Hc,O as Ic,V as Jc,D as Kc,F as Lc,L as Mc,G as Nc,Z as Oc,te as Pc,re as Qc,ie as Rc,u as Sc,we as Tc,ye as Uc,_ as Vc,m as Wc,z as Xc,S as Yc,J as Zc,K as _c,Re as $c};
|
|
2
|
-
|
|
3
|
-
//# debugId=857CC4AAB8256DCC64756E2164756E21
|
|
4
|
-
//# sourceMappingURL=chunk-5txwcr6j.js.map
|