@pawells/typescript-common 1.1.6 → 1.2.0

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.
Files changed (128) hide show
  1. package/README.md +32 -6
  2. package/build/array/array-chunk.js +1 -1
  3. package/build/array/array-chunk.js.map +1 -1
  4. package/build/array/array-contains.d.ts +1 -1
  5. package/build/array/array-contains.d.ts.map +1 -1
  6. package/build/array/array-count-by.d.ts +1 -1
  7. package/build/array/array-count-by.d.ts.map +1 -1
  8. package/build/array/array-difference.d.ts +1 -1
  9. package/build/array/array-difference.d.ts.map +1 -1
  10. package/build/array/array-filter.d.ts +1 -1
  11. package/build/array/array-filter.d.ts.map +1 -1
  12. package/build/array/array-filter.js +5 -0
  13. package/build/array/array-filter.js.map +1 -1
  14. package/build/array/array-group-by.d.ts +1 -1
  15. package/build/array/array-group-by.d.ts.map +1 -1
  16. package/build/array/array-intersection.d.ts +1 -1
  17. package/build/array/array-intersection.d.ts.map +1 -1
  18. package/build/array/array-partition.d.ts +1 -1
  19. package/build/array/array-partition.d.ts.map +1 -1
  20. package/build/array/array-sort-by.d.ts +1 -1
  21. package/build/array/array-sort-by.d.ts.map +1 -1
  22. package/build/array/assert.d.ts +17 -24
  23. package/build/array/assert.d.ts.map +1 -1
  24. package/build/array/assert.js +13 -21
  25. package/build/array/assert.js.map +1 -1
  26. package/build/asserts/errors.d.ts +18 -0
  27. package/build/asserts/errors.d.ts.map +1 -1
  28. package/build/asserts/errors.js +23 -0
  29. package/build/asserts/errors.js.map +1 -1
  30. package/build/asserts/generic.d.ts +19 -20
  31. package/build/asserts/generic.d.ts.map +1 -1
  32. package/build/asserts/generic.js +19 -34
  33. package/build/asserts/generic.js.map +1 -1
  34. package/build/asserts/internal-utils.d.ts +1 -44
  35. package/build/asserts/internal-utils.d.ts.map +1 -1
  36. package/build/asserts/internal-utils.js +2 -104
  37. package/build/asserts/internal-utils.js.map +1 -1
  38. package/build/boolean/assert.d.ts +2 -1
  39. package/build/boolean/assert.d.ts.map +1 -1
  40. package/build/boolean/assert.js +2 -3
  41. package/build/boolean/assert.js.map +1 -1
  42. package/build/function/memoize.d.ts +2 -1
  43. package/build/function/memoize.d.ts.map +1 -1
  44. package/build/function/memoize.js +4 -7
  45. package/build/function/memoize.js.map +1 -1
  46. package/build/function/once.d.ts.map +1 -1
  47. package/build/function/once.js +14 -2
  48. package/build/function/once.js.map +1 -1
  49. package/build/function/throttle.d.ts.map +1 -1
  50. package/build/function/throttle.js +4 -2
  51. package/build/function/throttle.js.map +1 -1
  52. package/build/index.d.ts +5 -4
  53. package/build/index.d.ts.map +1 -1
  54. package/build/index.js +6 -5
  55. package/build/index.js.map +1 -1
  56. package/build/lru-cache.d.ts +105 -0
  57. package/build/lru-cache.d.ts.map +1 -0
  58. package/build/lru-cache.js +139 -0
  59. package/build/lru-cache.js.map +1 -0
  60. package/build/number/assert.d.ts +2 -1
  61. package/build/number/assert.d.ts.map +1 -1
  62. package/build/number/assert.js +2 -5
  63. package/build/number/assert.js.map +1 -1
  64. package/build/object/assert-object.d.ts +13 -2
  65. package/build/object/assert-object.d.ts.map +1 -1
  66. package/build/object/assert-object.js +13 -2
  67. package/build/object/assert-object.js.map +1 -1
  68. package/build/object/assert.d.ts +4 -3
  69. package/build/object/assert.d.ts.map +1 -1
  70. package/build/object/assert.js +5 -8
  71. package/build/object/assert.js.map +1 -1
  72. package/build/object/clone.d.ts.map +1 -1
  73. package/build/object/clone.js +13 -8
  74. package/build/object/clone.js.map +1 -1
  75. package/build/object/equals.js +1 -1
  76. package/build/object/equals.js.map +1 -1
  77. package/build/object/filter-cached.d.ts.map +1 -1
  78. package/build/object/filter-cached.js +4 -6
  79. package/build/object/filter-cached.js.map +1 -1
  80. package/build/object/filter.d.ts.map +1 -1
  81. package/build/object/filter.js +2 -19
  82. package/build/object/filter.js.map +1 -1
  83. package/build/object/has-circular-reference.d.ts.map +1 -1
  84. package/build/object/has-circular-reference.js +5 -0
  85. package/build/object/has-circular-reference.js.map +1 -1
  86. package/build/object/hash.d.ts +12 -5
  87. package/build/object/hash.d.ts.map +1 -1
  88. package/build/object/hash.js +41 -13
  89. package/build/object/hash.js.map +1 -1
  90. package/build/object/index.d.ts +1 -1
  91. package/build/object/index.d.ts.map +1 -1
  92. package/build/object/index.js +1 -1
  93. package/build/object/index.js.map +1 -1
  94. package/build/object/key-value-pairs.d.ts.map +1 -1
  95. package/build/object/key-value-pairs.js +12 -4
  96. package/build/object/key-value-pairs.js.map +1 -1
  97. package/build/object/map-cached.d.ts.map +1 -1
  98. package/build/object/map-cached.js +2 -3
  99. package/build/object/map-cached.js.map +1 -1
  100. package/build/object/merge.d.ts.map +1 -1
  101. package/build/object/merge.js +3 -6
  102. package/build/object/merge.js.map +1 -1
  103. package/build/object/object-diff.d.ts +4 -8
  104. package/build/object/object-diff.d.ts.map +1 -1
  105. package/build/object/object-diff.js +8 -11
  106. package/build/object/object-diff.js.map +1 -1
  107. package/build/object/property-paths.js +2 -2
  108. package/build/object/property-paths.js.map +1 -1
  109. package/build/object/security-utils.d.ts.map +1 -1
  110. package/build/object/security-utils.js +0 -4
  111. package/build/object/security-utils.js.map +1 -1
  112. package/build/object/sort-keys.js +1 -1
  113. package/build/object/sort-keys.js.map +1 -1
  114. package/build/string/assert.d.ts +2 -1
  115. package/build/string/assert.d.ts.map +1 -1
  116. package/build/string/assert.js +5 -3
  117. package/build/string/assert.js.map +1 -1
  118. package/build/time/elapsed-time/elapsed-time.d.ts +1 -0
  119. package/build/time/elapsed-time/elapsed-time.d.ts.map +1 -1
  120. package/build/time/elapsed-time/elapsed-time.js +33 -22
  121. package/build/time/elapsed-time/elapsed-time.js.map +1 -1
  122. package/build/time/elapsed-time/types.d.ts +2 -2
  123. package/build/time/elapsed-time/types.d.ts.map +1 -1
  124. package/build/time/stopwatch/stopwatch.d.ts +20 -0
  125. package/build/time/stopwatch/stopwatch.d.ts.map +1 -1
  126. package/build/time/stopwatch/stopwatch.js +26 -4
  127. package/build/time/stopwatch/stopwatch.js.map +1 -1
  128. package/package.json +9 -12
@@ -16,10 +16,22 @@
16
16
  export function Once(fn) {
17
17
  let called = false;
18
18
  let result;
19
+ let error;
20
+ let hasError = false;
19
21
  return function once(...args) {
22
+ if (hasError) {
23
+ throw error;
24
+ }
20
25
  if (!called) {
21
- called = true;
22
- result = fn(...args);
26
+ try {
27
+ result = fn(...args);
28
+ called = true;
29
+ }
30
+ catch (e) {
31
+ error = e;
32
+ hasError = true;
33
+ throw e;
34
+ }
23
35
  }
24
36
  return result;
25
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"once.js","sourceRoot":"","sources":["../../src/function/once.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,IAAI,CAAoC,EAAK;IAC5D,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,MAAqB,CAAC;IAE1B,OAAO,SAAS,IAAI,CAAC,GAAG,IAAmB;QAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,GAAG,IAAI,CAAC;YACd,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAkB,CAAC;QACvC,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAM,CAAC;AACR,CAAC"}
1
+ {"version":3,"file":"once.js","sourceRoot":"","sources":["../../src/function/once.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,IAAI,CAAoC,EAAK;IAC5D,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,IAAI,MAAqB,CAAC;IAC1B,IAAI,KAAc,CAAC;IACnB,IAAI,QAAQ,GAAG,KAAK,CAAC;IAErB,OAAO,SAAS,IAAI,CAAC,GAAG,IAAmB;QAC1C,IAAI,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC;QACb,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,IAAI,CAAC;gBACJ,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAkB,CAAC;gBACtC,MAAM,GAAG,IAAI,CAAC;YACf,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACZ,KAAK,GAAG,CAAC,CAAC;gBACV,QAAQ,GAAG,IAAI,CAAC;gBAChB,MAAM,CAAC,CAAC;YACT,CAAC;QACF,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAM,CAAC;AACR,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../src/function/throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACzD,EAAE,EAAE,CAAC,EACL,EAAE,EAAE,MAAM,GACR,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAqBlC"}
1
+ {"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../src/function/throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACzD,EAAE,EAAE,CAAC,EACL,EAAE,EAAE,MAAM,GACR,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAuBlC"}
@@ -16,20 +16,22 @@
16
16
  export function Throttle(fn, ms) {
17
17
  let lastCall = 0;
18
18
  let timer;
19
+ let latestArgs;
19
20
  return function throttled(...args) {
21
+ latestArgs = args;
20
22
  const now = Date.now();
21
23
  const remaining = ms - (now - lastCall);
22
24
  if (remaining <= 0) {
23
25
  clearTimeout(timer);
24
26
  timer = undefined;
25
27
  lastCall = now;
26
- fn(...args);
28
+ fn(...latestArgs);
27
29
  }
28
30
  else {
29
31
  timer ??= setTimeout(() => {
30
32
  lastCall = Date.now();
31
33
  timer = undefined;
32
- fn(...args);
34
+ fn(...latestArgs);
33
35
  }, remaining);
34
36
  }
35
37
  };
@@ -1 +1 @@
1
- {"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../src/function/throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CACvB,EAAK,EACL,EAAU;IAEV,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,KAAgD,CAAC;IAErD,OAAO,SAAS,SAAS,CAAC,GAAG,IAAmB;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,SAAS,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAC;QAExC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;YACpB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,KAAK,GAAG,SAAS,CAAC;YAClB,QAAQ,GAAG,GAAG,CAAC;YACf,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACP,KAAK,KAAK,UAAU,CAAC,GAAG,EAAE;gBACzB,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACtB,KAAK,GAAG,SAAS,CAAC;gBAClB,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;YACb,CAAC,EAAE,SAAS,CAAC,CAAC;QACf,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../src/function/throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CACvB,EAAK,EACL,EAAU;IAEV,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,IAAI,KAAgD,CAAC;IACrD,IAAI,UAAyB,CAAC;IAE9B,OAAO,SAAS,SAAS,CAAC,GAAG,IAAmB;QAC/C,UAAU,GAAG,IAAI,CAAC;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,SAAS,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAC;QAExC,IAAI,SAAS,IAAI,CAAC,EAAE,CAAC;YACpB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,KAAK,GAAG,SAAS,CAAC;YAClB,QAAQ,GAAG,GAAG,CAAC;YACf,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC;QACnB,CAAC;aAAM,CAAC;YACP,KAAK,KAAK,UAAU,CAAC,GAAG,EAAE;gBACzB,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACtB,KAAK,GAAG,SAAS,CAAC;gBAClB,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC;YACnB,CAAC,EAAE,SAAS,CAAC,CAAC;QACf,CAAC;IACF,CAAC,CAAC;AACH,CAAC"}
package/build/index.d.ts CHANGED
@@ -26,12 +26,13 @@ export * as StringUtils from './string/index.js';
26
26
  export * as TimeUtils from './time/index.js';
27
27
  export * as EnumUtils from './enum/index.js';
28
28
  export * as FunctionUtils from './function/index.js';
29
+ export { LRUCache } from './lru-cache.js';
29
30
  export { ArrayFilter, ArrayContains, Unique, ArrayIntersection, ArrayChunk, ArrayShuffle, ArrayGroupBy, ArrayDifference, ArrayFlatten, ArrayCompact, ArrayPartition, ArrayZip, ArrayRange, ArraySortBy, ArrayCountBy, ArraySample, } from './array/index.js';
30
- export { CamelCase, PASCAL_CASE, KEBAB_CASE, SNAKE_CASE, SCREAMING_SNAKE_CASE, FormatString, EscapeHTML, StripHTML, Pluralize, WordCount, CountOccurrences, } from './string/index.js';
31
- export { AssertObject, ObjectClone, TransformObject, ObjectEquals, ObjectFilter, FilterObject, ObjectPick, ObjectOmit, ObjectMerge, MapObject, ObjectHash, ObjectSortKeys, ObjectFromKeyValuePairs, ObjectToKeyValuePairs, ObjectGetPropertyByPath, ObjectSetPropertyByPath, ObjectInvert, ObjectFlatten, ObjectDiff, } from './object/index.js';
32
- export { ElapsedTime, Stopwatch, } from './time/index.js';
31
+ export { CamelCase, CAPITALIZE, PASCAL_CASE, KEBAB_CASE, SNAKE_CASE, SCREAMING_SNAKE_CASE, FormatString, TruncateString, PadString, EscapeHTML, StripHTML, Pluralize, WordCount, CountOccurrences, REVERSE_STRING, SLUGIFY, IS_BLANK_STRING, IS_HEX_STRING, } from './string/index.js';
32
+ export { IsObject, ObjectClone, TransformObject, ObjectEquals, ObjectFilter, FilterObject, ObjectPick, ObjectOmit, ObjectMerge, MapObject, ObjectHash, ObjectSortKeys, ObjectFromKeyValuePairs, ObjectToKeyValuePairs, ObjectGetPropertyByPath, ObjectSetPropertyByPath, ObjectInvert, ObjectFlatten, ObjectDiff, } from './object/index.js';
33
+ export { ElapsedTime, FormatElapsedTime, Stopwatch, } from './time/index.js';
33
34
  export { EnumKeys, EnumValues, EnumEntries, ValidateEnumValue, EnumKeyByValue, EnumSafeValue, } from './enum/index.js';
34
35
  export { Debounce, Throttle, Memoize, Once, Compose, Pipe, Sleep, } from './function/index.js';
35
- export { AssertArray, AssertArray2D, AssertArrayAll, AssertArrayAny, AssertArrayNotEmpty, AssertBoolean, AssertEquals, AssertExtends, AssertFunction, AssertInstanceOf, AssertIsType, AssertNotEquals, AssertNotNull, AssertNull, AssertNumber, AssertObjectHasOwnProperty, AssertObjectHasProperty, AssertObjectPropertyNotNull, AssertPredicate, AssertString, AssertStringMatches, AssertStringNotEmpty, AssertSymbol, SetExceptionClass, SetExceptionMessage, ThrowException, AssertionError, BaseError, BufferOverflowError, InvalidArgumentError, NotFoundError, NotSupportedError, ValidationError, ArrayError, BooleanError, ExtendsError, FunctionError, InstanceOfError, NotNullError, NullError, NumberError, NumberRangeError, ObjectError, ObjectPropertyError, PredicateError, StringError, SymbolError, TypeGuardError, } from './asserts/index.js';
36
+ export { AssertArray, AssertArray2D, AssertArrayAll, AssertArrayAny, AssertArrayNotEmpty, AssertBoolean, AssertEquals, AssertExtends, AssertFunction, AssertInstanceOf, AssertIsType, AssertNotEquals, AssertNotNull, AssertNull, AssertNumber, AssertObject, AssertObjectHasOwnProperty, AssertObjectHasProperty, AssertObjectPropertyNotNull, AssertPredicate, AssertString, AssertStringMatches, AssertStringNotEmpty, AssertSymbol, SetExceptionClass, SetExceptionMessage, ThrowException, AssertionError, BaseError, BufferOverflowError, InvalidArgumentError, NotFoundError, NotSupportedError, ValidationError, ArrayError, BooleanError, ExtendsError, FunctionError, InstanceOfError, NotNullError, NullError, NumberError, NumberRangeError, ObjectError, ObjectPropertyError, PredicateError, StringError, SymbolError, TypeGuardError, } from './asserts/index.js';
36
37
  export type { IAssertException, TConstraintValue, TComparisonOperator, TValidationResult, TGuard, TValidationPredicate, TArrayTypeGuard, TObjectTypeGuard, TNonNullableGuard, TAssertFunction, TConstructorFunction, IAssertArrayArgs, IAssertArray2DArgs, TSizeConstraint, TDimensionConstraint, IAssertNumberArgs, TNumericComparison, TNumericRangeConstraints, TNumericTypeConstraints, } from './asserts/index.js';
37
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAG/C,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAGjD,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAGnD,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAGnD,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAGjD,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAGjD,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAG7C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAG7C,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAEN,WAAW,EACX,aAAa,EACb,MAAM,EACN,iBAAiB,EACjB,UA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BAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,cAAc,EAEd,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EACf,YAAY,EACZ,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,GACd,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EAEX,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,MAAM,EACN,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EAEpB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EAEpB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,uBAAuB,GACvB,MAAM,oBAAoB,CAAC"}
package/build/index.js CHANGED
@@ -35,19 +35,21 @@ export * as TimeUtils from './time/index.js';
35
35
  export * as EnumUtils from './enum/index.js';
36
36
  // Function utilities
37
37
  export * as FunctionUtils from './function/index.js';
38
+ // LRU Cache
39
+ export { LRUCache } from './lru-cache.js';
38
40
  // Direct exports for commonly used functions
39
41
  export {
40
42
  // Array utilities
41
43
  ArrayFilter, ArrayContains, Unique, ArrayIntersection, ArrayChunk, ArrayShuffle, ArrayGroupBy, ArrayDifference, ArrayFlatten, ArrayCompact, ArrayPartition, ArrayZip, ArrayRange, ArraySortBy, ArrayCountBy, ArraySample, } from './array/index.js';
42
44
  export {
43
45
  // String utilities
44
- CamelCase, PASCAL_CASE, KEBAB_CASE, SNAKE_CASE, SCREAMING_SNAKE_CASE, FormatString, EscapeHTML, StripHTML, Pluralize, WordCount, CountOccurrences, } from './string/index.js';
46
+ CamelCase, CAPITALIZE, PASCAL_CASE, KEBAB_CASE, SNAKE_CASE, SCREAMING_SNAKE_CASE, FormatString, TruncateString, PadString, EscapeHTML, StripHTML, Pluralize, WordCount, CountOccurrences, REVERSE_STRING, SLUGIFY, IS_BLANK_STRING, IS_HEX_STRING, } from './string/index.js';
45
47
  export {
46
48
  // Object utilities
47
- AssertObject, ObjectClone, TransformObject, ObjectEquals, ObjectFilter, FilterObject, ObjectPick, ObjectOmit, ObjectMerge, MapObject, ObjectHash, ObjectSortKeys, ObjectFromKeyValuePairs, ObjectToKeyValuePairs, ObjectGetPropertyByPath, ObjectSetPropertyByPath, ObjectInvert, ObjectFlatten, ObjectDiff, } from './object/index.js';
49
+ IsObject, ObjectClone, TransformObject, ObjectEquals, ObjectFilter, FilterObject, ObjectPick, ObjectOmit, ObjectMerge, MapObject, ObjectHash, ObjectSortKeys, ObjectFromKeyValuePairs, ObjectToKeyValuePairs, ObjectGetPropertyByPath, ObjectSetPropertyByPath, ObjectInvert, ObjectFlatten, ObjectDiff, } from './object/index.js';
48
50
  export {
49
51
  // Time utilities
50
- ElapsedTime, Stopwatch, } from './time/index.js';
52
+ ElapsedTime, FormatElapsedTime, Stopwatch, } from './time/index.js';
51
53
  export {
52
54
  // Enum utilities
53
55
  EnumKeys, EnumValues, EnumEntries, ValidateEnumValue, EnumKeyByValue, EnumSafeValue, } from './enum/index.js';
@@ -56,8 +58,7 @@ export {
56
58
  Debounce, Throttle, Memoize, Once, Compose, Pipe, Sleep, } from './function/index.js';
57
59
  export {
58
60
  // Asserts utilities
59
- // (AssertObject is omitted here it conflicts with ObjectUtils.AssertObject; use AssertsUtils.AssertObject instead)
60
- AssertArray, AssertArray2D, AssertArrayAll, AssertArrayAny, AssertArrayNotEmpty, AssertBoolean, AssertEquals, AssertExtends, AssertFunction, AssertInstanceOf, AssertIsType, AssertNotEquals, AssertNotNull, AssertNull, AssertNumber, AssertObjectHasOwnProperty, AssertObjectHasProperty, AssertObjectPropertyNotNull, AssertPredicate, AssertString, AssertStringMatches, AssertStringNotEmpty, AssertSymbol, SetExceptionClass, SetExceptionMessage, ThrowException,
61
+ AssertArray, AssertArray2D, AssertArrayAll, AssertArrayAny, AssertArrayNotEmpty, AssertBoolean, AssertEquals, AssertExtends, AssertFunction, AssertInstanceOf, AssertIsType, AssertNotEquals, AssertNotNull, AssertNull, AssertNumber, AssertObject, AssertObjectHasOwnProperty, AssertObjectHasProperty, AssertObjectPropertyNotNull, AssertPredicate, AssertString, AssertStringMatches, AssertStringNotEmpty, AssertSymbol, SetExceptionClass, SetExceptionMessage, ThrowException,
61
62
  // Error classes
62
63
  AssertionError, BaseError, BufferOverflowError, InvalidArgumentError, NotFoundError, NotSupportedError, ValidationError, ArrayError, BooleanError, ExtendsError, FunctionError, InstanceOfError, NotNullError, NullError, NumberError, NumberRangeError, ObjectError, ObjectPropertyError, PredicateError, StringError, SymbolError, TypeGuardError, } from './asserts/index.js';
63
64
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,kBAAkB;AAClB,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAC;AAE/C,mBAAmB;AACnB,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAEjD,oBAAoB;AACpB,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAEnD,oBAAoB;AACpB,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AAEnD,mBAAmB;AACnB,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAEjD,mBAAmB;AACnB,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAC;AAEjD,iBAAiB;AACjB,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAE7C,iBAAiB;AACjB,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAE7C,qBAAqB;AACrB,OAAO,KAAK,aAAa,MAAM,qBAAqB,CAAC;AAErD,6CAA6C;AAC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AAa,EACb,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,0BAA0B,EAC1B,uBAAuB,EACvB,2BAA2B,EAC3B,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,cAAc;AACd,gBAAgB;AAChB,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EACf,YAAY,EACZ,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,WAAW,EACX,WAAW,EACX,cAAc,GACd,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Generic Least Recently Used (LRU) Cache implementation.
3
+ *
4
+ * An `LRUCache` maintains a fixed-size cache of key-value pairs.
5
+ * When capacity is reached, the least recently used (oldest) entry is evicted.
6
+ * Both `get()` and `set()` operations update the recency order.
7
+ *
8
+ * @typeParam K - Key type
9
+ * @typeParam V - Value type
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const cache = new LRUCache<string, number>(2);
14
+ * cache.set('a', 1);
15
+ * cache.set('b', 2);
16
+ * cache.set('c', 3); // Evicts 'a' since capacity is 2
17
+ * console.log(cache.get('a')); // undefined
18
+ * console.log(cache.get('b')); // 2
19
+ * ```
20
+ */
21
+ export declare class LRUCache<K, V> {
22
+ private readonly _map;
23
+ private readonly _maxSize;
24
+ /**
25
+ * Creates a new `LRUCache` instance.
26
+ *
27
+ * @param maxSize - Maximum number of entries to cache before evicting the least recently used
28
+ * @throws {Error} If maxSize is less than 1
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const cache = new LRUCache<string, string>(100);
33
+ * ```
34
+ */
35
+ constructor(maxSize: number);
36
+ /**
37
+ * The current number of cached entries.
38
+ */
39
+ get size(): number;
40
+ /**
41
+ * Retrieves a value from the cache by key.
42
+ *
43
+ * Accessing a value marks it as recently used, moving it to the end of the
44
+ * eviction order.
45
+ *
46
+ * @param key - The key to look up
47
+ * @returns The cached value, or `undefined` if not found
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const cache = new LRUCache<string, number>(2);
52
+ * cache.set('a', 1);
53
+ * console.log(cache.get('a')); // 1
54
+ * console.log(cache.get('b')); // undefined
55
+ * ```
56
+ */
57
+ get(key: K): V | undefined;
58
+ /**
59
+ * Returns whether a key exists in the cache.
60
+ *
61
+ * @param key - The key to check
62
+ * @returns `true` if the key is present, `false` otherwise
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const cache = new LRUCache<string, number>(2);
67
+ * cache.set('a', 1);
68
+ * console.log(cache.has('a')); // true
69
+ * console.log(cache.has('b')); // false
70
+ * ```
71
+ */
72
+ has(key: K): boolean;
73
+ /**
74
+ * Sets a value in the cache.
75
+ *
76
+ * If the key already exists, its value is updated and it is marked as
77
+ * recently used. If the cache is at capacity and a new key is added,
78
+ * the least recently used (first) entry is evicted.
79
+ *
80
+ * @param key - The key to cache
81
+ * @param value - The value to associate with the key
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const cache = new LRUCache<string, number>(2);
86
+ * cache.set('a', 1);
87
+ * cache.set('b', 2);
88
+ * cache.set('c', 3); // Evicts 'a' since cache is full
89
+ * ```
90
+ */
91
+ set(key: K, value: V): void;
92
+ /**
93
+ * Clears all entries from the cache.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const cache = new LRUCache<string, number>(10);
98
+ * cache.set('a', 1);
99
+ * cache.clear();
100
+ * console.log(cache.size); // 0
101
+ * ```
102
+ */
103
+ clear(): void;
104
+ }
105
+ //# sourceMappingURL=lru-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lru-cache.d.ts","sourceRoot":"","sources":["../src/lru-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAmB;IAExC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC;;;;;;;;;;OAUG;gBACS,OAAO,EAAE,MAAM;IAO3B;;OAEG;IACH,IAAW,IAAI,IAAI,MAAM,CAExB;IAED;;;;;;;;;;;;;;;;OAgBG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAWjC;;;;;;;;;;;;;OAaG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAI3B;;;;;;;;;;;;;;;;;OAiBG;IACI,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAgBlC;;;;;;;;;;OAUG;IACI,KAAK,IAAI,IAAI;CAGpB"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Generic Least Recently Used (LRU) Cache implementation.
3
+ *
4
+ * An `LRUCache` maintains a fixed-size cache of key-value pairs.
5
+ * When capacity is reached, the least recently used (oldest) entry is evicted.
6
+ * Both `get()` and `set()` operations update the recency order.
7
+ *
8
+ * @typeParam K - Key type
9
+ * @typeParam V - Value type
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * const cache = new LRUCache<string, number>(2);
14
+ * cache.set('a', 1);
15
+ * cache.set('b', 2);
16
+ * cache.set('c', 3); // Evicts 'a' since capacity is 2
17
+ * console.log(cache.get('a')); // undefined
18
+ * console.log(cache.get('b')); // 2
19
+ * ```
20
+ */
21
+ export class LRUCache {
22
+ _map = new Map();
23
+ _maxSize;
24
+ /**
25
+ * Creates a new `LRUCache` instance.
26
+ *
27
+ * @param maxSize - Maximum number of entries to cache before evicting the least recently used
28
+ * @throws {Error} If maxSize is less than 1
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const cache = new LRUCache<string, string>(100);
33
+ * ```
34
+ */
35
+ constructor(maxSize) {
36
+ if (maxSize < 1) {
37
+ throw new Error('LRUCache maxSize must be at least 1');
38
+ }
39
+ this._maxSize = maxSize;
40
+ }
41
+ /**
42
+ * The current number of cached entries.
43
+ */
44
+ get size() {
45
+ return this._map.size;
46
+ }
47
+ /**
48
+ * Retrieves a value from the cache by key.
49
+ *
50
+ * Accessing a value marks it as recently used, moving it to the end of the
51
+ * eviction order.
52
+ *
53
+ * @param key - The key to look up
54
+ * @returns The cached value, or `undefined` if not found
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const cache = new LRUCache<string, number>(2);
59
+ * cache.set('a', 1);
60
+ * console.log(cache.get('a')); // 1
61
+ * console.log(cache.get('b')); // undefined
62
+ * ```
63
+ */
64
+ get(key) {
65
+ if (!this._map.has(key)) {
66
+ return undefined;
67
+ }
68
+ const value = this._map.get(key);
69
+ // Move to end (mark as recently used)
70
+ this._map.delete(key);
71
+ this._map.set(key, value);
72
+ return value;
73
+ }
74
+ /**
75
+ * Returns whether a key exists in the cache.
76
+ *
77
+ * @param key - The key to check
78
+ * @returns `true` if the key is present, `false` otherwise
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const cache = new LRUCache<string, number>(2);
83
+ * cache.set('a', 1);
84
+ * console.log(cache.has('a')); // true
85
+ * console.log(cache.has('b')); // false
86
+ * ```
87
+ */
88
+ has(key) {
89
+ return this._map.has(key);
90
+ }
91
+ /**
92
+ * Sets a value in the cache.
93
+ *
94
+ * If the key already exists, its value is updated and it is marked as
95
+ * recently used. If the cache is at capacity and a new key is added,
96
+ * the least recently used (first) entry is evicted.
97
+ *
98
+ * @param key - The key to cache
99
+ * @param value - The value to associate with the key
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const cache = new LRUCache<string, number>(2);
104
+ * cache.set('a', 1);
105
+ * cache.set('b', 2);
106
+ * cache.set('c', 3); // Evicts 'a' since cache is full
107
+ * ```
108
+ */
109
+ set(key, value) {
110
+ // If key already exists, delete it (will re-add at end)
111
+ if (this._map.has(key)) {
112
+ this._map.delete(key);
113
+ }
114
+ else if (this._map.size >= this._maxSize) {
115
+ // If at capacity and adding a new key, evict the oldest (first) entry
116
+ const firstKey = this._map.keys().next().value;
117
+ if (firstKey !== undefined) {
118
+ this._map.delete(firstKey);
119
+ }
120
+ }
121
+ // Add at the end (mark as recently used)
122
+ this._map.set(key, value);
123
+ }
124
+ /**
125
+ * Clears all entries from the cache.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const cache = new LRUCache<string, number>(10);
130
+ * cache.set('a', 1);
131
+ * cache.clear();
132
+ * console.log(cache.size); // 0
133
+ * ```
134
+ */
135
+ clear() {
136
+ this._map.clear();
137
+ }
138
+ }
139
+ //# sourceMappingURL=lru-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lru-cache.js","sourceRoot":"","sources":["../src/lru-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,QAAQ;IACH,IAAI,GAAG,IAAI,GAAG,EAAQ,CAAC;IAEvB,QAAQ,CAAS;IAElC;;;;;;;;;;OAUG;IACH,YAAY,OAAe;QAC1B,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACI,GAAG,CAAC,GAAM;QAChB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAM,CAAC;QACtC,sCAAsC;QACtC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,GAAG,CAAC,GAAM;QAChB,OAAO,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACI,GAAG,CAAC,GAAM,EAAE,KAAQ;QAC1B,wDAAwD;QACxD,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC5C,sEAAsE;YACtE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YAC/C,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC5B,CAAC;QACF,CAAC;QAED,yCAAyC;QACzC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK;QACX,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;CACD"}
@@ -1,4 +1,5 @@
1
1
  import type { IAssertException } from '../asserts/types.js';
2
+ import { SimpleError } from '../asserts/errors.js';
2
3
  /**
3
4
  * Error thrown when a value is not a valid number or fails basic numeric validation.
4
5
  *
@@ -13,7 +14,7 @@ import type { IAssertException } from '../asserts/types.js';
13
14
  * throw new NumberError('Expected number but received string');
14
15
  * ```
15
16
  */
16
- export declare class NumberError extends Error {
17
+ export declare class NumberError extends SimpleError {
17
18
  constructor(message?: string);
18
19
  }
19
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/number/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAG5D;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAY,SAAQ,KAAK;gBACzB,OAAO,CAAC,EAAE,MAAM;CAK5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAiB,SAAQ,WAAW;gBACpC,OAAO,CAAC,EAAE,MAAM;CAK5B;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC;AAEpE;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,IAAI,CAAC,iBAAiB,EAAE,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC;AAEnG;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,iBAAiB,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,iBAAiB;IACjC,4EAA4E;IAC5E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,yDAAyD;IACzD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,EAAE,CAAC,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAC;IACZ,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,EAAE,CAAC,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,iBAAsB,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAoDpI"}
@@ -1,4 +1,5 @@
1
1
  import { SetExceptionClass, SetExceptionMessage, ThrowException } from '../asserts/utils.js';
2
+ import { SimpleError } from '../asserts/errors.js';
2
3
  /**
3
4
  * Error thrown when a value is not a valid number or fails basic numeric validation.
4
5
  *
@@ -13,11 +14,9 @@ import { SetExceptionClass, SetExceptionMessage, ThrowException } from '../asser
13
14
  * throw new NumberError('Expected number but received string');
14
15
  * ```
15
16
  */
16
- export class NumberError extends Error {
17
+ export class NumberError extends SimpleError {
17
18
  constructor(message) {
18
19
  super(message ?? 'Value is not a valid number');
19
- this.name = 'NumberError';
20
- Object.setPrototypeOf(this, NumberError.prototype);
21
20
  }
22
21
  }
23
22
  /**
@@ -39,8 +38,6 @@ export class NumberError extends Error {
39
38
  export class NumberRangeError extends NumberError {
40
39
  constructor(message) {
41
40
  super(message ?? 'Value is not in the expected range');
42
- this.name = 'NumberRangeError';
43
- Object.setPrototypeOf(this, NumberRangeError.prototype);
44
41
  }
45
42
  }
46
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/number/assert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE7F;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACrC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,6BAA6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KAAK,SAAS,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAChD,mBAAmB,CAAC,SAAS,EAAE,qBAAqB,IAAI,CAAC,GAAG,iBAAiB,KAAK,EAAE,CAAC,CAAC;YACtF,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;QAED,0EAA0E;QAC1E,IAAI,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI,KAAK,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;YAC/C,mBAAmB,CAAC,SAAS,EAAE,oBAAoB,IAAI,CAAC,EAAE,iBAAiB,KAAK,EAAE,CAAC,CAAC;YACpF,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;QAED,iFAAiF;QACjF,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAChD,mBAAmB,CAAC,SAAS,EAAE,qBAAqB,IAAI,CAAC,GAAG,iBAAiB,KAAK,EAAE,CAAC,CAAC;YACtF,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -1,8 +1,19 @@
1
1
  /**
2
- * Type guard that checks if the provided value is a non-null, non-array object
2
+ * Type guard that checks if the provided value is a non-null, non-array object.
3
+ *
4
+ * Use this for type narrowing in conditionals. For runtime assertions that
5
+ * throw on failure, use {@link AssertObject} from the asserts module.
3
6
  *
4
7
  * @param item - The value to check
5
8
  * @returns True if the value is an object (not null and not an array)
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * if (IsObject(value)) {
13
+ * // value is now typed as Record<string, any>
14
+ * console.log(value.someProperty);
15
+ * }
16
+ * ```
6
17
  */
7
- export declare function AssertObject(item: unknown): item is Record<string, any>;
18
+ export declare function IsObject(item: unknown): item is Record<string, any>;
8
19
  //# sourceMappingURL=assert-object.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"assert-object.d.ts","sourceRoot":"","sources":["../../src/object/assert-object.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAEvE"}
1
+ {"version":3,"file":"assert-object.d.ts","sourceRoot":"","sources":["../../src/object/assert-object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAEnE"}
@@ -1,10 +1,21 @@
1
1
  /**
2
- * Type guard that checks if the provided value is a non-null, non-array object
2
+ * Type guard that checks if the provided value is a non-null, non-array object.
3
+ *
4
+ * Use this for type narrowing in conditionals. For runtime assertions that
5
+ * throw on failure, use {@link AssertObject} from the asserts module.
3
6
  *
4
7
  * @param item - The value to check
5
8
  * @returns True if the value is an object (not null and not an array)
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * if (IsObject(value)) {
13
+ * // value is now typed as Record<string, any>
14
+ * console.log(value.someProperty);
15
+ * }
16
+ * ```
6
17
  */
7
- export function AssertObject(item) {
18
+ export function IsObject(item) {
8
19
  return item !== null && typeof item === 'object' && !Array.isArray(item);
9
20
  }
10
21
  //# sourceMappingURL=assert-object.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"assert-object.js","sourceRoot":"","sources":["../../src/object/assert-object.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAa;IACzC,OAAO,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1E,CAAC"}
1
+ {"version":3,"file":"assert-object.js","sourceRoot":"","sources":["../../src/object/assert-object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAa;IACrC,OAAO,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1E,CAAC"}
@@ -1,11 +1,12 @@
1
1
  import { IAssertException } from '../asserts/types.js';
2
+ import { SimpleError } from '../asserts/errors.js';
2
3
  /**
3
4
  * Error thrown when a value is not a valid object or fails an object assertion.
4
5
  *
5
6
  * @example
6
7
  * throw new ObjectError('Value is not a valid object');
7
8
  */
8
- export declare class ObjectError extends Error {
9
+ export declare class ObjectError extends SimpleError {
9
10
  constructor(message?: string);
10
11
  }
11
12
  /**
@@ -14,7 +15,7 @@ export declare class ObjectError extends Error {
14
15
  * @example
15
16
  * throw new PropertyError('Object is missing required property');
16
17
  */
17
- export declare class ObjectPropertyError extends Error {
18
+ export declare class ObjectPropertyError extends SimpleError {
18
19
  constructor(message?: string);
19
20
  }
20
21
  /**
@@ -79,7 +80,7 @@ export declare function AssertObjectHasProperty<T extends object, K extends Prop
79
80
  *
80
81
  * This method validates that the specified property exists as an own property
81
82
  * of the object, excluding properties from the prototype chain. Uses
82
- * Object.prototype.hasOwnProperty.call() for reliable detection. This is useful
83
+ * `Object.hasOwn()` for reliable detection. This is useful
83
84
  * when you need to ensure a property is directly defined on the object.
84
85
  *
85
86
  * @template T - The object type
@@ -1 +1 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/object/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAMvD;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,KAAK;gBACzB,OAAO,CAAC,EAAE,MAAM;CAK5B;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBACjC,OAAO,CAAC,EAAE,MAAM;CAK5B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,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,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBvH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAU9I;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAUjJ;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAW9I"}
@@ -1,4 +1,5 @@
1
1
  import { SetExceptionClass, SetExceptionMessage, ThrowException } from '../asserts/utils.js';
2
+ import { SimpleError } from '../asserts/errors.js';
2
3
  /** Maximum number of characters to include from a value in an error message. */
3
4
  const MAX_VALUE_DISPLAY_LENGTH = 100;
4
5
  /**
@@ -7,11 +8,9 @@ const MAX_VALUE_DISPLAY_LENGTH = 100;
7
8
  * @example
8
9
  * throw new ObjectError('Value is not a valid object');
9
10
  */
10
- export class ObjectError extends Error {
11
+ export class ObjectError extends SimpleError {
11
12
  constructor(message) {
12
13
  super(message ?? 'Object assertion failed');
13
- this.name = 'ObjectError';
14
- Object.setPrototypeOf(this, ObjectError.prototype);
15
14
  }
16
15
  }
17
16
  /**
@@ -20,11 +19,9 @@ export class ObjectError extends Error {
20
19
  * @example
21
20
  * throw new PropertyError('Object is missing required property');
22
21
  */
23
- export class ObjectPropertyError extends Error {
22
+ export class ObjectPropertyError extends SimpleError {
24
23
  constructor(message) {
25
24
  super(message ?? 'Object Property Assertion Failed');
26
- this.name = 'ObjectPropertyError';
27
- Object.setPrototypeOf(this, ObjectPropertyError.prototype);
28
25
  }
29
26
  }
30
27
  /**
@@ -126,7 +123,7 @@ export function AssertObjectHasProperty(value, property, exception = {}) {
126
123
  *
127
124
  * This method validates that the specified property exists as an own property
128
125
  * of the object, excluding properties from the prototype chain. Uses
129
- * Object.prototype.hasOwnProperty.call() for reliable detection. This is useful
126
+ * `Object.hasOwn()` for reliable detection. This is useful
130
127
  * when you need to ensure a property is directly defined on the object.
131
128
  *
132
129
  * @template T - The object type
@@ -156,7 +153,7 @@ export function AssertObjectHasOwnProperty(value, property, exception = {}) {
156
153
  AssertObject(value, { class: ObjectError });
157
154
  // Then check for own property existence, using the configured exception class or default
158
155
  SetExceptionClass(exception, ObjectPropertyError);
159
- if (!Object.prototype.hasOwnProperty.call(value, property)) {
156
+ if (!Object.hasOwn(value, property)) {
160
157
  SetExceptionMessage(exception, `Expected object to have own property '${String(property)}' but property was not found`);
161
158
  ThrowException(exception);
162
159
  }