@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,18 @@
|
|
|
1
|
+
import type { Jsonable } from '../../core'
|
|
2
|
+
import type { SerializeContext } from '../types'
|
|
3
|
+
|
|
4
|
+
export function serializeLeafObject(value: unknown, ctx: SerializeContext): Jsonable | undefined {
|
|
5
|
+
if (value instanceof Date) {
|
|
6
|
+
return ctx.replacer({ type: 'date', value: value.toISOString() })
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (value instanceof RegExp) {
|
|
10
|
+
return ctx.replacer({ type: 'regexp', value: value.toString() })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (value instanceof URL) {
|
|
14
|
+
return ctx.replacer({ type: 'url', value: value.href })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return undefined
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Jsonable } from '../../core'
|
|
2
|
+
import type { SerializeContext } from '../types'
|
|
3
|
+
|
|
4
|
+
export function serializeNumber(value: number, ctx: SerializeContext): Jsonable {
|
|
5
|
+
if (Number.isNaN(value)) {
|
|
6
|
+
return ctx.replacer({ type: 'number', value: 'NaN' })
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (!Number.isFinite(value)) {
|
|
10
|
+
return ctx.replacer({ type: 'number', value: value > 0 ? 'Infinity' : '-Infinity' })
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return value
|
|
14
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Jsonable } from '../../core'
|
|
2
|
+
import type { SerializeContext, SerializeValueFn } from '../types'
|
|
3
|
+
import { OMIT_SENTINEL } from '../constants'
|
|
4
|
+
|
|
5
|
+
export function handlePropertyAccessError(error: unknown, strategy: SerializeContext['onPropertyAccess'], key: string | symbol, ctx: SerializeContext): Jsonable | typeof OMIT_SENTINEL {
|
|
6
|
+
if (strategy === 'throw') {
|
|
7
|
+
throw error
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (strategy === 'omit') {
|
|
11
|
+
return OMIT_SENTINEL
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return ctx.replacer({ type: 'property-access-error', value: `[Property Access Error: ${String(key)}]` })
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function safeAccess(obj: object, key: string | symbol, strategy: SerializeContext['onPropertyAccess'], ctx: SerializeContext): unknown {
|
|
18
|
+
try {
|
|
19
|
+
return (obj as Record<string | symbol, unknown>)[key]
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return handlePropertyAccessError(error, strategy, key, ctx)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function serializeObject(obj: object, ctx: SerializeContext, serializeValue: SerializeValueFn): Record<string, Jsonable> {
|
|
26
|
+
const result: Record<string, Jsonable> = {}
|
|
27
|
+
const { onPropertyAccess, symbolRegistry } = ctx
|
|
28
|
+
|
|
29
|
+
for (const key of Object.keys(obj)) {
|
|
30
|
+
const value = safeAccess(obj, key, onPropertyAccess, ctx)
|
|
31
|
+
|
|
32
|
+
if (value === OMIT_SENTINEL) {
|
|
33
|
+
continue
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const serializedValue = serializeValue(value, ctx)
|
|
37
|
+
|
|
38
|
+
if (serializedValue === OMIT_SENTINEL) {
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
result[key] = serializedValue
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
for (const sym of Object.getOwnPropertySymbols(obj)) {
|
|
46
|
+
const value = safeAccess(obj, sym, onPropertyAccess, ctx)
|
|
47
|
+
|
|
48
|
+
if (value === OMIT_SENTINEL) {
|
|
49
|
+
continue
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const serializedValue = serializeValue(value, ctx)
|
|
53
|
+
|
|
54
|
+
if (serializedValue === OMIT_SENTINEL) {
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
result[symbolRegistry(sym)] = serializedValue
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return result
|
|
62
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Jsonable } from '../../core'
|
|
2
|
+
import type { SerializeContext } from '../types'
|
|
3
|
+
import { isGenerator } from '../../core'
|
|
4
|
+
import { serializeFunction } from './function'
|
|
5
|
+
|
|
6
|
+
export function serializeOpaque(value: unknown, ctx: SerializeContext): Jsonable | undefined {
|
|
7
|
+
if (typeof value === 'function') {
|
|
8
|
+
return serializeFunction(value as (...args: unknown[]) => unknown, ctx)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (value instanceof Promise) {
|
|
12
|
+
return ctx.replacer({ type: 'promise', value: '[Promise]' })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (value instanceof WeakMap) {
|
|
16
|
+
return ctx.replacer({ type: 'weakmap', value: '[WeakMap]' })
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (value instanceof WeakSet) {
|
|
20
|
+
return ctx.replacer({ type: 'weakset', value: '[WeakSet]' })
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (typeof WeakRef !== 'undefined' && value instanceof WeakRef) {
|
|
24
|
+
return ctx.replacer({ type: 'weakref', value: '[WeakRef]' })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof ReadableStream !== 'undefined' && value instanceof ReadableStream) {
|
|
28
|
+
return ctx.replacer({ type: 'readablestream', value: '[ReadableStream]' })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (isGenerator(value)) {
|
|
32
|
+
return ctx.replacer({ type: 'generator', value: '[Generator]' })
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Jsonable } from '../../core'
|
|
2
|
+
import type { SerializeContext } from '../types'
|
|
3
|
+
import { isBigInt, isJsonablePrimitive, isNumber, isSymbol } from '../../core'
|
|
4
|
+
import { serializeNumber } from './number'
|
|
5
|
+
|
|
6
|
+
export function serializePrimitive(value: unknown, ctx: SerializeContext): Jsonable | undefined {
|
|
7
|
+
if (value === null) {
|
|
8
|
+
return null
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (value === undefined) {
|
|
12
|
+
return ctx.replacer({ type: 'undefined', value: null })
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (isNumber(value)) {
|
|
16
|
+
return serializeNumber(value, ctx)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (isJsonablePrimitive(value)) {
|
|
20
|
+
return value
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (isBigInt(value)) {
|
|
24
|
+
return ctx.replacer({ type: 'bigint', value: value.toString() })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (isSymbol(value)) {
|
|
28
|
+
return ctx.replacer({ type: 'symbol', value: ctx.symbolRegistry(value) })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return undefined
|
|
32
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function createSymbolKeySerializer() {
|
|
2
|
+
const cache = new Map<symbol, string>()
|
|
3
|
+
const usedKeys = new Set<string>()
|
|
4
|
+
|
|
5
|
+
let counter = 0
|
|
6
|
+
|
|
7
|
+
return (symbol: symbol): string => {
|
|
8
|
+
const cached = cache.get(symbol)
|
|
9
|
+
|
|
10
|
+
if (cached !== undefined) {
|
|
11
|
+
return cached
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const desc = symbol.description
|
|
15
|
+
const base = desc?.length ? desc : `@@${++counter}`
|
|
16
|
+
|
|
17
|
+
let key = `[Symbol(${base})]`
|
|
18
|
+
|
|
19
|
+
while (usedKeys.has(key)) {
|
|
20
|
+
key = `[Symbol(${base}@@${++counter})]`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
usedKeys.add(key)
|
|
24
|
+
cache.set(symbol, key)
|
|
25
|
+
|
|
26
|
+
return key
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Jsonable } from '../core'
|
|
2
|
+
import type { OMIT_SENTINEL } from './constants'
|
|
3
|
+
|
|
4
|
+
export interface SerializedValue {
|
|
5
|
+
__serialized__: true
|
|
6
|
+
metadata?: Record<string, Jsonable>
|
|
7
|
+
type: string
|
|
8
|
+
value: Jsonable
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type SerializeReplacer = (value: Omit<SerializedValue, '__serialized__'>) => Jsonable
|
|
12
|
+
|
|
13
|
+
export type SerializeErrorStrategy = 'omit' | 'placeholder' | 'throw'
|
|
14
|
+
|
|
15
|
+
export interface SerializeErrorHandlers {
|
|
16
|
+
circularRef?: SerializeErrorStrategy
|
|
17
|
+
maxDepth?: SerializeErrorStrategy
|
|
18
|
+
propertyAccess?: SerializeErrorStrategy
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface SerializeOptions {
|
|
22
|
+
maxDepth?: number
|
|
23
|
+
onError?: SerializeErrorHandlers | SerializeErrorStrategy
|
|
24
|
+
onUnserializable?: ((value: unknown) => Jsonable) | false
|
|
25
|
+
replacer?: SerializeReplacer
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SerializeContext {
|
|
29
|
+
depth: number
|
|
30
|
+
readonly maxDepth: number
|
|
31
|
+
readonly onCircularRef: SerializeErrorStrategy
|
|
32
|
+
readonly onMaxDepth: SerializeErrorStrategy
|
|
33
|
+
readonly onPropertyAccess: SerializeErrorStrategy
|
|
34
|
+
readonly onUnserializable: ((value: unknown) => Jsonable) | false
|
|
35
|
+
readonly replacer: SerializeReplacer
|
|
36
|
+
readonly symbolRegistry: (symbol: symbol) => string
|
|
37
|
+
readonly visited: Set<object>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type SerializeValueFn = (value: unknown, ctx: SerializeContext) => Jsonable | typeof OMIT_SENTINEL
|
|
41
|
+
|
|
42
|
+
export type ErrorPropertyValue = Jsonable | typeof OMIT_SENTINEL | undefined
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Jsonable } from '../core'
|
|
2
|
+
import type { SerializeContext, SerializeErrorStrategy } from './types'
|
|
3
|
+
import { OMIT_SENTINEL } from './constants'
|
|
4
|
+
|
|
5
|
+
export function handleError(strategy: SerializeErrorStrategy, type: string, placeholder: string, ctx: SerializeContext): Jsonable | typeof OMIT_SENTINEL {
|
|
6
|
+
if (strategy === 'throw') {
|
|
7
|
+
throw new Error(placeholder)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (strategy === 'omit') {
|
|
11
|
+
return OMIT_SENTINEL
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return ctx.replacer({ type, value: placeholder })
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const WHITESPACE_CHARACTERS = new Set([' ', '\n', '\r', '\t', '\v', '\f'])
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function randomStr(length = 16, characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
|
|
2
|
+
let result = ''
|
|
3
|
+
|
|
4
|
+
for (let i = 0; i < length; i++) {
|
|
5
|
+
result += characters.charAt(Math.floor(Math.random() * characters.length))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return result
|
|
9
|
+
}
|
|
@@ -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,145 @@
|
|
|
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
|
+
)
|
|
100
|
+
|
|
101
|
+
export function indent(str: string, count: number, trim = false) {
|
|
102
|
+
const pad = ' '.repeat(count)
|
|
103
|
+
|
|
104
|
+
if (trim) {
|
|
105
|
+
return str.split('\n').map((line) => pad + ltrim(line)).join('\n')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return pad + str.replaceAll('\n', `\n${pad}`)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function unindent(str: TemplateStringsArray | string, ...values: unknown[]) {
|
|
112
|
+
const raw = typeof str === 'string' ? str : String.raw({ raw: str }, ...values)
|
|
113
|
+
const lines = raw.split('\n')
|
|
114
|
+
|
|
115
|
+
// Trim leading/trailing empty lines via slice (immutable)
|
|
116
|
+
let head = 0
|
|
117
|
+
let tail = lines.length
|
|
118
|
+
|
|
119
|
+
while (head < tail && lines[head]!.trim() === '') {
|
|
120
|
+
head++
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
while (tail > head && lines[tail - 1]!.trim() === '') {
|
|
124
|
+
tail--
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const trimmed = lines.slice(head, tail)
|
|
128
|
+
|
|
129
|
+
// Find minimum indent across non-empty lines
|
|
130
|
+
let minIndent = Infinity
|
|
131
|
+
|
|
132
|
+
for (const line of trimmed) {
|
|
133
|
+
if (line.trim() === '') {
|
|
134
|
+
continue
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
minIndent = Math.min(minIndent, /^[ \t]*/u.exec(line)![0].length)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (minIndent === 0 || minIndent === Infinity) {
|
|
141
|
+
return trimmed.join('\n')
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return trimmed.map((line) => line.slice(minIndent)).join('\n')
|
|
145
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// eslint-disable-next-line no-control-regex, regexp/no-control-character, sonarjs/no-control-regex -- ANSI stripping requires matching control characters
|
|
2
|
+
const ANSI_REGEX = /\u001B(?:\[[\d;]*[A-Za-z]|\].*?(?:\u0007|\u001B\\)|\([A-Za-z]|[A-Z])/gu
|
|
3
|
+
|
|
4
|
+
export function stripAnsi(str: string) {
|
|
5
|
+
ANSI_REGEX.lastIndex = 0
|
|
6
|
+
|
|
7
|
+
if (!ANSI_REGEX.test(str)) {
|
|
8
|
+
return str
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
ANSI_REGEX.lastIndex = 0
|
|
12
|
+
|
|
13
|
+
return str.replace(ANSI_REGEX, '')
|
|
14
|
+
}
|
|
@@ -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
|
+
)
|