@pawells/typescript-common 2.0.0 → 2.1.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/README.md +370 -223
- package/{build → dist}/array/array-chunk.d.ts +1 -1
- package/{build → dist}/array/array-chunk.js +2 -3
- package/{build → dist}/array/array-compact.d.ts +1 -1
- package/{build → dist}/array/array-compact.js +1 -2
- package/{build → dist}/array/array-contains.d.ts +1 -1
- package/{build → dist}/array/array-contains.js +2 -3
- package/{build → dist}/array/array-count-by.d.ts +1 -1
- package/{build → dist}/array/array-count-by.js +2 -3
- package/{build → dist}/array/array-difference.d.ts +12 -5
- package/dist/array/array-difference.d.ts.map +1 -0
- package/dist/array/array-difference.js +70 -0
- package/dist/array/array-element.js +1 -0
- package/{build → dist}/array/array-filter.d.ts +1 -1
- package/{build → dist}/array/array-filter.js +1 -2
- package/{build → dist}/array/array-flatten.d.ts +2 -2
- package/{build → dist}/array/array-flatten.d.ts.map +1 -1
- package/{build → dist}/array/array-flatten.js +1 -2
- package/{build → dist}/array/array-group-by.d.ts +1 -1
- package/{build → dist}/array/array-group-by.d.ts.map +1 -1
- package/{build → dist}/array/array-group-by.js +10 -9
- package/{build → dist}/array/array-intersection.d.ts +12 -5
- package/dist/array/array-intersection.d.ts.map +1 -0
- package/dist/array/array-intersection.js +79 -0
- package/{build → dist}/array/array-partition.d.ts +1 -1
- package/{build → dist}/array/array-partition.js +2 -3
- package/{build → dist}/array/array-range.d.ts +1 -1
- package/{build → dist}/array/array-range.js +1 -2
- package/{build → dist}/array/array-sample.d.ts +2 -2
- package/{build → dist}/array/array-sample.js +3 -5
- package/{build → dist}/array/array-shuffle.d.ts +1 -1
- package/{build → dist}/array/array-shuffle.js +1 -2
- package/{build → dist}/array/array-sort-by.d.ts +1 -1
- package/{build → dist}/array/array-sort-by.js +1 -2
- package/{build → dist}/array/array-zip.d.ts +1 -1
- package/{build → dist}/array/array-zip.js +1 -2
- package/{build → dist}/array/assert.d.ts +5 -5
- package/{build → dist}/array/assert.d.ts.map +1 -1
- package/{build → dist}/array/assert.js +13 -14
- package/{build → dist}/array/index.d.ts +1 -0
- package/{build → dist}/array/index.d.ts.map +1 -1
- package/{build → dist}/array/index.js +1 -1
- package/dist/array/iterators.d.ts +40 -0
- package/dist/array/iterators.d.ts.map +1 -0
- package/dist/array/iterators.js +54 -0
- package/{build → dist}/array/types.d.ts +20 -2
- package/{build → dist}/array/types.d.ts.map +1 -1
- package/dist/array/types.js +1 -0
- package/{build → dist}/array/unique.d.ts +1 -1
- package/{build → dist}/array/unique.js +1 -2
- package/dist/asserts/errors.d.ts.map +1 -0
- package/{build → dist}/asserts/errors.js +5 -3
- package/{build → dist}/asserts/generic.d.ts +23 -3
- package/dist/asserts/generic.d.ts.map +1 -0
- package/{build → dist}/asserts/generic.js +39 -7
- package/dist/asserts/index.d.ts +47 -0
- package/dist/asserts/index.d.ts.map +1 -0
- package/dist/asserts/index.js +46 -0
- package/{build → dist}/asserts/internal-utils.d.ts.map +1 -1
- package/{build → dist}/asserts/internal-utils.js +0 -1
- package/{build → dist}/asserts/types.d.ts +56 -17
- package/dist/asserts/types.d.ts.map +1 -0
- package/dist/asserts/types.js +1 -0
- package/{build → dist}/asserts/utils.d.ts +5 -21
- package/dist/asserts/utils.d.ts.map +1 -0
- package/{build → dist}/asserts/utils.js +14 -39
- package/{build → dist}/boolean/assert.d.ts +1 -2
- package/{build → dist}/boolean/assert.d.ts.map +1 -1
- package/{build → dist}/boolean/assert.js +1 -3
- package/dist/boolean/index.d.ts +13 -0
- package/dist/boolean/index.d.ts.map +1 -0
- package/dist/boolean/index.js +12 -0
- package/{build → dist}/enum/enum-entries.d.ts +1 -1
- package/dist/enum/enum-entries.d.ts.map +1 -0
- package/{build → dist}/enum/enum-entries.js +0 -1
- package/{build → dist}/enum/enum-key-by-value.d.ts +1 -1
- package/dist/enum/enum-key-by-value.d.ts.map +1 -0
- package/{build → dist}/enum/enum-key-by-value.js +0 -1
- package/{build → dist}/enum/enum-keys.js +0 -1
- package/{build → dist}/enum/enum-safe-value.d.ts +1 -1
- package/dist/enum/enum-safe-value.d.ts.map +1 -0
- package/{build → dist}/enum/enum-safe-value.js +0 -1
- package/{build → dist}/enum/enum-values.js +0 -1
- package/{build → dist}/enum/index.d.ts +1 -1
- package/dist/enum/index.d.ts.map +1 -0
- package/{build → dist}/enum/index.js +1 -2
- package/dist/enum/types.js +1 -0
- package/{build → dist}/enum/validate-enum-value.d.ts +1 -1
- package/dist/enum/validate-enum-value.d.ts.map +1 -0
- package/{build → dist}/enum/validate-enum-value.js +0 -1
- package/{build → dist}/function/compose.d.ts +6 -0
- package/dist/function/compose.d.ts.map +1 -0
- package/{build → dist}/function/compose.js +0 -1
- package/{build → dist}/function/debounce.d.ts +6 -0
- package/dist/function/debounce.d.ts.map +1 -0
- package/{build → dist}/function/debounce.js +6 -1
- package/{build → dist}/function/index.js +0 -1
- package/dist/function/memoize.d.ts +56 -0
- package/dist/function/memoize.d.ts.map +1 -0
- package/dist/function/memoize.js +72 -0
- package/{build → dist}/function/once.d.ts.map +1 -1
- package/{build → dist}/function/once.js +1 -1
- package/{build → dist}/function/sleep.js +0 -1
- package/{build → dist}/function/throttle.d.ts +7 -0
- package/dist/function/throttle.d.ts.map +1 -0
- package/{build → dist}/function/throttle.js +7 -1
- package/dist/function/types.d.ts +18 -0
- package/dist/function/types.d.ts.map +1 -0
- package/dist/function/types.js +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/json.sanitization.d.ts +14 -0
- package/dist/json.sanitization.d.ts.map +1 -0
- package/dist/json.sanitization.js +37 -0
- package/{build → dist}/lru-cache.d.ts +19 -0
- package/dist/lru-cache.d.ts.map +1 -0
- package/{build → dist}/lru-cache.js +24 -2
- package/{build → dist}/number/assert.js +0 -1
- package/dist/number/index.d.ts +13 -0
- package/dist/number/index.d.ts.map +1 -0
- package/dist/number/index.js +12 -0
- package/{build → dist}/object/assert-object.d.ts +5 -1
- package/{build → dist}/object/assert-object.d.ts.map +1 -1
- package/{build → dist}/object/assert-object.js +4 -1
- package/{build → dist}/object/assert.d.ts +1 -1
- package/dist/object/assert.d.ts.map +1 -0
- package/{build → dist}/object/assert.js +7 -29
- package/{build → dist}/object/clone.d.ts +6 -0
- package/dist/object/clone.d.ts.map +1 -0
- package/{build → dist}/object/clone.js +14 -5
- package/{build → dist}/object/equals.d.ts.map +1 -1
- package/{build → dist}/object/equals.js +3 -7
- package/dist/object/filter-cached.d.ts +26 -0
- package/{build → dist}/object/filter-cached.d.ts.map +1 -1
- package/{build → dist}/object/filter-cached.js +27 -6
- package/{build → dist}/object/filter.d.ts.map +1 -1
- package/{build → dist}/object/filter.js +22 -6
- package/{build → dist}/object/has-circular-reference.d.ts.map +1 -1
- package/{build → dist}/object/has-circular-reference.js +4 -2
- package/{build → dist}/object/hash.d.ts +4 -0
- package/dist/object/hash.d.ts.map +1 -0
- package/{build → dist}/object/hash.js +20 -7
- package/{build → dist}/object/index.d.ts +2 -2
- package/{build → dist}/object/index.d.ts.map +1 -1
- package/{build → dist}/object/index.js +1 -2
- package/{build → dist}/object/json-circular-replacer.d.ts.map +1 -1
- package/{build → dist}/object/json-circular-replacer.js +0 -1
- package/{build → dist}/object/key-value-pairs.js +0 -1
- package/dist/object/map-cached.d.ts +31 -0
- package/dist/object/map-cached.d.ts.map +1 -0
- package/{build → dist}/object/map-cached.js +34 -6
- package/{build → dist}/object/map.js +0 -1
- package/{build → dist}/object/merge.d.ts.map +1 -1
- package/{build → dist}/object/merge.js +7 -7
- package/{build → dist}/object/object-diff.d.ts +2 -2
- package/{build → dist}/object/object-diff.d.ts.map +1 -1
- package/{build → dist}/object/object-diff.js +11 -5
- package/{build → dist}/object/object-flatten.d.ts +1 -1
- package/{build → dist}/object/object-flatten.d.ts.map +1 -1
- package/{build → dist}/object/object-flatten.js +10 -4
- package/{build → dist}/object/object-invert.js +0 -1
- package/{build → dist}/object/omit.js +0 -1
- package/{build → dist}/object/pick.js +0 -1
- package/{build → dist}/object/property-paths.d.ts +2 -0
- package/{build → dist}/object/property-paths.d.ts.map +1 -1
- package/{build → dist}/object/property-paths.js +8 -7
- package/dist/object/security-utils.d.ts +193 -0
- package/dist/object/security-utils.d.ts.map +1 -0
- package/dist/object/security-utils.js +304 -0
- package/{build → dist}/object/sort-keys.d.ts +15 -1
- package/dist/object/sort-keys.d.ts.map +1 -0
- package/dist/object/sort-keys.js +73 -0
- package/{build → dist}/object/types.d.ts +0 -61
- package/dist/object/types.d.ts.map +1 -0
- package/dist/object/types.js +1 -0
- package/{build → dist}/string/assert.d.ts +24 -0
- package/dist/string/assert.d.ts.map +1 -0
- package/{build → dist}/string/assert.js +30 -1
- package/{build → dist}/string/case-conversion.js +0 -1
- package/{build → dist}/string/comparison.d.ts.map +1 -1
- package/{build → dist}/string/comparison.js +3 -1
- package/{build → dist}/string/formatting.d.ts.map +1 -1
- package/{build → dist}/string/formatting.js +5 -3
- package/{build → dist}/string/index.js +0 -1
- package/{build → dist}/string/transformation.js +0 -1
- package/dist/string/types.d.ts +118 -0
- package/dist/string/types.d.ts.map +1 -0
- package/dist/string/types.js +1 -0
- package/{build → dist}/string/validation.js +0 -1
- package/dist/time/elapsed-time/constants.d.ts +36 -0
- package/{build → dist}/time/elapsed-time/constants.d.ts.map +1 -1
- package/{build → dist}/time/elapsed-time/constants.js +32 -3
- package/{build → dist}/time/elapsed-time/elapsed-time.d.ts +74 -22
- package/dist/time/elapsed-time/elapsed-time.d.ts.map +1 -0
- package/{build → dist}/time/elapsed-time/elapsed-time.js +183 -89
- package/dist/time/elapsed-time/types.d.ts +336 -0
- package/dist/time/elapsed-time/types.d.ts.map +1 -0
- package/dist/time/elapsed-time/types.js +1 -0
- package/{build → dist}/time/elapsed-time/utils.d.ts +1 -1
- package/dist/time/elapsed-time/utils.d.ts.map +1 -0
- package/{build → dist}/time/elapsed-time/utils.js +0 -1
- package/dist/time/index.d.ts +14 -0
- package/dist/time/index.d.ts.map +1 -0
- package/{build → dist}/time/index.js +0 -5
- package/{build → dist}/time/stopwatch/entry.d.ts +1 -1
- package/dist/time/stopwatch/entry.d.ts.map +1 -0
- package/{build → dist}/time/stopwatch/entry.js +0 -1
- package/{build → dist}/time/stopwatch/stopwatch.d.ts +27 -3
- package/dist/time/stopwatch/stopwatch.d.ts.map +1 -0
- package/{build → dist}/time/stopwatch/stopwatch.js +32 -4
- package/dist/zod-util.d.ts +145 -0
- package/dist/zod-util.d.ts.map +1 -0
- package/dist/zod-util.js +126 -0
- package/package.json +51 -67
- package/LICENSE +0 -21
- package/build/array/array-chunk.js.map +0 -1
- package/build/array/array-compact.js.map +0 -1
- package/build/array/array-contains.js.map +0 -1
- package/build/array/array-count-by.js.map +0 -1
- package/build/array/array-difference.d.ts.map +0 -1
- package/build/array/array-difference.js +0 -51
- package/build/array/array-difference.js.map +0 -1
- package/build/array/array-element.js +0 -2
- package/build/array/array-element.js.map +0 -1
- package/build/array/array-filter.js.map +0 -1
- package/build/array/array-flatten.js.map +0 -1
- package/build/array/array-group-by.js.map +0 -1
- package/build/array/array-intersection.d.ts.map +0 -1
- package/build/array/array-intersection.js +0 -57
- package/build/array/array-intersection.js.map +0 -1
- package/build/array/array-partition.js.map +0 -1
- package/build/array/array-range.js.map +0 -1
- package/build/array/array-sample.js.map +0 -1
- package/build/array/array-shuffle.js.map +0 -1
- package/build/array/array-sort-by.js.map +0 -1
- package/build/array/array-zip.js.map +0 -1
- package/build/array/assert.js.map +0 -1
- package/build/array/index.js.map +0 -1
- package/build/array/types.js +0 -2
- package/build/array/types.js.map +0 -1
- package/build/array/unique.js.map +0 -1
- package/build/asserts/errors.d.ts.map +0 -1
- package/build/asserts/errors.js.map +0 -1
- package/build/asserts/generic.d.ts.map +0 -1
- package/build/asserts/generic.js.map +0 -1
- package/build/asserts/index.d.ts +0 -41
- package/build/asserts/index.d.ts.map +0 -1
- package/build/asserts/index.js +0 -41
- package/build/asserts/index.js.map +0 -1
- package/build/asserts/internal-utils.js.map +0 -1
- package/build/asserts/types.d.ts.map +0 -1
- package/build/asserts/types.js +0 -2
- package/build/asserts/types.js.map +0 -1
- package/build/asserts/utils.d.ts.map +0 -1
- package/build/asserts/utils.js.map +0 -1
- package/build/boolean/assert.js.map +0 -1
- package/build/boolean/index.d.ts +0 -9
- package/build/boolean/index.d.ts.map +0 -1
- package/build/boolean/index.js +0 -9
- package/build/boolean/index.js.map +0 -1
- package/build/enum/enum-entries.d.ts.map +0 -1
- package/build/enum/enum-entries.js.map +0 -1
- package/build/enum/enum-key-by-value.d.ts.map +0 -1
- package/build/enum/enum-key-by-value.js.map +0 -1
- package/build/enum/enum-keys.js.map +0 -1
- package/build/enum/enum-safe-value.d.ts.map +0 -1
- package/build/enum/enum-safe-value.js.map +0 -1
- package/build/enum/enum-values.js.map +0 -1
- package/build/enum/index.d.ts.map +0 -1
- package/build/enum/index.js.map +0 -1
- package/build/enum/types.js +0 -2
- package/build/enum/types.js.map +0 -1
- package/build/enum/validate-enum-value.d.ts.map +0 -1
- package/build/enum/validate-enum-value.js.map +0 -1
- package/build/function/compose.d.ts.map +0 -1
- package/build/function/compose.js.map +0 -1
- package/build/function/debounce.d.ts.map +0 -1
- package/build/function/debounce.js.map +0 -1
- package/build/function/index.js.map +0 -1
- package/build/function/memoize.d.ts +0 -30
- package/build/function/memoize.d.ts.map +0 -1
- package/build/function/memoize.js +0 -44
- package/build/function/memoize.js.map +0 -1
- package/build/function/once.js.map +0 -1
- package/build/function/sleep.js.map +0 -1
- package/build/function/throttle.d.ts.map +0 -1
- package/build/function/throttle.js.map +0 -1
- package/build/function/types.d.ts +0 -5
- package/build/function/types.d.ts.map +0 -1
- package/build/function/types.js +0 -2
- package/build/function/types.js.map +0 -1
- package/build/index.d.ts +0 -38
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -64
- package/build/index.js.map +0 -1
- package/build/lru-cache.d.ts.map +0 -1
- package/build/lru-cache.js.map +0 -1
- package/build/number/assert.js.map +0 -1
- package/build/number/index.d.ts +0 -9
- package/build/number/index.d.ts.map +0 -1
- package/build/number/index.js +0 -9
- package/build/number/index.js.map +0 -1
- package/build/object/assert-object.js.map +0 -1
- package/build/object/assert.d.ts.map +0 -1
- package/build/object/assert.js.map +0 -1
- package/build/object/clone.d.ts.map +0 -1
- package/build/object/clone.js.map +0 -1
- package/build/object/equals.js.map +0 -1
- package/build/object/filter-cached.d.ts +0 -21
- package/build/object/filter-cached.js.map +0 -1
- package/build/object/filter.js.map +0 -1
- package/build/object/has-circular-reference.js.map +0 -1
- package/build/object/hash.d.ts.map +0 -1
- package/build/object/hash.js.map +0 -1
- package/build/object/index.js.map +0 -1
- package/build/object/json-circular-replacer.js.map +0 -1
- package/build/object/key-value-pairs.js.map +0 -1
- package/build/object/map-cached.d.ts +0 -20
- package/build/object/map-cached.d.ts.map +0 -1
- package/build/object/map-cached.js.map +0 -1
- package/build/object/map.js.map +0 -1
- package/build/object/merge.js.map +0 -1
- package/build/object/object-diff.js.map +0 -1
- package/build/object/object-flatten.js.map +0 -1
- package/build/object/object-invert.js.map +0 -1
- package/build/object/omit.js.map +0 -1
- package/build/object/pick.js.map +0 -1
- package/build/object/property-paths.js.map +0 -1
- package/build/object/security-utils.d.ts +0 -59
- package/build/object/security-utils.d.ts.map +0 -1
- package/build/object/security-utils.js +0 -161
- package/build/object/security-utils.js.map +0 -1
- package/build/object/sort-keys.d.ts.map +0 -1
- package/build/object/sort-keys.js +0 -52
- package/build/object/sort-keys.js.map +0 -1
- package/build/object/types.d.ts.map +0 -1
- package/build/object/types.js +0 -6
- package/build/object/types.js.map +0 -1
- package/build/string/assert.d.ts.map +0 -1
- package/build/string/assert.js.map +0 -1
- package/build/string/case-conversion.js.map +0 -1
- package/build/string/comparison.js.map +0 -1
- package/build/string/formatting.js.map +0 -1
- package/build/string/index.js.map +0 -1
- package/build/string/transformation.js.map +0 -1
- package/build/string/types.d.ts +0 -44
- package/build/string/types.d.ts.map +0 -1
- package/build/string/types.js +0 -2
- package/build/string/types.js.map +0 -1
- package/build/string/validation.js.map +0 -1
- package/build/time/elapsed-time/constants.d.ts +0 -10
- package/build/time/elapsed-time/constants.js.map +0 -1
- package/build/time/elapsed-time/elapsed-time.d.ts.map +0 -1
- package/build/time/elapsed-time/elapsed-time.js.map +0 -1
- package/build/time/elapsed-time/types.d.ts +0 -150
- package/build/time/elapsed-time/types.d.ts.map +0 -1
- package/build/time/elapsed-time/types.js +0 -2
- package/build/time/elapsed-time/types.js.map +0 -1
- package/build/time/elapsed-time/utils.d.ts.map +0 -1
- package/build/time/elapsed-time/utils.js.map +0 -1
- package/build/time/index.d.ts +0 -18
- package/build/time/index.d.ts.map +0 -1
- package/build/time/index.js.map +0 -1
- package/build/time/stopwatch/entry-types.d.ts +0 -13
- package/build/time/stopwatch/entry-types.d.ts.map +0 -1
- package/build/time/stopwatch/entry-types.js +0 -2
- package/build/time/stopwatch/entry-types.js.map +0 -1
- package/build/time/stopwatch/entry.d.ts.map +0 -1
- package/build/time/stopwatch/entry.js.map +0 -1
- package/build/time/stopwatch/stopwatch.d.ts.map +0 -1
- package/build/time/stopwatch/stopwatch.js.map +0 -1
- /package/{build → dist}/array/array-chunk.d.ts.map +0 -0
- /package/{build → dist}/array/array-compact.d.ts.map +0 -0
- /package/{build → dist}/array/array-contains.d.ts.map +0 -0
- /package/{build → dist}/array/array-count-by.d.ts.map +0 -0
- /package/{build → dist}/array/array-element.d.ts +0 -0
- /package/{build → dist}/array/array-element.d.ts.map +0 -0
- /package/{build → dist}/array/array-filter.d.ts.map +0 -0
- /package/{build → dist}/array/array-partition.d.ts.map +0 -0
- /package/{build → dist}/array/array-range.d.ts.map +0 -0
- /package/{build → dist}/array/array-sample.d.ts.map +0 -0
- /package/{build → dist}/array/array-shuffle.d.ts.map +0 -0
- /package/{build → dist}/array/array-sort-by.d.ts.map +0 -0
- /package/{build → dist}/array/array-zip.d.ts.map +0 -0
- /package/{build → dist}/array/unique.d.ts.map +0 -0
- /package/{build → dist}/asserts/errors.d.ts +0 -0
- /package/{build → dist}/asserts/internal-utils.d.ts +0 -0
- /package/{build → dist}/enum/enum-keys.d.ts +0 -0
- /package/{build → dist}/enum/enum-keys.d.ts.map +0 -0
- /package/{build → dist}/enum/enum-values.d.ts +0 -0
- /package/{build → dist}/enum/enum-values.d.ts.map +0 -0
- /package/{build → dist}/enum/types.d.ts +0 -0
- /package/{build → dist}/enum/types.d.ts.map +0 -0
- /package/{build → dist}/function/index.d.ts +0 -0
- /package/{build → dist}/function/index.d.ts.map +0 -0
- /package/{build → dist}/function/once.d.ts +0 -0
- /package/{build → dist}/function/sleep.d.ts +0 -0
- /package/{build → dist}/function/sleep.d.ts.map +0 -0
- /package/{build → dist}/number/assert.d.ts +0 -0
- /package/{build → dist}/number/assert.d.ts.map +0 -0
- /package/{build → dist}/object/equals.d.ts +0 -0
- /package/{build → dist}/object/filter.d.ts +0 -0
- /package/{build → dist}/object/has-circular-reference.d.ts +0 -0
- /package/{build → dist}/object/json-circular-replacer.d.ts +0 -0
- /package/{build → dist}/object/key-value-pairs.d.ts +0 -0
- /package/{build → dist}/object/key-value-pairs.d.ts.map +0 -0
- /package/{build → dist}/object/map.d.ts +0 -0
- /package/{build → dist}/object/map.d.ts.map +0 -0
- /package/{build → dist}/object/merge.d.ts +0 -0
- /package/{build → dist}/object/object-invert.d.ts +0 -0
- /package/{build → dist}/object/object-invert.d.ts.map +0 -0
- /package/{build → dist}/object/omit.d.ts +0 -0
- /package/{build → dist}/object/omit.d.ts.map +0 -0
- /package/{build → dist}/object/pick.d.ts +0 -0
- /package/{build → dist}/object/pick.d.ts.map +0 -0
- /package/{build → dist}/string/case-conversion.d.ts +0 -0
- /package/{build → dist}/string/case-conversion.d.ts.map +0 -0
- /package/{build → dist}/string/comparison.d.ts +0 -0
- /package/{build → dist}/string/formatting.d.ts +0 -0
- /package/{build → dist}/string/index.d.ts +0 -0
- /package/{build → dist}/string/index.d.ts.map +0 -0
- /package/{build → dist}/string/transformation.d.ts +0 -0
- /package/{build → dist}/string/transformation.d.ts.map +0 -0
- /package/{build → dist}/string/validation.d.ts +0 -0
- /package/{build → dist}/string/validation.d.ts.map +0 -0
|
@@ -7,44 +7,55 @@ const MINUTES_PER_HOUR = 60;
|
|
|
7
7
|
const HOURS_PER_DAY = 24;
|
|
8
8
|
const DAYS_PER_WEEK = 7;
|
|
9
9
|
const PRECISION_DECIMAL_PLACES = 3;
|
|
10
|
+
// Format key aliases for case-insensitive matching
|
|
11
|
+
const FORMAT_ALIASES = {
|
|
12
|
+
mostsignificant: 'mostSignificant',
|
|
13
|
+
timewithseconds: 'timeWithSeconds',
|
|
14
|
+
};
|
|
10
15
|
/**
|
|
11
16
|
* Represents a duration of time with formatting and calculation capabilities.
|
|
12
17
|
*/
|
|
13
18
|
export class ElapsedTime {
|
|
14
19
|
/** Whether the elapsed time represents a negative duration */
|
|
15
|
-
|
|
20
|
+
_isNegative = false;
|
|
16
21
|
/** The total duration in milliseconds (always positive, sign stored in isNegative) */
|
|
17
|
-
|
|
22
|
+
_totalMilliseconds = 0;
|
|
18
23
|
// Cached calculations for better performance - computed on-demand
|
|
19
24
|
/** Cached total seconds value */
|
|
20
|
-
|
|
25
|
+
_totalSeconds = 0;
|
|
21
26
|
/** Cached total minutes value */
|
|
22
|
-
|
|
27
|
+
_totalMinutes = 0;
|
|
23
28
|
/** Cached total hours value */
|
|
24
|
-
|
|
29
|
+
_totalHours = 0;
|
|
25
30
|
/** Cached total days value */
|
|
26
|
-
|
|
31
|
+
_totalDays = 0;
|
|
27
32
|
/** Cached seconds component (excluding complete minutes) */
|
|
28
|
-
|
|
33
|
+
_seconds = 0;
|
|
29
34
|
/** Cached minutes component (excluding complete hours) */
|
|
30
|
-
|
|
35
|
+
_minutes = 0;
|
|
31
36
|
/** Cached hours component (excluding complete days) */
|
|
32
|
-
|
|
37
|
+
_hours = 0;
|
|
33
38
|
/** Cached days component (excluding complete weeks) */
|
|
34
|
-
|
|
39
|
+
_days = 0;
|
|
35
40
|
/** Cached weeks component */
|
|
36
|
-
|
|
41
|
+
_weeks = 0;
|
|
37
42
|
/** Cached milliseconds component (excluding complete seconds) */
|
|
38
|
-
|
|
43
|
+
_milliseconds = 0;
|
|
39
44
|
/** Flag to track whether cached values have been calculated */
|
|
40
|
-
|
|
45
|
+
_valuesCalculated = false;
|
|
46
|
+
/**
|
|
47
|
+
* Cache object for computed property values when in stopped/paused state.
|
|
48
|
+
* Stores the last computed property value to avoid recalculation on repeated access.
|
|
49
|
+
* Cleared when TotalMilliseconds is set (instance becomes mutable again).
|
|
50
|
+
*/
|
|
51
|
+
_propertyCache = {};
|
|
41
52
|
/**
|
|
42
53
|
* Creates a new ElapsedTime instance.
|
|
43
54
|
* @param milliseconds The total number of milliseconds.
|
|
44
55
|
*/
|
|
45
56
|
constructor(milliseconds) {
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
57
|
+
this._totalMilliseconds = Math.abs(milliseconds);
|
|
58
|
+
this._isNegative = milliseconds < 0;
|
|
48
59
|
}
|
|
49
60
|
/**
|
|
50
61
|
* Calculate all time unit values for efficient access.
|
|
@@ -67,48 +78,77 @@ export class ElapsedTime {
|
|
|
67
78
|
* console.log(elapsed.TotalHours); // 26
|
|
68
79
|
* ```
|
|
69
80
|
*/
|
|
70
|
-
|
|
71
|
-
if (this.
|
|
81
|
+
_calculateTimeValues() {
|
|
82
|
+
if (this._valuesCalculated)
|
|
72
83
|
return;
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
75
|
-
this.
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
84
|
+
this._totalSeconds = Math.floor(this._totalMilliseconds / MS_PER_SECOND);
|
|
85
|
+
this._totalMinutes = Math.floor(this._totalSeconds / SECONDS_PER_MINUTE);
|
|
86
|
+
this._totalHours = Math.floor(this._totalMinutes / MINUTES_PER_HOUR);
|
|
87
|
+
this._totalDays = Math.floor(this._totalHours / HOURS_PER_DAY);
|
|
88
|
+
this._weeks = Math.floor(this._totalDays / DAYS_PER_WEEK);
|
|
89
|
+
this._days = this._totalDays % DAYS_PER_WEEK;
|
|
90
|
+
this._hours = this._totalHours % HOURS_PER_DAY;
|
|
91
|
+
this._minutes = this._totalMinutes % MINUTES_PER_HOUR;
|
|
92
|
+
this._seconds = this._totalSeconds % SECONDS_PER_MINUTE;
|
|
93
|
+
this._milliseconds = this._totalMilliseconds % MS_PER_SECOND;
|
|
94
|
+
this._valuesCalculated = true;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get a cached property value, computing and caching it if necessary.
|
|
98
|
+
* For stopped/paused instances (where TotalMilliseconds doesn't change),
|
|
99
|
+
* this returns the cached value on subsequent accesses, avoiding repeated
|
|
100
|
+
* property getter indirection and computation.
|
|
101
|
+
*
|
|
102
|
+
* @param key - Cache key identifying the property
|
|
103
|
+
* @param getter - Function to compute the value if not cached
|
|
104
|
+
* @returns The cached or newly computed value
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
_getCachedProperty(key, getter) {
|
|
108
|
+
// Check if value is already cached
|
|
109
|
+
if (key in this._propertyCache) {
|
|
110
|
+
return this._propertyCache[key];
|
|
111
|
+
}
|
|
112
|
+
// Compute and cache the value
|
|
113
|
+
const value = getter();
|
|
114
|
+
this._propertyCache[key] = value;
|
|
115
|
+
return value;
|
|
84
116
|
}
|
|
85
117
|
/**
|
|
86
118
|
* Gets the number of weeks in the elapsed time.
|
|
87
119
|
*/
|
|
88
120
|
get Weeks() {
|
|
89
|
-
this.
|
|
90
|
-
|
|
121
|
+
return this._getCachedProperty('weeks', () => {
|
|
122
|
+
this._calculateTimeValues();
|
|
123
|
+
return this._weeks;
|
|
124
|
+
});
|
|
91
125
|
}
|
|
92
126
|
/**
|
|
93
127
|
* Gets the number of days in the elapsed time (excluding complete weeks).
|
|
94
128
|
*/
|
|
95
129
|
get Days() {
|
|
96
|
-
this.
|
|
97
|
-
|
|
130
|
+
return this._getCachedProperty('days', () => {
|
|
131
|
+
this._calculateTimeValues();
|
|
132
|
+
return this._days;
|
|
133
|
+
});
|
|
98
134
|
}
|
|
99
135
|
/**
|
|
100
136
|
* Gets the total number of days in the elapsed time.
|
|
101
137
|
*/
|
|
102
138
|
get TotalDays() {
|
|
103
|
-
this.
|
|
104
|
-
|
|
139
|
+
return this._getCachedProperty('totalDays', () => {
|
|
140
|
+
this._calculateTimeValues();
|
|
141
|
+
return this._totalDays;
|
|
142
|
+
});
|
|
105
143
|
}
|
|
106
144
|
/**
|
|
107
145
|
* Gets the number of hours in the elapsed time (excluding complete days).
|
|
108
146
|
*/
|
|
109
147
|
get Hours() {
|
|
110
|
-
this.
|
|
111
|
-
|
|
148
|
+
return this._getCachedProperty('hours', () => {
|
|
149
|
+
this._calculateTimeValues();
|
|
150
|
+
return this._hours;
|
|
151
|
+
});
|
|
112
152
|
}
|
|
113
153
|
static _pad(value, length) {
|
|
114
154
|
return value.toString().padStart(length, '0');
|
|
@@ -125,8 +165,10 @@ export class ElapsedTime {
|
|
|
125
165
|
* Gets the total number of hours in the elapsed time.
|
|
126
166
|
*/
|
|
127
167
|
get TotalHours() {
|
|
128
|
-
this.
|
|
129
|
-
|
|
168
|
+
return this._getCachedProperty('totalHours', () => {
|
|
169
|
+
this._calculateTimeValues();
|
|
170
|
+
return this._totalHours;
|
|
171
|
+
});
|
|
130
172
|
}
|
|
131
173
|
/**
|
|
132
174
|
* Gets the total hours as a padded string.
|
|
@@ -140,8 +182,10 @@ export class ElapsedTime {
|
|
|
140
182
|
* Gets the number of minutes in the elapsed time (excluding complete hours).
|
|
141
183
|
*/
|
|
142
184
|
get Minutes() {
|
|
143
|
-
this.
|
|
144
|
-
|
|
185
|
+
return this._getCachedProperty('minutes', () => {
|
|
186
|
+
this._calculateTimeValues();
|
|
187
|
+
return this._minutes;
|
|
188
|
+
});
|
|
145
189
|
}
|
|
146
190
|
/**
|
|
147
191
|
* Gets the minutes component as a padded string.
|
|
@@ -155,8 +199,10 @@ export class ElapsedTime {
|
|
|
155
199
|
* Gets the total number of minutes in the elapsed time.
|
|
156
200
|
*/
|
|
157
201
|
get TotalMinutes() {
|
|
158
|
-
this.
|
|
159
|
-
|
|
202
|
+
return this._getCachedProperty('totalMinutes', () => {
|
|
203
|
+
this._calculateTimeValues();
|
|
204
|
+
return this._totalMinutes;
|
|
205
|
+
});
|
|
160
206
|
}
|
|
161
207
|
/**
|
|
162
208
|
* Gets the total minutes as a padded string.
|
|
@@ -170,8 +216,10 @@ export class ElapsedTime {
|
|
|
170
216
|
* Gets the number of seconds in the elapsed time (excluding complete minutes).
|
|
171
217
|
*/
|
|
172
218
|
get Seconds() {
|
|
173
|
-
this.
|
|
174
|
-
|
|
219
|
+
return this._getCachedProperty('seconds', () => {
|
|
220
|
+
this._calculateTimeValues();
|
|
221
|
+
return this._seconds;
|
|
222
|
+
});
|
|
175
223
|
}
|
|
176
224
|
/**
|
|
177
225
|
* Gets the seconds component as a padded string.
|
|
@@ -185,8 +233,10 @@ export class ElapsedTime {
|
|
|
185
233
|
* Gets the total number of seconds in the elapsed time.
|
|
186
234
|
*/
|
|
187
235
|
get TotalSeconds() {
|
|
188
|
-
this.
|
|
189
|
-
|
|
236
|
+
return this._getCachedProperty('totalSeconds', () => {
|
|
237
|
+
this._calculateTimeValues();
|
|
238
|
+
return this._totalSeconds;
|
|
239
|
+
});
|
|
190
240
|
}
|
|
191
241
|
/**
|
|
192
242
|
* Gets the total seconds as a padded string.
|
|
@@ -200,8 +250,10 @@ export class ElapsedTime {
|
|
|
200
250
|
* Gets the number of milliseconds in the elapsed time (excluding complete seconds).
|
|
201
251
|
*/
|
|
202
252
|
get Milliseconds() {
|
|
203
|
-
this.
|
|
204
|
-
|
|
253
|
+
return this._getCachedProperty('milliseconds', () => {
|
|
254
|
+
this._calculateTimeValues();
|
|
255
|
+
return this._milliseconds;
|
|
256
|
+
});
|
|
205
257
|
}
|
|
206
258
|
/**
|
|
207
259
|
* Gets the milliseconds component as a padded string.
|
|
@@ -215,21 +267,22 @@ export class ElapsedTime {
|
|
|
215
267
|
* Checks if the elapsed time represents a negative duration.
|
|
216
268
|
*/
|
|
217
269
|
get IsNegative() {
|
|
218
|
-
return this.
|
|
270
|
+
return this._isNegative;
|
|
219
271
|
}
|
|
220
272
|
/**
|
|
221
273
|
* Gets the total number of milliseconds in the elapsed time.
|
|
222
274
|
*/
|
|
223
275
|
get TotalMilliseconds() {
|
|
224
|
-
return this.
|
|
276
|
+
return this._totalMilliseconds;
|
|
225
277
|
}
|
|
226
278
|
/**
|
|
227
279
|
* Sets the total number of milliseconds in the elapsed time.
|
|
228
280
|
*/
|
|
229
281
|
set TotalMilliseconds(value) {
|
|
230
|
-
this.
|
|
231
|
-
this.
|
|
232
|
-
this.
|
|
282
|
+
this._isNegative = value < 0;
|
|
283
|
+
this._totalMilliseconds = Math.abs(value);
|
|
284
|
+
this._valuesCalculated = false;
|
|
285
|
+
this._propertyCache = {};
|
|
233
286
|
}
|
|
234
287
|
/**
|
|
235
288
|
* Get the total milliseconds as a padded string.
|
|
@@ -364,13 +417,9 @@ export class ElapsedTime {
|
|
|
364
417
|
*/
|
|
365
418
|
Format(format = 'concise', options = {}) {
|
|
366
419
|
// Ensure all time values are calculated
|
|
367
|
-
this.
|
|
420
|
+
this._calculateTimeValues();
|
|
368
421
|
let resolvedOptions = { ...options };
|
|
369
422
|
// Handle predefined formats
|
|
370
|
-
const FORMAT_ALIASES = {
|
|
371
|
-
mostsignificant: 'mostSignificant',
|
|
372
|
-
timewithseconds: 'timeWithSeconds',
|
|
373
|
-
};
|
|
374
423
|
let formatKey = '';
|
|
375
424
|
if (typeof format === 'string') {
|
|
376
425
|
const stripped = format.toLowerCase().replace(/_/g, '');
|
|
@@ -382,9 +431,9 @@ export class ElapsedTime {
|
|
|
382
431
|
const appliedOptions = ApplyDefaultOptions(resolvedOptions);
|
|
383
432
|
// Special case for LONG format which needs pluralization
|
|
384
433
|
if (formatKey === 'long') {
|
|
385
|
-
return this.
|
|
434
|
+
return this._formatLong(appliedOptions);
|
|
386
435
|
}
|
|
387
|
-
return this.
|
|
436
|
+
return this._formatUsingTokens(appliedOptions, formatKey, options);
|
|
388
437
|
}
|
|
389
438
|
/**
|
|
390
439
|
* Special formatter for LONG format with proper pluralization.
|
|
@@ -405,26 +454,26 @@ export class ElapsedTime {
|
|
|
405
454
|
* elapsed2.Format('LONG'); // "2 hours 2 minutes 2 seconds" (all plural)
|
|
406
455
|
* ```
|
|
407
456
|
*/
|
|
408
|
-
|
|
457
|
+
_formatLong(options) {
|
|
409
458
|
const parts = [];
|
|
410
459
|
// Process each time unit in order of significance
|
|
411
|
-
if (this.
|
|
412
|
-
parts.push(`${this.
|
|
460
|
+
if (this._weeks > 0 || options.showZeroValues) {
|
|
461
|
+
parts.push(`${this._weeks} ${this._weeks === 1 ? 'week' : 'weeks'}`);
|
|
413
462
|
}
|
|
414
|
-
if (this.
|
|
415
|
-
parts.push(`${this.
|
|
463
|
+
if (this._days > 0 || options.showZeroValues) {
|
|
464
|
+
parts.push(`${this._days} ${this._days === 1 ? 'day' : 'days'}`);
|
|
416
465
|
}
|
|
417
|
-
if (this.
|
|
418
|
-
parts.push(`${this.
|
|
466
|
+
if (this._hours > 0 || options.showZeroValues) {
|
|
467
|
+
parts.push(`${this._hours} ${this._hours === 1 ? 'hour' : 'hours'}`);
|
|
419
468
|
}
|
|
420
|
-
if (this.
|
|
421
|
-
parts.push(`${this.
|
|
469
|
+
if (this._minutes > 0 || options.showZeroValues) {
|
|
470
|
+
parts.push(`${this._minutes} ${this._minutes === 1 ? 'minute' : 'minutes'}`);
|
|
422
471
|
}
|
|
423
|
-
if (this.
|
|
424
|
-
parts.push(`${this.
|
|
472
|
+
if (this._seconds > 0 || options.showZeroValues) {
|
|
473
|
+
parts.push(`${this._seconds} ${this._seconds === 1 ? 'second' : 'seconds'}`);
|
|
425
474
|
}
|
|
426
|
-
if (this.
|
|
427
|
-
parts.push(`${this.
|
|
475
|
+
if (this._milliseconds > 0 || options.showZeroValues) {
|
|
476
|
+
parts.push(`${this._milliseconds} ${this._milliseconds === 1 ? 'millisecond' : 'milliseconds'}`);
|
|
428
477
|
}
|
|
429
478
|
// Handle case where no parts were added
|
|
430
479
|
if (parts.length === 0) {
|
|
@@ -437,7 +486,7 @@ export class ElapsedTime {
|
|
|
437
486
|
const formatted = parts.join(' ');
|
|
438
487
|
// Apply negative formatting
|
|
439
488
|
if (this.IsNegative) {
|
|
440
|
-
return ElapsedTime.
|
|
489
|
+
return ElapsedTime._applyNegativeFormatting(formatted, options);
|
|
441
490
|
}
|
|
442
491
|
return formatted;
|
|
443
492
|
}
|
|
@@ -462,7 +511,7 @@ export class ElapsedTime {
|
|
|
462
511
|
* // Called automatically by Format() method for most format types
|
|
463
512
|
* ```
|
|
464
513
|
*/
|
|
465
|
-
|
|
514
|
+
_formatUsingTokens(options, formatKey = '', originalOptions = {}) {
|
|
466
515
|
// Define all available time units
|
|
467
516
|
const units = [
|
|
468
517
|
{ unit: 'week', value: this.Weeks },
|
|
@@ -473,21 +522,23 @@ export class ElapsedTime {
|
|
|
473
522
|
{ unit: 'millisecond', value: this.Milliseconds },
|
|
474
523
|
];
|
|
475
524
|
// Filter and limit units based on options
|
|
476
|
-
const filteredUnits = ElapsedTime.
|
|
525
|
+
const filteredUnits = ElapsedTime._filterAndLimitUnits(units, options);
|
|
477
526
|
const unitLabels = options.unitLabels ?? DEFAULT_UNIT_LABELS.medium;
|
|
527
|
+
// Determine if custom labels were explicitly provided by the user (not from format defaults)
|
|
528
|
+
const hasCustomLabels = originalOptions.unitLabels !== undefined;
|
|
478
529
|
// Determine the formatting approach based on the resolved format key.
|
|
479
530
|
// TIME and TIME_WITH_SECONDS use a colon-separated layout; all other
|
|
480
531
|
// predefined and custom formats use the standard token layout.
|
|
481
532
|
let formatted;
|
|
482
533
|
const isTimeFormat = formatKey === 'time' || formatKey === 'timeWithSeconds';
|
|
483
534
|
if (isTimeFormat) {
|
|
484
|
-
formatted = ElapsedTime.
|
|
535
|
+
formatted = ElapsedTime._formatTimeUnits(filteredUnits, unitLabels);
|
|
485
536
|
}
|
|
486
537
|
else {
|
|
487
538
|
// Handle different format types
|
|
488
|
-
formatted = ElapsedTime.
|
|
539
|
+
formatted = ElapsedTime._formatStandardUnits(filteredUnits, unitLabels, formatKey, hasCustomLabels);
|
|
489
540
|
}
|
|
490
|
-
return this.IsNegative ? ElapsedTime.
|
|
541
|
+
return this.IsNegative ? ElapsedTime._applyNegativeFormatting(formatted, options) : formatted;
|
|
491
542
|
}
|
|
492
543
|
/**
|
|
493
544
|
* Format time units for TIME and TIME_WITH_SECONDS formats
|
|
@@ -497,7 +548,7 @@ export class ElapsedTime {
|
|
|
497
548
|
* @returns Formatted time string with colons (e.g., "1:30:45")
|
|
498
549
|
* @private
|
|
499
550
|
*/
|
|
500
|
-
static
|
|
551
|
+
static _formatTimeUnits(units, unitLabels) {
|
|
501
552
|
return units.map(({ unit, value: _value }) => {
|
|
502
553
|
const labelFunc = unitLabels[unit];
|
|
503
554
|
if (!labelFunc)
|
|
@@ -510,10 +561,12 @@ export class ElapsedTime {
|
|
|
510
561
|
* Handles different formatting styles including CONCISE, SHORT, MEDIUM, LONG, and custom formats
|
|
511
562
|
* @param units - Array of time units with their values
|
|
512
563
|
* @param unitLabels - Object containing label definitions for each time unit
|
|
564
|
+
* @param formatKey - The format key (concise, short, medium, etc.)
|
|
565
|
+
* @param hasCustomLabels - Whether custom labels were provided by the user
|
|
513
566
|
* @returns Formatted time string according to the specified format style
|
|
514
567
|
* @private
|
|
515
568
|
*/
|
|
516
|
-
static
|
|
569
|
+
static _formatStandardUnits(units, unitLabels, formatKey = '', hasCustomLabels = false) {
|
|
517
570
|
// Function-based labels: invoke each label function with the value (e.g. pluralization)
|
|
518
571
|
if (Object.values(unitLabels).some((label) => typeof label === 'function')) {
|
|
519
572
|
return units.map(({ unit, value }) => {
|
|
@@ -524,15 +577,25 @@ export class ElapsedTime {
|
|
|
524
577
|
return `${value} ${label}`;
|
|
525
578
|
}).join(' ');
|
|
526
579
|
}
|
|
527
|
-
//
|
|
528
|
-
|
|
580
|
+
// Detect the format style from the labels object or fall back to formatKey.
|
|
581
|
+
// This check is more robust than reference equality: it works even if a copy
|
|
582
|
+
// of the DEFAULT_UNIT_LABELS object is passed by external code.
|
|
583
|
+
const labelStyle = unitLabels.style;
|
|
584
|
+
const style = labelStyle || formatKey;
|
|
585
|
+
// Check if these are truly custom labels (not from DEFAULT_UNIT_LABELS or a copy thereof).
|
|
586
|
+
// If the labels have a recognized style property, treat them as default-style labels.
|
|
587
|
+
const isDefaultStyle = labelStyle !== undefined && ['concise', 'short', 'medium', 'long'].includes(labelStyle);
|
|
588
|
+
const hasActuallyCustomLabels = hasCustomLabels && !isDefaultStyle;
|
|
589
|
+
// For CONCISE and SHORT formats with default labels (no custom override)
|
|
590
|
+
// No space between value and label (e.g., "1h 30m" or "1hr 30min")
|
|
591
|
+
if (!hasActuallyCustomLabels && (style === 'concise' || style === 'short')) {
|
|
529
592
|
return units.map(({ unit, value }) => `${value}${unitLabels[unit]}`).join(' ');
|
|
530
593
|
}
|
|
531
594
|
// For MEDIUM format (e.g., "1 hour 30 min")
|
|
532
|
-
if (
|
|
595
|
+
if (style === 'medium' || style === '') {
|
|
533
596
|
return units.map(({ unit, value }) => `${value} ${unitLabels[unit]}`).join(' ');
|
|
534
597
|
}
|
|
535
|
-
// Custom labels: join with a space so units are properly separated.
|
|
598
|
+
// Custom labels or other formats: join with a space so units are properly separated.
|
|
536
599
|
return units.map(({ unit, value }) => {
|
|
537
600
|
const label = unitLabels[unit];
|
|
538
601
|
if (typeof label === 'undefined')
|
|
@@ -563,7 +626,7 @@ export class ElapsedTime {
|
|
|
563
626
|
* // All zero values -> ensures at least "0 seconds" is shown
|
|
564
627
|
* ```
|
|
565
628
|
*/
|
|
566
|
-
static
|
|
629
|
+
static _filterAndLimitUnits(units, options) {
|
|
567
630
|
// Filter out zero values if not showing them
|
|
568
631
|
let filteredUnits = options.showZeroValues ? units : units.filter((item) => item.value > 0);
|
|
569
632
|
// Handle the case where all values are zero
|
|
@@ -596,7 +659,7 @@ export class ElapsedTime {
|
|
|
596
659
|
* // Empty: "1h 30m" -> "1h 30m" (no change)
|
|
597
660
|
* ```
|
|
598
661
|
*/
|
|
599
|
-
static
|
|
662
|
+
static _applyNegativeFormatting(output, options) {
|
|
600
663
|
switch (options.negativeValueFormat) {
|
|
601
664
|
case 'NegativeSign':
|
|
602
665
|
return `-${output}`;
|
|
@@ -612,7 +675,8 @@ export class ElapsedTime {
|
|
|
612
675
|
}
|
|
613
676
|
/**
|
|
614
677
|
* Formats elapsed time using the specified configuration.
|
|
615
|
-
*
|
|
678
|
+
* Convenience wrapper equivalent to `ElapsedTime.Format(milliseconds, 'concise', options)`.
|
|
679
|
+
* For other format styles, use {@link ElapsedTime.Format} directly.
|
|
616
680
|
*
|
|
617
681
|
* @param milliseconds - The total number of milliseconds to format
|
|
618
682
|
* @param options - Formatting configuration options
|
|
@@ -625,6 +689,37 @@ export class ElapsedTime {
|
|
|
625
689
|
* console.log(FormatElapsedTime(3661000)); // "1h 1m 1s"
|
|
626
690
|
* console.log(FormatElapsedTime(3661000, { maxUnits: 1 })); // "1h"
|
|
627
691
|
* ```
|
|
692
|
+
*
|
|
693
|
+
* @see ElapsedTime.Format
|
|
694
|
+
*/
|
|
695
|
+
/**
|
|
696
|
+
* Format elapsed time using the concise format with optional customization.
|
|
697
|
+
* Convenience function that creates a temporary ElapsedTime instance and formats it.
|
|
698
|
+
* Always uses the 'concise' format (e.g., "1h 30m 45s") with optional overrides.
|
|
699
|
+
*
|
|
700
|
+
* @param milliseconds - The total number of milliseconds to format
|
|
701
|
+
* @param options - Optional formatting configuration to customize maxUnits and unitLabels
|
|
702
|
+
* @returns The formatted time string in concise format
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* ```typescript
|
|
706
|
+
* // Basic usage with default concise format
|
|
707
|
+
* console.log(FormatElapsedTime(3661000)); // "1h 1m 1s"
|
|
708
|
+
* console.log(FormatElapsedTime(5425000)); // "1h 30m 25s"
|
|
709
|
+
*
|
|
710
|
+
* // With maxUnits option
|
|
711
|
+
* console.log(FormatElapsedTime(3661000, { maxUnits: 2 })); // "1h 1m"
|
|
712
|
+
*
|
|
713
|
+
* // With custom labels
|
|
714
|
+
* const options = {
|
|
715
|
+
* unitLabels: {
|
|
716
|
+
* hour: 'hrs',
|
|
717
|
+
* minute: 'mins',
|
|
718
|
+
* second: 'secs'
|
|
719
|
+
* }
|
|
720
|
+
* };
|
|
721
|
+
* console.log(FormatElapsedTime(3661000, options)); // "1 hrs 1 mins 1 secs"
|
|
722
|
+
* ```
|
|
628
723
|
*/
|
|
629
724
|
export function FormatElapsedTime(milliseconds, options) {
|
|
630
725
|
const elapsedTime = new ElapsedTime(milliseconds);
|
|
@@ -639,4 +734,3 @@ export function FormatElapsedTime(milliseconds, options) {
|
|
|
639
734
|
}
|
|
640
735
|
return elapsedTime.Format('concise', formatOptions);
|
|
641
736
|
}
|
|
642
|
-
//# sourceMappingURL=elapsed-time.js.map
|