@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IsPropertyPathSafe, IsPropertyKeySafe } from './security-utils.js';
|
|
2
2
|
/**
|
|
3
3
|
* Safely gets a nested property from an object using a path string with dot notation.
|
|
4
4
|
* Returns the default value if the path doesn't exist or any intermediate value is null/undefined.
|
|
@@ -59,14 +59,14 @@ export function ObjectGetPropertyByPath(obj, path, defaultValue) {
|
|
|
59
59
|
return defaultValue;
|
|
60
60
|
}
|
|
61
61
|
// Security validation: Check if the path is safe
|
|
62
|
-
if (!
|
|
62
|
+
if (!IsPropertyPathSafe(path)) {
|
|
63
63
|
return defaultValue;
|
|
64
64
|
}
|
|
65
65
|
const keys = path.split('.');
|
|
66
66
|
let result = obj;
|
|
67
67
|
for (const key of keys) {
|
|
68
68
|
// Security check for each key
|
|
69
|
-
if (!
|
|
69
|
+
if (!IsPropertyKeySafe(key)) {
|
|
70
70
|
return defaultValue;
|
|
71
71
|
}
|
|
72
72
|
if (result === null || result === undefined || typeof result !== 'object') {
|
|
@@ -95,6 +95,8 @@ export function ObjectGetPropertyByPath(obj, path, defaultValue) {
|
|
|
95
95
|
* @param obj - Target object to modify
|
|
96
96
|
* @param path - Path to the property using dot notation (e.g., 'user.address.street')
|
|
97
97
|
* @param value - Value to set at the specified path
|
|
98
|
+
* @throws Throws if `path` contains dangerous keys (`__proto__`, `constructor`, `prototype`)
|
|
99
|
+
* @throws Throws if `path` is invalid or contains non-string segments
|
|
98
100
|
*
|
|
99
101
|
* @example
|
|
100
102
|
* ```typescript
|
|
@@ -147,7 +149,7 @@ export function ObjectSetPropertyByPath(obj, path, value) {
|
|
|
147
149
|
return;
|
|
148
150
|
}
|
|
149
151
|
// Security validation: Check if the path is safe
|
|
150
|
-
if (!
|
|
152
|
+
if (!IsPropertyPathSafe(path)) {
|
|
151
153
|
return;
|
|
152
154
|
}
|
|
153
155
|
const keys = path.split('.');
|
|
@@ -156,13 +158,13 @@ export function ObjectSetPropertyByPath(obj, path, value) {
|
|
|
156
158
|
return;
|
|
157
159
|
}
|
|
158
160
|
// Additional security check for the final key
|
|
159
|
-
if (!
|
|
161
|
+
if (!IsPropertyKeySafe(lastKey)) {
|
|
160
162
|
return;
|
|
161
163
|
}
|
|
162
164
|
let current = obj;
|
|
163
165
|
for (const key of keys) {
|
|
164
166
|
// Security check for each intermediate key
|
|
165
|
-
if (!
|
|
167
|
+
if (!IsPropertyKeySafe(key)) {
|
|
166
168
|
return;
|
|
167
169
|
}
|
|
168
170
|
if (current[key] === null || current[key] === undefined || typeof current[key] !== 'object') {
|
|
@@ -172,4 +174,3 @@ export function ObjectSetPropertyByPath(obj, path, value) {
|
|
|
172
174
|
}
|
|
173
175
|
current[lastKey] = value;
|
|
174
176
|
}
|
|
175
|
-
//# sourceMappingURL=property-paths.js.map
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security utilities for object manipulation functions
|
|
3
|
+
* Provides protection against prototype pollution, path traversal, and other security vulnerabilities
|
|
4
|
+
*
|
|
5
|
+
* Sensitive data patterns considered by these utilities include:
|
|
6
|
+
* - Prototype pollution vectors: `__proto__`, `constructor`, `prototype`
|
|
7
|
+
* - Path traversal sequences: `..`, encoded dots (`%2e%2e`, `%252e%252e`)
|
|
8
|
+
* - Null byte injections: `\0`, `%00`
|
|
9
|
+
* - Unicode attacks: BOM characters, reversed BOM, invalid unicode sequences
|
|
10
|
+
* - Malformed input: consecutive dots, leading/trailing dots, empty segments
|
|
11
|
+
*
|
|
12
|
+
* @author Security Auditor Agent
|
|
13
|
+
* @version 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Validates if a property key is safe to use (not dangerous for prototype pollution)
|
|
17
|
+
*
|
|
18
|
+
* Blocks dangerous property names and path traversal patterns:
|
|
19
|
+
* - Prototype pollution vectors: `__proto__`, `constructor`, `prototype`
|
|
20
|
+
* - Path traversal: `..`, URL-encoded variants (`%2e%2e`, `%252e%252e`)
|
|
21
|
+
* - Null bytes: `\0` (literal), `%00` (URL-encoded)
|
|
22
|
+
* - Unicode attacks: BOM characters and invalid sequences
|
|
23
|
+
*
|
|
24
|
+
* @param key - The property key to validate
|
|
25
|
+
* @returns True if the key is safe to use as an object property, false if it's a known attack vector
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* IsPropertyKeySafe('name'); // true
|
|
30
|
+
* IsPropertyKeySafe('user_id'); // true
|
|
31
|
+
* IsPropertyKeySafe('__proto__'); // false (prototype pollution)
|
|
32
|
+
* IsPropertyKeySafe('constructor'); // false (prototype pollution)
|
|
33
|
+
* IsPropertyKeySafe('..'); // false (path traversal)
|
|
34
|
+
* IsPropertyKeySafe('%2e%2e'); // false (encoded path traversal)
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function IsPropertyKeySafe(key: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Validates a property path for security issues
|
|
40
|
+
*
|
|
41
|
+
* Detects and blocks malformed or dangerous paths:
|
|
42
|
+
* - Leading or trailing dots: `.name`, `path.`
|
|
43
|
+
* - Consecutive dots: `user..name` (double dot traversal)
|
|
44
|
+
* - Each path segment is validated via `IsPropertyKeySafe`
|
|
45
|
+
*
|
|
46
|
+
* Used by `ObjectGetPropertyByPath` and `ObjectSetPropertyByPath` to prevent
|
|
47
|
+
* prototype pollution and path traversal attacks. Safe for untrusted input
|
|
48
|
+
* when `validatePaths: true` is passed to ObjectFilter.
|
|
49
|
+
*
|
|
50
|
+
* @param path - The property path to validate using dot notation (e.g., `user.profile.name`)
|
|
51
|
+
* @returns True if the path is safe, false if it contains security risks
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* IsPropertyPathSafe('user.profile.name'); // true
|
|
56
|
+
* IsPropertyPathSafe('user..name'); // false (double dot)
|
|
57
|
+
* IsPropertyPathSafe('.user.name'); // false (leading dot)
|
|
58
|
+
* IsPropertyPathSafe('user.name.'); // false (trailing dot)
|
|
59
|
+
* IsPropertyPathSafe('user.__proto__.name'); // false (dangerous segment)
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function IsPropertyPathSafe(path: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Sanitizes a property key by removing or replacing dangerous characters
|
|
65
|
+
*
|
|
66
|
+
* Returns `null` if the key contains dangerous patterns (prototype pollution vectors,
|
|
67
|
+
* path traversal sequences) that cannot be safely sanitized. Otherwise returns the
|
|
68
|
+
* key with leading/trailing whitespace trimmed.
|
|
69
|
+
*
|
|
70
|
+
* @param key - The property key to sanitize
|
|
71
|
+
* @returns The sanitized key (with whitespace trimmed), or `null` if the key is dangerous
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* SanitizePropertyKey(' user.name '); // 'user.name'
|
|
76
|
+
* SanitizePropertyKey('__proto__'); // null (dangerous)
|
|
77
|
+
* SanitizePropertyKey('valid-key'); // 'valid-key'
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export declare function SanitizePropertyKey(key: string): string | null;
|
|
81
|
+
/**
|
|
82
|
+
* Filters out dangerous keys from an object
|
|
83
|
+
*
|
|
84
|
+
* Creates a new object containing only properties whose keys pass the `IsPropertyKeySafe` check.
|
|
85
|
+
* Blocks prototype pollution vectors: `__proto__`, `constructor`, `prototype`.
|
|
86
|
+
* Safe for untrusted input. Used internally by ObjectClone and ObjectMerge.
|
|
87
|
+
*
|
|
88
|
+
* @template T - The type of the object
|
|
89
|
+
* @param obj - The object to filter
|
|
90
|
+
* @returns New object with only safe keys (subset of input properties)
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* FilterDangerousKeys({ name: 'John', __proto__: {}, valid: true });
|
|
95
|
+
* // { name: 'John', valid: true }
|
|
96
|
+
*
|
|
97
|
+
* FilterDangerousKeys({ a: 1, constructor: 'bad', b: 2 });
|
|
98
|
+
* // { a: 1, b: 2 }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function FilterDangerousKeys<T extends Record<string, unknown>>(obj: T): Partial<T>;
|
|
102
|
+
/**
|
|
103
|
+
* Interface for circular reference detection utility
|
|
104
|
+
*
|
|
105
|
+
* Provides methods to track visited objects during recursive traversal,
|
|
106
|
+
* enabling detection and handling of circular references in object graphs.
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* Uses a WeakSet internally for memory-efficient object tracking. Suitable for
|
|
110
|
+
* single-threaded traversal; not thread-safe for concurrent use.
|
|
111
|
+
*/
|
|
112
|
+
export interface ICircularReferenceDetector {
|
|
113
|
+
/**
|
|
114
|
+
* Marks an object as visited
|
|
115
|
+
* @param obj - Object to mark as visited
|
|
116
|
+
*/
|
|
117
|
+
markVisited(obj: object): void;
|
|
118
|
+
/**
|
|
119
|
+
* Checks if an object has been visited (circular reference indicator)
|
|
120
|
+
* @param obj - Object to check
|
|
121
|
+
* @returns True if object was already marked as visited
|
|
122
|
+
*/
|
|
123
|
+
isVisited(obj: object): boolean;
|
|
124
|
+
/**
|
|
125
|
+
* Clears all visited object entries, resetting the detector
|
|
126
|
+
*/
|
|
127
|
+
clear(): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Creates a circular reference detection utility using WeakSet
|
|
131
|
+
*
|
|
132
|
+
* Provides an efficient way to track visited objects during recursive traversal
|
|
133
|
+
* of object graphs, enabling detection and handling of circular references.
|
|
134
|
+
* The internal WeakSet allows garbage collection of visited objects when they
|
|
135
|
+
* are no longer referenced elsewhere.
|
|
136
|
+
*
|
|
137
|
+
* @returns An {@link ICircularReferenceDetector} instance with methods to track visited objects
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* // Create detector once and reuse across multiple calls:
|
|
142
|
+
* const detector = CreateCircularReferenceDetector();
|
|
143
|
+
*
|
|
144
|
+
* function traverse(obj: unknown): void {
|
|
145
|
+
* if (typeof obj !== 'object' || obj === null) return;
|
|
146
|
+
*
|
|
147
|
+
* if (detector.isVisited(obj)) {
|
|
148
|
+
* console.log('Circular reference detected!');
|
|
149
|
+
* return;
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
* detector.markVisited(obj);
|
|
153
|
+
* // Process obj...
|
|
154
|
+
* }
|
|
155
|
+
*
|
|
156
|
+
* for (const obj of objects) {
|
|
157
|
+
* detector.clear(); // Reset between unrelated traversals
|
|
158
|
+
* traverse(obj);
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @remarks
|
|
163
|
+
* Do NOT create a new detector inside a loop for each object. Create once and reuse,
|
|
164
|
+
* calling `clear()` between unrelated traversals. Each call to this function creates
|
|
165
|
+
* a new WeakSet instance, so reusing is more efficient.
|
|
166
|
+
*/
|
|
167
|
+
export declare function CreateCircularReferenceDetector(): ICircularReferenceDetector;
|
|
168
|
+
/**
|
|
169
|
+
* Validates input for common security issues
|
|
170
|
+
*
|
|
171
|
+
* Checks for:
|
|
172
|
+
* - String length exceeding `maxLength` (default: 10,000 chars) to prevent DoS
|
|
173
|
+
* - Path traversal patterns: `..`, encoded variants, null bytes, unicode attacks
|
|
174
|
+
* - Null/undefined are considered safe (falsy validation only)
|
|
175
|
+
*
|
|
176
|
+
* Designed primarily for property path validation in `ObjectSetPropertyByPath` and
|
|
177
|
+
* related functions. Not a general-purpose string validator.
|
|
178
|
+
*
|
|
179
|
+
* @param input - Input to validate (typically a property path or key string)
|
|
180
|
+
* @param maxLength - Maximum allowed string length in characters (default: 10,000)
|
|
181
|
+
* @returns True if input is safe, false if it exceeds length or contains attack patterns
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```typescript
|
|
185
|
+
* IsInputSafe('user.profile.name'); // true
|
|
186
|
+
* IsInputSafe('user..name'); // false (path traversal)
|
|
187
|
+
* IsInputSafe('a'.repeat(20000)); // false (exceeds default length)
|
|
188
|
+
* IsInputSafe(null); // true (null is safe)
|
|
189
|
+
* IsInputSafe('%2e%2e'); // false (encoded traversal)
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function IsInputSafe(input: unknown, maxLength?: number): boolean;
|
|
193
|
+
//# sourceMappingURL=security-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security-utils.d.ts","sourceRoot":"","sources":["../../src/object/security-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAsDH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAkBtD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAkBxD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO9D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAUzF;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;;;OAIG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,+BAA+B,IAAI,0BAA0B,CA6B5E;AAKD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,MAAiC,GAAG,OAAO,CAqBjG"}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security utilities for object manipulation functions
|
|
3
|
+
* Provides protection against prototype pollution, path traversal, and other security vulnerabilities
|
|
4
|
+
*
|
|
5
|
+
* Sensitive data patterns considered by these utilities include:
|
|
6
|
+
* - Prototype pollution vectors: `__proto__`, `constructor`, `prototype`
|
|
7
|
+
* - Path traversal sequences: `..`, encoded dots (`%2e%2e`, `%252e%252e`)
|
|
8
|
+
* - Null byte injections: `\0`, `%00`
|
|
9
|
+
* - Unicode attacks: BOM characters, reversed BOM, invalid unicode sequences
|
|
10
|
+
* - Malformed input: consecutive dots, leading/trailing dots, empty segments
|
|
11
|
+
*
|
|
12
|
+
* @author Security Auditor Agent
|
|
13
|
+
* @version 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* List of dangerous property names that should be blocked to prevent prototype pollution.
|
|
17
|
+
* Only the three canonical prototype-pollution vectors are blocked; other Object.prototype
|
|
18
|
+
* methods (toString, valueOf, hasOwnProperty, etc.) are legitimate property names.
|
|
19
|
+
*/
|
|
20
|
+
const /**
|
|
21
|
+
* Property names that are commonly used in prototype pollution attacks.
|
|
22
|
+
*
|
|
23
|
+
* This list blocks direct assignment to the most common attack vectors
|
|
24
|
+
* (__proto__, constructor, prototype) but is not a complete sandbox.
|
|
25
|
+
* It prevents the most obvious exploitation paths and should be combined
|
|
26
|
+
* with other security measures such as object freezing and deep cloning
|
|
27
|
+
* for sensitive data structures.
|
|
28
|
+
*/ DANGEROUS_PROPERTY_NAMES = new Set([
|
|
29
|
+
'__proto__',
|
|
30
|
+
'constructor',
|
|
31
|
+
'prototype',
|
|
32
|
+
]);
|
|
33
|
+
/**
|
|
34
|
+
* Regular expression patterns for detecting path traversal attempts.
|
|
35
|
+
*
|
|
36
|
+
* Includes:
|
|
37
|
+
* - URL-encoded dots (both single and double encoding)
|
|
38
|
+
* - Null byte injection (both as \0 literal and %00 URL-encoded)
|
|
39
|
+
* - Unicode BOM and invalid character sequences
|
|
40
|
+
*
|
|
41
|
+
* NOTE: Null byte detection is informational and defensive-in-depth.
|
|
42
|
+
* JavaScript strings handle null bytes safely by design — they do not
|
|
43
|
+
* truncate at null bytes like C strings do. This pattern is included
|
|
44
|
+
* to flag suspicious input that may have been crafted for other contexts.
|
|
45
|
+
*
|
|
46
|
+
* PERFORMANCE NOTE: All patterns avoid nested quantifiers that could cause
|
|
47
|
+
* ReDoS (Regular Expression Denial of Service). Each pattern is simple and
|
|
48
|
+
* anchored to prevent catastrophic backtracking.
|
|
49
|
+
*/
|
|
50
|
+
const PATH_TRAVERSAL_PATTERNS = [
|
|
51
|
+
/\.\./, // ASCII parent directory (..)
|
|
52
|
+
/\//, // ASCII solidus (forward slash)
|
|
53
|
+
/%2e%2e/i, // URL encoded ..
|
|
54
|
+
/%2f/i, // URL encoded solidus
|
|
55
|
+
/%252e%252e/i, // Double URL encoded ..
|
|
56
|
+
/%252f/i, // Double URL encoded solidus
|
|
57
|
+
/../, // Fullwidth parent directory (U+FF0E U+FF0E)
|
|
58
|
+
///, // Fullwidth solidus (U+FF0F)
|
|
59
|
+
/∕/, // Division slash (U+2215)
|
|
60
|
+
new RegExp(String.fromCharCode(0)), // Null byte injection
|
|
61
|
+
/%00/i, // URL encoded null byte
|
|
62
|
+
new RegExp('[]'), // Unicode BOM, reversed BOM, and invalid characters
|
|
63
|
+
];
|
|
64
|
+
/**
|
|
65
|
+
* Validates if a property key is safe to use (not dangerous for prototype pollution)
|
|
66
|
+
*
|
|
67
|
+
* Blocks dangerous property names and path traversal patterns:
|
|
68
|
+
* - Prototype pollution vectors: `__proto__`, `constructor`, `prototype`
|
|
69
|
+
* - Path traversal: `..`, URL-encoded variants (`%2e%2e`, `%252e%252e`)
|
|
70
|
+
* - Null bytes: `\0` (literal), `%00` (URL-encoded)
|
|
71
|
+
* - Unicode attacks: BOM characters and invalid sequences
|
|
72
|
+
*
|
|
73
|
+
* @param key - The property key to validate
|
|
74
|
+
* @returns True if the key is safe to use as an object property, false if it's a known attack vector
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* IsPropertyKeySafe('name'); // true
|
|
79
|
+
* IsPropertyKeySafe('user_id'); // true
|
|
80
|
+
* IsPropertyKeySafe('__proto__'); // false (prototype pollution)
|
|
81
|
+
* IsPropertyKeySafe('constructor'); // false (prototype pollution)
|
|
82
|
+
* IsPropertyKeySafe('..'); // false (path traversal)
|
|
83
|
+
* IsPropertyKeySafe('%2e%2e'); // false (encoded path traversal)
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export function IsPropertyKeySafe(key) {
|
|
87
|
+
if (typeof key !== 'string') {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
// Check against dangerous property names
|
|
91
|
+
if (DANGEROUS_PROPERTY_NAMES.has(key)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
// Check for path traversal patterns
|
|
95
|
+
for (const pattern of PATH_TRAVERSAL_PATTERNS) {
|
|
96
|
+
if (pattern.test(key)) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Validates a property path for security issues
|
|
104
|
+
*
|
|
105
|
+
* Detects and blocks malformed or dangerous paths:
|
|
106
|
+
* - Leading or trailing dots: `.name`, `path.`
|
|
107
|
+
* - Consecutive dots: `user..name` (double dot traversal)
|
|
108
|
+
* - Each path segment is validated via `IsPropertyKeySafe`
|
|
109
|
+
*
|
|
110
|
+
* Used by `ObjectGetPropertyByPath` and `ObjectSetPropertyByPath` to prevent
|
|
111
|
+
* prototype pollution and path traversal attacks. Safe for untrusted input
|
|
112
|
+
* when `validatePaths: true` is passed to ObjectFilter.
|
|
113
|
+
*
|
|
114
|
+
* @param path - The property path to validate using dot notation (e.g., `user.profile.name`)
|
|
115
|
+
* @returns True if the path is safe, false if it contains security risks
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* IsPropertyPathSafe('user.profile.name'); // true
|
|
120
|
+
* IsPropertyPathSafe('user..name'); // false (double dot)
|
|
121
|
+
* IsPropertyPathSafe('.user.name'); // false (leading dot)
|
|
122
|
+
* IsPropertyPathSafe('user.name.'); // false (trailing dot)
|
|
123
|
+
* IsPropertyPathSafe('user.__proto__.name'); // false (dangerous segment)
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function IsPropertyPathSafe(path) {
|
|
127
|
+
if (!path || typeof path !== 'string') {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
// Check if path starts or ends with a dot
|
|
131
|
+
if (path.startsWith('.') || path.endsWith('.')) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
// Check for consecutive dots (potential traversal)
|
|
135
|
+
if (path.includes('..')) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
// Validate each segment of the path
|
|
139
|
+
const segments = path.split('.');
|
|
140
|
+
return segments.every((segment) => IsPropertyKeySafe(segment));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Sanitizes a property key by removing or replacing dangerous characters
|
|
144
|
+
*
|
|
145
|
+
* Returns `null` if the key contains dangerous patterns (prototype pollution vectors,
|
|
146
|
+
* path traversal sequences) that cannot be safely sanitized. Otherwise returns the
|
|
147
|
+
* key with leading/trailing whitespace trimmed.
|
|
148
|
+
*
|
|
149
|
+
* @param key - The property key to sanitize
|
|
150
|
+
* @returns The sanitized key (with whitespace trimmed), or `null` if the key is dangerous
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* SanitizePropertyKey(' user.name '); // 'user.name'
|
|
155
|
+
* SanitizePropertyKey('__proto__'); // null (dangerous)
|
|
156
|
+
* SanitizePropertyKey('valid-key'); // 'valid-key'
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
export function SanitizePropertyKey(key) {
|
|
160
|
+
if (!IsPropertyKeySafe(key)) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
// Additional sanitization for edge cases
|
|
164
|
+
return key.trim();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Filters out dangerous keys from an object
|
|
168
|
+
*
|
|
169
|
+
* Creates a new object containing only properties whose keys pass the `IsPropertyKeySafe` check.
|
|
170
|
+
* Blocks prototype pollution vectors: `__proto__`, `constructor`, `prototype`.
|
|
171
|
+
* Safe for untrusted input. Used internally by ObjectClone and ObjectMerge.
|
|
172
|
+
*
|
|
173
|
+
* @template T - The type of the object
|
|
174
|
+
* @param obj - The object to filter
|
|
175
|
+
* @returns New object with only safe keys (subset of input properties)
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* FilterDangerousKeys({ name: 'John', __proto__: {}, valid: true });
|
|
180
|
+
* // { name: 'John', valid: true }
|
|
181
|
+
*
|
|
182
|
+
* FilterDangerousKeys({ a: 1, constructor: 'bad', b: 2 });
|
|
183
|
+
* // { a: 1, b: 2 }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export function FilterDangerousKeys(obj) {
|
|
187
|
+
const filtered = {};
|
|
188
|
+
for (const key in obj) {
|
|
189
|
+
if (Object.hasOwn(obj, key) && IsPropertyKeySafe(key)) {
|
|
190
|
+
filtered[key] = obj[key];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return filtered;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Creates a circular reference detection utility using WeakSet
|
|
197
|
+
*
|
|
198
|
+
* Provides an efficient way to track visited objects during recursive traversal
|
|
199
|
+
* of object graphs, enabling detection and handling of circular references.
|
|
200
|
+
* The internal WeakSet allows garbage collection of visited objects when they
|
|
201
|
+
* are no longer referenced elsewhere.
|
|
202
|
+
*
|
|
203
|
+
* @returns An {@link ICircularReferenceDetector} instance with methods to track visited objects
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // Create detector once and reuse across multiple calls:
|
|
208
|
+
* const detector = CreateCircularReferenceDetector();
|
|
209
|
+
*
|
|
210
|
+
* function traverse(obj: unknown): void {
|
|
211
|
+
* if (typeof obj !== 'object' || obj === null) return;
|
|
212
|
+
*
|
|
213
|
+
* if (detector.isVisited(obj)) {
|
|
214
|
+
* console.log('Circular reference detected!');
|
|
215
|
+
* return;
|
|
216
|
+
* }
|
|
217
|
+
*
|
|
218
|
+
* detector.markVisited(obj);
|
|
219
|
+
* // Process obj...
|
|
220
|
+
* }
|
|
221
|
+
*
|
|
222
|
+
* for (const obj of objects) {
|
|
223
|
+
* detector.clear(); // Reset between unrelated traversals
|
|
224
|
+
* traverse(obj);
|
|
225
|
+
* }
|
|
226
|
+
* ```
|
|
227
|
+
*
|
|
228
|
+
* @remarks
|
|
229
|
+
* Do NOT create a new detector inside a loop for each object. Create once and reuse,
|
|
230
|
+
* calling `clear()` between unrelated traversals. Each call to this function creates
|
|
231
|
+
* a new WeakSet instance, so reusing is more efficient.
|
|
232
|
+
*/
|
|
233
|
+
export function CreateCircularReferenceDetector() {
|
|
234
|
+
let visited = new WeakSet();
|
|
235
|
+
return {
|
|
236
|
+
/**
|
|
237
|
+
* Marks an object as visited
|
|
238
|
+
* @param obj - Object to mark as visited
|
|
239
|
+
*/
|
|
240
|
+
markVisited(obj) {
|
|
241
|
+
visited.add(obj);
|
|
242
|
+
},
|
|
243
|
+
/**
|
|
244
|
+
* Checks if an object has been visited (circular reference)
|
|
245
|
+
* @param obj - Object to check
|
|
246
|
+
* @returns True if object was already visited
|
|
247
|
+
*/
|
|
248
|
+
isVisited(obj) {
|
|
249
|
+
return visited.has(obj);
|
|
250
|
+
},
|
|
251
|
+
/**
|
|
252
|
+
* Clears the visited objects set
|
|
253
|
+
*/
|
|
254
|
+
clear() {
|
|
255
|
+
// WeakSet doesn't have a clear method, so we create a new one
|
|
256
|
+
visited = new WeakSet();
|
|
257
|
+
},
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
/** Default maximum input length for security validation */
|
|
261
|
+
const DEFAULT_MAX_INPUT_LENGTH = 10000;
|
|
262
|
+
/**
|
|
263
|
+
* Validates input for common security issues
|
|
264
|
+
*
|
|
265
|
+
* Checks for:
|
|
266
|
+
* - String length exceeding `maxLength` (default: 10,000 chars) to prevent DoS
|
|
267
|
+
* - Path traversal patterns: `..`, encoded variants, null bytes, unicode attacks
|
|
268
|
+
* - Null/undefined are considered safe (falsy validation only)
|
|
269
|
+
*
|
|
270
|
+
* Designed primarily for property path validation in `ObjectSetPropertyByPath` and
|
|
271
|
+
* related functions. Not a general-purpose string validator.
|
|
272
|
+
*
|
|
273
|
+
* @param input - Input to validate (typically a property path or key string)
|
|
274
|
+
* @param maxLength - Maximum allowed string length in characters (default: 10,000)
|
|
275
|
+
* @returns True if input is safe, false if it exceeds length or contains attack patterns
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* IsInputSafe('user.profile.name'); // true
|
|
280
|
+
* IsInputSafe('user..name'); // false (path traversal)
|
|
281
|
+
* IsInputSafe('a'.repeat(20000)); // false (exceeds default length)
|
|
282
|
+
* IsInputSafe(null); // true (null is safe)
|
|
283
|
+
* IsInputSafe('%2e%2e'); // false (encoded traversal)
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
286
|
+
export function IsInputSafe(input, maxLength = DEFAULT_MAX_INPUT_LENGTH) {
|
|
287
|
+
// Check for null/undefined
|
|
288
|
+
if (input === null || input === undefined) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
// Check string length to prevent DoS
|
|
292
|
+
if (typeof input === 'string' && input.length > maxLength) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
// Check for dangerous string patterns
|
|
296
|
+
if (typeof input === 'string') {
|
|
297
|
+
for (const pattern of PATH_TRAVERSAL_PATTERNS) {
|
|
298
|
+
if (pattern.test(input)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
@@ -22,5 +22,19 @@
|
|
|
22
22
|
* // Result: { active: true, age: 30, email: 'john@example.com', name: 'John' }
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Sorts the enumerable keys of an object in ascending order.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* - Sorts only enumerable keys; non-enumerable properties are preserved in-place
|
|
30
|
+
* - Symbol keys are not sorted (enumerable symbols appear in creation order)
|
|
31
|
+
* - Returns a new object with sorted enumerable keys and all non-enumerable properties
|
|
32
|
+
*
|
|
33
|
+
* @param object - The object to sort
|
|
34
|
+
* @returns A new object with sorted enumerable keys
|
|
35
|
+
* @example
|
|
36
|
+
* const obj = { z: 1, a: 2, m: 3 };
|
|
37
|
+
* ObjectSortKeys(obj); // { a: 2, m: 3, z: 1 }
|
|
38
|
+
*/
|
|
39
|
+
export declare function ObjectSortKeys<T extends Record<string, unknown>>(object: T): T;
|
|
26
40
|
//# sourceMappingURL=sort-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-keys.d.ts","sourceRoot":"","sources":["../../src/object/sort-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAuC9E"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sorts the keys of an object alphabetically and returns a new object with the same type
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the input object
|
|
5
|
+
* @param object - Object whose keys should be sorted
|
|
6
|
+
* @returns A new object with sorted keys maintaining the original type
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const input = { z: 1, a: 2, m: 3 };
|
|
11
|
+
* const sorted = ObjectSortKeys(input);
|
|
12
|
+
* // Result: { a: 2, m: 3, z: 1 }
|
|
13
|
+
*
|
|
14
|
+
* // With complex object
|
|
15
|
+
* const user = {
|
|
16
|
+
* name: 'John',
|
|
17
|
+
* age: 30,
|
|
18
|
+
* email: 'john@example.com',
|
|
19
|
+
* active: true
|
|
20
|
+
* };
|
|
21
|
+
* const sortedUser = ObjectSortKeys(user);
|
|
22
|
+
* // Result: { active: true, age: 30, email: 'john@example.com', name: 'John' }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Sorts the enumerable keys of an object in ascending order.
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* - Sorts only enumerable keys; non-enumerable properties are preserved in-place
|
|
30
|
+
* - Symbol keys are not sorted (enumerable symbols appear in creation order)
|
|
31
|
+
* - Returns a new object with sorted enumerable keys and all non-enumerable properties
|
|
32
|
+
*
|
|
33
|
+
* @param object - The object to sort
|
|
34
|
+
* @returns A new object with sorted enumerable keys
|
|
35
|
+
* @example
|
|
36
|
+
* const obj = { z: 1, a: 2, m: 3 };
|
|
37
|
+
* ObjectSortKeys(obj); // { a: 2, m: 3, z: 1 }
|
|
38
|
+
*/
|
|
39
|
+
export function ObjectSortKeys(object) {
|
|
40
|
+
if (!object || typeof object !== 'object' || Array.isArray(object)) {
|
|
41
|
+
return object;
|
|
42
|
+
}
|
|
43
|
+
// Single-pass collection: get all property names and classify them by enumerability
|
|
44
|
+
const allKeys = Object.getOwnPropertyNames(object);
|
|
45
|
+
const enumerableKeys = [];
|
|
46
|
+
const nonEnumerableDescriptors = [];
|
|
47
|
+
for (const key of allKeys) {
|
|
48
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
49
|
+
if (descriptor?.enumerable) {
|
|
50
|
+
enumerableKeys.push(key);
|
|
51
|
+
}
|
|
52
|
+
else if (descriptor) {
|
|
53
|
+
nonEnumerableDescriptors.push([key, descriptor]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// Sort enumerable keys and build result with them
|
|
57
|
+
const sorted = enumerableKeys.sort((a, b) => {
|
|
58
|
+
if (a < b)
|
|
59
|
+
return -1;
|
|
60
|
+
if (a > b)
|
|
61
|
+
return 1;
|
|
62
|
+
return 0;
|
|
63
|
+
})
|
|
64
|
+
.reduce((entry, key) => {
|
|
65
|
+
entry[key] = object[key];
|
|
66
|
+
return entry;
|
|
67
|
+
}, {});
|
|
68
|
+
// Restore non-enumerable properties with their original descriptors
|
|
69
|
+
for (const [key, descriptor] of nonEnumerableDescriptors) {
|
|
70
|
+
Object.defineProperty(sorted, key, descriptor);
|
|
71
|
+
}
|
|
72
|
+
return sorted;
|
|
73
|
+
}
|