@pawells/typescript-common 1.1.0 → 1.1.3

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 (118) hide show
  1. package/README.md +1 -118
  2. package/build/array/array-chunk.d.ts +10 -4
  3. package/build/array/array-chunk.d.ts.map +1 -1
  4. package/build/array/array-chunk.js +10 -4
  5. package/build/array/array-chunk.js.map +1 -1
  6. package/build/array/array-contains.d.ts +11 -3
  7. package/build/array/array-contains.d.ts.map +1 -1
  8. package/build/array/array-contains.js +11 -3
  9. package/build/array/array-contains.js.map +1 -1
  10. package/build/array/array-group-by.d.ts +14 -5
  11. package/build/array/array-group-by.d.ts.map +1 -1
  12. package/build/array/array-group-by.js +14 -5
  13. package/build/array/array-group-by.js.map +1 -1
  14. package/build/array/array-shuffle.d.ts +12 -3
  15. package/build/array/array-shuffle.d.ts.map +1 -1
  16. package/build/array/array-shuffle.js +12 -3
  17. package/build/array/array-shuffle.js.map +1 -1
  18. package/build/array/unique.d.ts +13 -3
  19. package/build/array/unique.d.ts.map +1 -1
  20. package/build/array/unique.js +13 -3
  21. package/build/array/unique.js.map +1 -1
  22. package/build/asserts/errors.d.ts +91 -7
  23. package/build/asserts/errors.d.ts.map +1 -1
  24. package/build/asserts/errors.js +91 -7
  25. package/build/asserts/errors.js.map +1 -1
  26. package/build/asserts/generic.d.ts +8 -4
  27. package/build/asserts/generic.d.ts.map +1 -1
  28. package/build/asserts/generic.js +8 -4
  29. package/build/asserts/generic.js.map +1 -1
  30. package/build/enum/enum-entries.d.ts +8 -3
  31. package/build/enum/enum-entries.d.ts.map +1 -1
  32. package/build/enum/enum-entries.js +8 -3
  33. package/build/enum/enum-entries.js.map +1 -1
  34. package/build/enum/enum-key-by-value.d.ts +10 -5
  35. package/build/enum/enum-key-by-value.d.ts.map +1 -1
  36. package/build/enum/enum-key-by-value.js +10 -5
  37. package/build/enum/enum-key-by-value.js.map +1 -1
  38. package/build/enum/enum-keys.d.ts +12 -3
  39. package/build/enum/enum-keys.d.ts.map +1 -1
  40. package/build/enum/enum-keys.js +12 -3
  41. package/build/enum/enum-keys.js.map +1 -1
  42. package/build/enum/enum-safe-value.d.ts +11 -6
  43. package/build/enum/enum-safe-value.d.ts.map +1 -1
  44. package/build/enum/enum-safe-value.js +11 -6
  45. package/build/enum/enum-safe-value.js.map +1 -1
  46. package/build/enum/validate-enum-value.d.ts +10 -5
  47. package/build/enum/validate-enum-value.d.ts.map +1 -1
  48. package/build/enum/validate-enum-value.js +10 -5
  49. package/build/enum/validate-enum-value.js.map +1 -1
  50. package/build/index.d.ts +1 -0
  51. package/build/index.d.ts.map +1 -1
  52. package/build/number/assert.d.ts +14 -14
  53. package/build/number/assert.d.ts.map +1 -1
  54. package/build/object/clone.d.ts +17 -6
  55. package/build/object/clone.d.ts.map +1 -1
  56. package/build/object/clone.js +17 -6
  57. package/build/object/clone.js.map +1 -1
  58. package/build/object/filter-cached.d.ts +15 -3
  59. package/build/object/filter-cached.d.ts.map +1 -1
  60. package/build/object/filter-cached.js +15 -3
  61. package/build/object/filter-cached.js.map +1 -1
  62. package/build/object/has-circular-reference.d.ts +12 -3
  63. package/build/object/has-circular-reference.d.ts.map +1 -1
  64. package/build/object/has-circular-reference.js +12 -3
  65. package/build/object/has-circular-reference.js.map +1 -1
  66. package/build/object/key-value-pairs.d.ts +11 -3
  67. package/build/object/key-value-pairs.d.ts.map +1 -1
  68. package/build/object/key-value-pairs.js +11 -3
  69. package/build/object/key-value-pairs.js.map +1 -1
  70. package/build/object/map-cached.d.ts +14 -3
  71. package/build/object/map-cached.d.ts.map +1 -1
  72. package/build/object/map-cached.js +14 -3
  73. package/build/object/map-cached.js.map +1 -1
  74. package/build/object/merge.d.ts +18 -7
  75. package/build/object/merge.d.ts.map +1 -1
  76. package/build/object/merge.js +18 -7
  77. package/build/object/merge.js.map +1 -1
  78. package/build/object/omit.d.ts +13 -4
  79. package/build/object/omit.d.ts.map +1 -1
  80. package/build/object/omit.js +13 -4
  81. package/build/object/omit.js.map +1 -1
  82. package/build/string/formatting.d.ts +10 -3
  83. package/build/string/formatting.d.ts.map +1 -1
  84. package/build/string/formatting.js +10 -3
  85. package/build/string/formatting.js.map +1 -1
  86. package/package.json +9 -5
  87. package/build/array/array.test.d.ts +0 -2
  88. package/build/array/array.test.d.ts.map +0 -1
  89. package/build/array/array.test.js +0 -347
  90. package/build/array/array.test.js.map +0 -1
  91. package/build/asserts/object.d.ts +0 -138
  92. package/build/asserts/object.d.ts.map +0 -1
  93. package/build/asserts/object.js +0 -204
  94. package/build/asserts/object.js.map +0 -1
  95. package/build/asserts/string.d.ts +0 -100
  96. package/build/asserts/string.d.ts.map +0 -1
  97. package/build/asserts/string.js +0 -185
  98. package/build/asserts/string.js.map +0 -1
  99. package/build/enum/enum.test.d.ts +0 -2
  100. package/build/enum/enum.test.d.ts.map +0 -1
  101. package/build/enum/enum.test.js +0 -122
  102. package/build/enum/enum.test.js.map +0 -1
  103. package/build/function/function.test.d.ts +0 -2
  104. package/build/function/function.test.d.ts.map +0 -1
  105. package/build/function/function.test.js +0 -158
  106. package/build/function/function.test.js.map +0 -1
  107. package/build/object/object.test.d.ts +0 -2
  108. package/build/object/object.test.d.ts.map +0 -1
  109. package/build/object/object.test.js +0 -432
  110. package/build/object/object.test.js.map +0 -1
  111. package/build/string/string.test.d.ts +0 -2
  112. package/build/string/string.test.d.ts.map +0 -1
  113. package/build/string/string.test.js +0 -321
  114. package/build/string/string.test.js.map +0 -1
  115. package/build/time/time.test.d.ts +0 -2
  116. package/build/time/time.test.d.ts.map +0 -1
  117. package/build/time/time.test.js +0 -211
  118. package/build/time/time.test.js.map +0 -1
@@ -1,204 +0,0 @@
1
- import { SetExceptionClass, SetExceptionMessage, ThrowException } from './utils.js';
2
- /** Maximum number of characters to include from a value in an error message. */
3
- const MAX_VALUE_DISPLAY_LENGTH = 100;
4
- /**
5
- * Error thrown when a value is not a valid object or fails an object assertion.
6
- *
7
- * @example
8
- * throw new ObjectError('Value is not a valid object');
9
- */
10
- export class ObjectError extends Error {
11
- constructor(message) {
12
- super(message ?? 'Object assertion failed');
13
- this.name = 'ObjectError';
14
- Object.setPrototypeOf(this, ObjectError.prototype);
15
- }
16
- }
17
- /**
18
- * Error thrown when an object is missing a required property or a property fails an assertion.
19
- *
20
- * @example
21
- * throw new PropertyError('Object is missing required property');
22
- */
23
- export class ObjectPropertyError extends Error {
24
- constructor(message) {
25
- super(message ?? 'Object Property Assertion Failed');
26
- this.name = 'ObjectPropertyError';
27
- Object.setPrototypeOf(this, ObjectPropertyError.prototype);
28
- }
29
- }
30
- /**
31
- * Asserts that a value is a plain object (not null, not an array, not a function).
32
- *
33
- * This method validates that the provided value is an object type, excluding null,
34
- * arrays, and functions which are technically objects in JavaScript but not plain
35
- * objects. After this assertion, the value is typed as Record<string, unknown>
36
- * for safe property access.
37
- *
38
- * @template TError - Custom error type to throw on failure
39
- * @param value - The value to validate as an object
40
- * @param exception - Optional exception configuration for custom error handling
41
- * @throws {ObjectError} When value is not a plain object
42
- *
43
- * @example
44
- * ```typescript
45
- * AssertObject({ name: "John" }); // ✓ Valid (plain object)
46
- * AssertObject({}); // ✓ Valid (empty object)
47
- * AssertObject(new Date()); // ✓ Valid (object instance)
48
- * AssertObject([1, 2, 3]); // ✗ Throws ObjectError (array)
49
- * AssertObject(null); // ✗ Throws ObjectError (null)
50
- * AssertObject("string"); // ✗ Throws ObjectError (primitive)
51
- * AssertObject(() => {}); // ✗ Throws ObjectError (function)
52
- * ```
53
- */
54
- export function AssertObject(value, exception = {}) {
55
- SetExceptionClass(exception, ObjectError);
56
- if (typeof value !== 'object' || value === null || Array.isArray(value) || typeof value === 'function') {
57
- const actualType = value === null ? 'null' : Array.isArray(value) ? 'array' : typeof value;
58
- let valueStr;
59
- try {
60
- if (typeof value === 'function') {
61
- valueStr = '[Function]';
62
- }
63
- else if (value === null) {
64
- valueStr = 'null';
65
- }
66
- else if (value === undefined) {
67
- valueStr = 'undefined';
68
- }
69
- else if (typeof value === 'symbol') {
70
- valueStr = `[Symbol: ${String(value)}]`;
71
- }
72
- else {
73
- valueStr = JSON.stringify(value);
74
- }
75
- }
76
- catch {
77
- valueStr = String(value);
78
- }
79
- SetExceptionMessage(exception, `Expected object but received ${actualType}: ${valueStr.slice(0, MAX_VALUE_DISPLAY_LENGTH)}`);
80
- ThrowException(exception);
81
- }
82
- }
83
- /**
84
- * Asserts that an object has a specific property (inherited or own).
85
- *
86
- * This method validates that the specified property exists in the object,
87
- * including properties from the prototype chain. Uses the 'in' operator
88
- * for property detection. This is useful for checking if an object conforms
89
- * to an expected interface or has required properties.
90
- *
91
- * @template T - The object type
92
- * @template K - The property key type
93
- * @template TError - Custom error type to throw on failure
94
- * @param value - The object to check for the property
95
- * @param property - The property key to check for
96
- * @param exception - Optional exception configuration for custom error handling
97
- * @throws {PropertyError} When object does not have the specified property
98
- *
99
- * @example
100
- * ```typescript
101
- * const obj = { name: "John", age: 30 };
102
- * AssertHasProperty(obj, "name"); // ✓ Valid (own property)
103
- * AssertHasProperty(obj, "toString"); // ✓ Valid (inherited property)
104
- * AssertHasProperty(obj, "invalid"); // ✗ Throws PropertyError
105
- *
106
- * // Type narrowing with property presence
107
- * function processUser(obj: unknown) {
108
- * AssertObject(obj);
109
- * AssertHasProperty(obj, "name");
110
- * // obj["name"] is now accessible safely
111
- * }
112
- * ```
113
- */
114
- export function AssertObjectHasProperty(value, property, exception = {}) {
115
- // First check if value is an object, using ObjectError
116
- AssertObject(value, { class: ObjectError });
117
- // Then check for property existence, using the configured exception class or default
118
- SetExceptionClass(exception, ObjectPropertyError);
119
- if (!(property in value)) {
120
- SetExceptionMessage(exception, `Expected object to have property '${String(property)}' but property was not found`);
121
- ThrowException(exception);
122
- }
123
- }
124
- /**
125
- * Asserts that an object has a specific own property (not inherited).
126
- *
127
- * This method validates that the specified property exists as an own property
128
- * of the object, excluding properties from the prototype chain. Uses
129
- * Object.prototype.hasOwnProperty.call() for reliable detection. This is useful
130
- * when you need to ensure a property is directly defined on the object.
131
- *
132
- * @template T - The object type
133
- * @template K - The property key type
134
- * @template TError - Custom error type to throw on failure
135
- * @param value - The object to check for the own property
136
- * @param property - The property key to check for
137
- * @param exception - Optional exception configuration for custom error handling
138
- * @throws {PropertyError} When object does not have the specified own property
139
- *
140
- * @example
141
- * ```typescript
142
- * const obj = { name: "John" };
143
- * AssertHasOwnProperty(obj, "name"); // ✓ Valid (own property)
144
- * AssertHasOwnProperty(obj, "toString"); // ✗ Throws (inherited property)
145
- * AssertHasOwnProperty(obj, "invalid"); // ✗ Throws (doesn't exist)
146
- *
147
- * // Checking for data vs inherited methods
148
- * function validateUserData(obj: object) {
149
- * AssertHasOwnProperty(obj, "id"); // Must be own property
150
- * AssertHasOwnProperty(obj, "name"); // Must be own property
151
- * }
152
- * ```
153
- */
154
- export function AssertObjectHasOwnProperty(value, property, exception = {}) {
155
- // First check if value is an object, using ObjectError
156
- AssertObject(value, { class: ObjectError });
157
- // Then check for own property existence, using the configured exception class or default
158
- SetExceptionClass(exception, ObjectPropertyError);
159
- if (!Object.prototype.hasOwnProperty.call(value, property)) {
160
- SetExceptionMessage(exception, `Expected object to have own property '${String(property)}' but property was not found`);
161
- ThrowException(exception);
162
- }
163
- }
164
- /**
165
- * Asserts that a specific property of an object is not null or undefined.
166
- *
167
- * This method validates that the specified property exists and has a non-nullish value.
168
- * It combines property existence checking with null/undefined validation. Useful for
169
- * validating that required object properties have been properly initialized.
170
- *
171
- * @template T - The object type
172
- * @template K - The property key type (must be a key of T)
173
- * @template TError - Custom error type to throw on failure
174
- * @param value - The object to check
175
- * @param property - The property key to validate for non-null value
176
- * @param exception - Optional exception configuration for custom error handling
177
- * @throws {PropertyError} When property is null, undefined, or doesn't exist
178
- *
179
- * @example
180
- * ```typescript
181
- * const user = { id: 123, name: "John", email: null };
182
- * AssertPropertyNotNull(user, "id"); // ✓ Valid (123 is not null/undefined)
183
- * AssertPropertyNotNull(user, "name"); // ✓ Valid ("John" is not null/undefined)
184
- * AssertPropertyNotNull(user, "email"); // ✗ Throws PropertyError (null)
185
- *
186
- * // Type narrowing for property values
187
- * function processUser(user: { name?: string | null }) {
188
- * AssertPropertyNotNull(user, "name");
189
- * // user.name is now typed as string (null/undefined excluded)
190
- * }
191
- * ```
192
- */
193
- export function AssertObjectPropertyNotNull(value, property, exception = {}) {
194
- // First check if value is an object, using ObjectError
195
- AssertObject(value, { class: ObjectError });
196
- // Then check for property value, using the configured exception class or default
197
- SetExceptionClass(exception, ObjectPropertyError);
198
- if (value[property] === null || value[property] === undefined) {
199
- const actualValue = value[property] === null ? 'null' : 'undefined';
200
- SetExceptionMessage(exception, `Expected property '${String(property)}' to be non-null/non-undefined but received ${actualValue}`);
201
- ThrowException(exception);
202
- }
203
- }
204
- //# sourceMappingURL=object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/asserts/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpF,gFAAgF;AAChF,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACrC,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,yBAAyB,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC7C,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,kCAAkC,CAAC,CAAC;QACrD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;CACD;AAED;;;;;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CAAC;IAE5C,iFAAiF;IACjF,iBAAiB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;IAClD,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,SAAS,EAAE,CAAC;QAC/D,MAAM,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC;QACpE,mBAAmB,CAAC,SAAS,EAAE,sBAAsB,MAAM,CAAC,QAAQ,CAAC,+CAA+C,WAAW,EAAE,CAAC,CAAC;QACnI,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACF,CAAC"}
@@ -1,100 +0,0 @@
1
- import type { IAssertException } from './types.js';
2
- /**
3
- * Error thrown when a value is not a valid string or fails a string assertion.
4
- *
5
- * @example
6
- * throw new StringError('Value is not a valid string');
7
- */
8
- export declare class StringError extends Error {
9
- constructor(message?: string);
10
- }
11
- /**
12
- * Asserts that a value is a string primitive type.
13
- *
14
- * This method validates that the provided value is of type 'string'. It accepts
15
- * any string including empty strings. This is a strict type check that will
16
- * reject string objects created with new String().
17
- *
18
- * @template TError - Custom error type to throw on failure
19
- * @param value - The value to validate as a string
20
- * @param exception - Optional exception configuration for custom error handling
21
- * @throws {StringError} When value is not a string primitive
22
- *
23
- * @example
24
- * ```typescript
25
- * AssertString("hello"); // ✓ Valid
26
- * AssertString(""); // ✓ Valid (empty string is still a string)
27
- * AssertString("123"); // ✓ Valid (numeric string)
28
- * AssertString(123); // ✗ Throws StringError (number)
29
- * AssertString(null); // ✗ Throws StringError
30
- * AssertString(new String("hello")); // ✗ Throws StringError (String object)
31
- * ```
32
- */
33
- export declare function AssertString(value: unknown, exception?: IAssertException): asserts value is string;
34
- /**
35
- * Asserts that a value is a non-empty string (after trimming whitespace).
36
- *
37
- * This method validates that the provided value is a string and contains at least
38
- * one non-whitespace character after trimming. This is useful for validating user
39
- * inputs, form fields, and API parameters where empty or whitespace-only strings
40
- * are not acceptable.
41
- *
42
- * @template TError - Custom error type to throw on failure
43
- * @param value - The value to validate as a non-empty string
44
- * @param exception - Optional exception configuration for custom error handling
45
- * @throws {StringError} When value is not a string or is empty/whitespace-only
46
- *
47
- * @example
48
- * ```typescript
49
- * AssertStringNotEmpty("hello"); // ✓ Valid
50
- * AssertStringNotEmpty(" a "); // ✓ Valid (has non-whitespace content)
51
- * AssertStringNotEmpty("x"); // ✓ Valid (single character)
52
- * AssertStringNotEmpty(""); // ✗ Throws StringError (empty)
53
- * AssertStringNotEmpty(" "); // ✗ Throws StringError (whitespace only)
54
- * AssertStringNotEmpty("\t\n "); // ✗ Throws StringError (whitespace only)
55
- * AssertStringNotEmpty(123); // ✗ Throws StringError (not a string)
56
- * ```
57
- */
58
- export declare function AssertStringNotEmpty(value: unknown, exception?: IAssertException): asserts value is string;
59
- /**
60
- * Asserts that a string matches a regular expression pattern.
61
- *
62
- * This method validates that the provided string matches the specified regular
63
- * expression pattern. The string must be a valid string type (use AssertString first
64
- * if needed). Useful for validating formats like emails, phone numbers, IDs, and
65
- * other structured text data.
66
- *
67
- * For performance optimization, regex patterns are cached when possible to avoid
68
- * recompilation of the same patterns. This provides significant performance benefits
69
- * when validating many values against the same pattern.
70
- *
71
- * @template TError - Custom error type to throw on failure
72
- * @param value - The string to test against the pattern
73
- * @param regex - The regular expression pattern to match against
74
- * @param exception - Optional exception configuration for custom error handling
75
- * @throws {StringError} When string does not match the pattern
76
- *
77
- * @example
78
- * ```typescript
79
- * // Email validation
80
- * AssertStringMatches("hello@example.com", /^[^\s@]+@[^\s@]+\.[^\s@]+$/); // ✓ Valid
81
- *
82
- * // Digits only validation
83
- * AssertStringMatches("123", /^\d+$/); // ✓ Valid
84
- * AssertStringMatches("12a", /^\d+$/); // ✗ Throws StringError
85
- *
86
- * // Phone number format
87
- * AssertStringMatches("(555) 123-4567", /^\(\d{3}\) \d{3}-\d{4}$/); // ✓ Valid
88
- *
89
- * // Alphanumeric with length constraint
90
- * AssertStringMatches("abc123", /^[a-zA-Z0-9]{3,10}$/); // ✓ Valid
91
- * AssertStringMatches("ab", /^[a-zA-Z0-9]{3,10}$/); // ✗ Throws (too short)
92
- *
93
- * // Performance benefit with repeated pattern usage
94
- * const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
95
- * AssertStringMatches("user1@example.com", emailPattern); // Cached for future use
96
- * AssertStringMatches("user2@example.com", emailPattern); // Uses cached pattern
97
- * ```
98
- */
99
- export declare function AssertStringMatches(value: string, regex: RegExp, exception?: IAssertException): void;
100
- //# sourceMappingURL=string.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/asserts/string.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAqDnD;;;;;GAKG;AACH,qBAAa,WAAY,SAAQ,KAAK;gBACzB,OAAO,CAAC,EAAE,MAAM;CAK5B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAMtG;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAe9G;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAkBxG"}
@@ -1,185 +0,0 @@
1
- import { SetExceptionClass, SetExceptionMessage, ThrowException } from './utils.js';
2
- /**
3
- * Cache for compiled regex patterns to improve performance when the same patterns are used repeatedly.
4
- * Maps regex source + flags to the compiled RegExp object for efficient reuse.
5
- *
6
- * @internal
7
- */
8
- const REGEX_PATTERN_CACHE = new Map();
9
- /**
10
- * Maximum number of cached regex patterns to prevent unbounded memory growth.
11
- * When this limit is reached, the cache will be cleared to maintain memory efficiency.
12
- *
13
- * @internal
14
- */
15
- const MAX_CACHE_SIZE = 100;
16
- /**
17
- * Number of oldest cache entries to evict in one batch when the cache is full.
18
- *
19
- * @internal
20
- */
21
- const CACHE_EVICTION_BATCH_SIZE = 20;
22
- /**
23
- * Gets a cached regex pattern or creates and caches a new one.
24
- * This optimization improves performance when the same regex patterns are used repeatedly.
25
- *
26
- * @param source - The regex pattern source string
27
- * @param flags - The regex flags string
28
- * @returns The compiled RegExp object
29
- * @internal
30
- */
31
- function getCachedRegex(source, flags = '') {
32
- const cacheKey = `${source}:::${flags}`;
33
- let regex = REGEX_PATTERN_CACHE.get(cacheKey);
34
- if (!regex) {
35
- // Use LRU eviction: delete oldest entries when cache reaches limit
36
- if (REGEX_PATTERN_CACHE.size >= MAX_CACHE_SIZE) {
37
- const keysToDelete = Array.from(REGEX_PATTERN_CACHE.keys()).slice(0, CACHE_EVICTION_BATCH_SIZE);
38
- keysToDelete.forEach(key => REGEX_PATTERN_CACHE.delete(key));
39
- }
40
- regex = new RegExp(source, flags);
41
- REGEX_PATTERN_CACHE.set(cacheKey, regex);
42
- }
43
- return regex;
44
- }
45
- /**
46
- * Error thrown when a value is not a valid string or fails a string assertion.
47
- *
48
- * @example
49
- * throw new StringError('Value is not a valid string');
50
- */
51
- export class StringError extends Error {
52
- constructor(message) {
53
- super(message ?? 'String Assertion Failed');
54
- this.name = 'StringError';
55
- Object.setPrototypeOf(this, StringError.prototype);
56
- }
57
- }
58
- /**
59
- * Asserts that a value is a string primitive type.
60
- *
61
- * This method validates that the provided value is of type 'string'. It accepts
62
- * any string including empty strings. This is a strict type check that will
63
- * reject string objects created with new String().
64
- *
65
- * @template TError - Custom error type to throw on failure
66
- * @param value - The value to validate as a string
67
- * @param exception - Optional exception configuration for custom error handling
68
- * @throws {StringError} When value is not a string primitive
69
- *
70
- * @example
71
- * ```typescript
72
- * AssertString("hello"); // ✓ Valid
73
- * AssertString(""); // ✓ Valid (empty string is still a string)
74
- * AssertString("123"); // ✓ Valid (numeric string)
75
- * AssertString(123); // ✗ Throws StringError (number)
76
- * AssertString(null); // ✗ Throws StringError
77
- * AssertString(new String("hello")); // ✗ Throws StringError (String object)
78
- * ```
79
- */
80
- export function AssertString(value, exception = {}) {
81
- SetExceptionClass(exception, StringError);
82
- if (typeof value !== 'string') {
83
- SetExceptionMessage(exception, `Expected string but received ${typeof value}: ${String(value)}`);
84
- ThrowException(exception);
85
- }
86
- }
87
- /**
88
- * Asserts that a value is a non-empty string (after trimming whitespace).
89
- *
90
- * This method validates that the provided value is a string and contains at least
91
- * one non-whitespace character after trimming. This is useful for validating user
92
- * inputs, form fields, and API parameters where empty or whitespace-only strings
93
- * are not acceptable.
94
- *
95
- * @template TError - Custom error type to throw on failure
96
- * @param value - The value to validate as a non-empty string
97
- * @param exception - Optional exception configuration for custom error handling
98
- * @throws {StringError} When value is not a string or is empty/whitespace-only
99
- *
100
- * @example
101
- * ```typescript
102
- * AssertStringNotEmpty("hello"); // ✓ Valid
103
- * AssertStringNotEmpty(" a "); // ✓ Valid (has non-whitespace content)
104
- * AssertStringNotEmpty("x"); // ✓ Valid (single character)
105
- * AssertStringNotEmpty(""); // ✗ Throws StringError (empty)
106
- * AssertStringNotEmpty(" "); // ✗ Throws StringError (whitespace only)
107
- * AssertStringNotEmpty("\t\n "); // ✗ Throws StringError (whitespace only)
108
- * AssertStringNotEmpty(123); // ✗ Throws StringError (not a string)
109
- * ```
110
- */
111
- export function AssertStringNotEmpty(value, exception = {}) {
112
- SetExceptionClass(exception, StringError);
113
- if (typeof value !== 'string') {
114
- SetExceptionMessage(exception, `Expected non-empty string but received ${typeof value}: ${String(value)}`);
115
- ThrowException(exception);
116
- }
117
- const str = value;
118
- if (str === '') {
119
- SetExceptionMessage(exception, 'Expected non-empty string but received empty string');
120
- ThrowException(exception);
121
- }
122
- if (str.trim() === '') {
123
- SetExceptionMessage(exception, 'Expected non-empty string but received whitespace-only string');
124
- ThrowException(exception);
125
- }
126
- }
127
- /**
128
- * Asserts that a string matches a regular expression pattern.
129
- *
130
- * This method validates that the provided string matches the specified regular
131
- * expression pattern. The string must be a valid string type (use AssertString first
132
- * if needed). Useful for validating formats like emails, phone numbers, IDs, and
133
- * other structured text data.
134
- *
135
- * For performance optimization, regex patterns are cached when possible to avoid
136
- * recompilation of the same patterns. This provides significant performance benefits
137
- * when validating many values against the same pattern.
138
- *
139
- * @template TError - Custom error type to throw on failure
140
- * @param value - The string to test against the pattern
141
- * @param regex - The regular expression pattern to match against
142
- * @param exception - Optional exception configuration for custom error handling
143
- * @throws {StringError} When string does not match the pattern
144
- *
145
- * @example
146
- * ```typescript
147
- * // Email validation
148
- * AssertStringMatches("hello@example.com", /^[^\s@]+@[^\s@]+\.[^\s@]+$/); // ✓ Valid
149
- *
150
- * // Digits only validation
151
- * AssertStringMatches("123", /^\d+$/); // ✓ Valid
152
- * AssertStringMatches("12a", /^\d+$/); // ✗ Throws StringError
153
- *
154
- * // Phone number format
155
- * AssertStringMatches("(555) 123-4567", /^\(\d{3}\) \d{3}-\d{4}$/); // ✓ Valid
156
- *
157
- * // Alphanumeric with length constraint
158
- * AssertStringMatches("abc123", /^[a-zA-Z0-9]{3,10}$/); // ✓ Valid
159
- * AssertStringMatches("ab", /^[a-zA-Z0-9]{3,10}$/); // ✗ Throws (too short)
160
- *
161
- * // Performance benefit with repeated pattern usage
162
- * const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
163
- * AssertStringMatches("user1@example.com", emailPattern); // Cached for future use
164
- * AssertStringMatches("user2@example.com", emailPattern); // Uses cached pattern
165
- * ```
166
- */
167
- export function AssertStringMatches(value, regex, exception = {}) {
168
- SetExceptionClass(exception, StringError);
169
- AssertString(value, exception); // Ensure value is a string before matching
170
- // Use cached regex for better performance when possible
171
- // If the regex has a source and flags, we can cache it for reuse
172
- let testRegex;
173
- if (regex.source && regex.flags !== undefined) {
174
- testRegex = getCachedRegex(regex.source, regex.flags);
175
- }
176
- else {
177
- // Fallback to original regex if caching is not possible
178
- testRegex = regex;
179
- }
180
- if (!testRegex.test(value)) {
181
- SetExceptionMessage(exception, `String does not match the required pattern: ${regex.toString()}`);
182
- ThrowException(exception);
183
- }
184
- }
185
- //# sourceMappingURL=string.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/asserts/string.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEpF;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,cAAc,GAAG,GAAG,CAAC;AAE3B;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,MAAc,EAAE,QAAgB,EAAE;IACzD,MAAM,QAAQ,GAAG,GAAG,MAAM,MAAM,KAAK,EAAE,CAAC;IACxC,IAAI,KAAK,GAAG,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE9C,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,mEAAmE;QACnE,IAAI,mBAAmB,CAAC,IAAI,IAAI,cAAc,EAAE,CAAC;YAChD,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,yBAAyB,CAAC,CAAC;YAChG,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,KAAK,GAAG,IAAI,MAAM,CAAC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;QACtF,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACvB,mBAAmB,CAAC,SAAS,EAAE,+DAA+D,CAAC,CAAC;QAChG,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa,EAAE,KAAa,EAAE,YAA8B,EAAE;IACjG,iBAAiB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC1C,YAAY,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,2CAA2C;IAE3E,wDAAwD;IACxD,iEAAiE;IACjE,IAAI,SAAiB,CAAC;IACtB,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;QAC/C,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACP,wDAAwD;QACxD,SAAS,GAAG,KAAK,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,mBAAmB,CAAC,SAAS,EAAE,+CAA+C,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAClG,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACF,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=enum.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.test.d.ts","sourceRoot":"","sources":["../../src/enum/enum.test.ts"],"names":[],"mappings":""}
@@ -1,122 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { EnumEntries } from './enum-entries.js';
3
- import { EnumKeyByValue } from './enum-key-by-value.js';
4
- import { EnumKeys } from './enum-keys.js';
5
- import { EnumSafeValue } from './enum-safe-value.js';
6
- import { EnumValues } from './enum-values.js';
7
- import { ValidateEnumValue } from './validate-enum-value.js';
8
- var Direction;
9
- (function (Direction) {
10
- Direction["Up"] = "UP";
11
- Direction["Down"] = "DOWN";
12
- Direction["Left"] = "LEFT";
13
- Direction["Right"] = "RIGHT";
14
- })(Direction || (Direction = {}));
15
- var Status;
16
- (function (Status) {
17
- Status[Status["Active"] = 1] = "Active";
18
- Status[Status["Inactive"] = 2] = "Inactive";
19
- Status[Status["Pending"] = 3] = "Pending";
20
- })(Status || (Status = {}));
21
- describe('EnumEntries', () => {
22
- it('returns key-value pairs for a string enum', () => {
23
- const entries = EnumEntries(Direction);
24
- expect(entries).toEqual([
25
- ['Up', 'UP'],
26
- ['Down', 'DOWN'],
27
- ['Left', 'LEFT'],
28
- ['Right', 'RIGHT'],
29
- ]);
30
- });
31
- it('filters out numeric reverse-mapping keys', () => {
32
- const entries = EnumEntries(Status);
33
- // Numeric enums have reverse mappings like { 1: 'Active', Active: 1 }
34
- // EnumEntries should return only the non-numeric ones
35
- entries.forEach(([key]) => {
36
- expect(Number.isNaN(Number(key))).toBe(true);
37
- });
38
- expect(entries).toHaveLength(3);
39
- });
40
- it('returns empty array for null/undefined input', () => {
41
- expect(EnumEntries(null)).toEqual([]);
42
- });
43
- });
44
- describe('EnumKeys', () => {
45
- it('returns keys for a string enum', () => {
46
- expect(EnumKeys(Direction)).toEqual(['Up', 'Down', 'Left', 'Right']);
47
- });
48
- it('returns only non-numeric keys for a numeric enum', () => {
49
- const keys = EnumKeys(Status);
50
- expect(keys).toEqual(['Active', 'Inactive', 'Pending']);
51
- });
52
- it('returns empty array for null input', () => {
53
- expect(EnumKeys(null)).toEqual([]);
54
- });
55
- });
56
- describe('EnumValues', () => {
57
- it('returns values for a string enum', () => {
58
- expect(EnumValues(Direction)).toEqual(['UP', 'DOWN', 'LEFT', 'RIGHT']);
59
- });
60
- it('returns numeric values for a numeric enum', () => {
61
- expect(EnumValues(Status)).toEqual([1, 2, 3]);
62
- });
63
- it('returns empty array for null input', () => {
64
- expect(EnumValues(null)).toEqual([]);
65
- });
66
- });
67
- describe('ValidateEnumValue', () => {
68
- it('returns true for a valid string enum value', () => {
69
- expect(ValidateEnumValue(Direction, 'UP')).toBe(true);
70
- });
71
- it('returns false for an invalid value', () => {
72
- expect(ValidateEnumValue(Direction, 'DIAGONAL')).toBe(false);
73
- });
74
- it('returns true for a valid numeric enum value', () => {
75
- expect(ValidateEnumValue(Status, 1)).toBe(true);
76
- });
77
- it('returns false for an invalid numeric value', () => {
78
- expect(ValidateEnumValue(Status, 99)).toBe(false);
79
- });
80
- it('returns false for null/undefined value', () => {
81
- expect(ValidateEnumValue(Direction, null)).toBe(false);
82
- expect(ValidateEnumValue(Direction, undefined)).toBe(false);
83
- });
84
- it('returns false for null enum', () => {
85
- expect(ValidateEnumValue(null, 'UP')).toBe(false);
86
- });
87
- });
88
- describe('EnumKeyByValue', () => {
89
- it('returns key for a valid value', () => {
90
- expect(EnumKeyByValue(Direction, 'UP')).toBe('Up');
91
- expect(EnumKeyByValue(Direction, 'DOWN')).toBe('Down');
92
- });
93
- it('returns undefined for an unknown value', () => {
94
- expect(EnumKeyByValue(Direction, 'DIAGONAL')).toBeUndefined();
95
- });
96
- it('returns undefined for null/undefined value', () => {
97
- expect(EnumKeyByValue(Direction, null)).toBeUndefined();
98
- expect(EnumKeyByValue(Direction, undefined)).toBeUndefined();
99
- });
100
- it('returns undefined for null enum', () => {
101
- expect(EnumKeyByValue(null, 'UP')).toBeUndefined();
102
- });
103
- it('works with numeric enum', () => {
104
- expect(EnumKeyByValue(Status, 1)).toBe('Active');
105
- });
106
- });
107
- describe('EnumSafeValue', () => {
108
- it('returns the original value when valid', () => {
109
- expect(EnumSafeValue(Direction, 'UP', 'DOWN')).toBe('UP');
110
- });
111
- it('returns the fallback when value is invalid', () => {
112
- expect(EnumSafeValue(Direction, 'DIAGONAL', 'DOWN')).toBe('DOWN');
113
- });
114
- it('returns the fallback for null value', () => {
115
- expect(EnumSafeValue(Direction, null, 'UP')).toBe('UP');
116
- });
117
- it('works with numeric enums', () => {
118
- expect(EnumSafeValue(Status, 1, 2)).toBe(1);
119
- expect(EnumSafeValue(Status, 99, 2)).toBe(2);
120
- });
121
- });
122
- //# sourceMappingURL=enum.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.test.js","sourceRoot":"","sources":["../../src/enum/enum.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,IAAK,SAKJ;AALD,WAAK,SAAS;IACb,sBAAS,CAAA;IACT,0BAAa,CAAA;IACb,0BAAa,CAAA;IACb,4BAAe,CAAA;AAChB,CAAC,EALI,SAAS,KAAT,SAAS,QAKb;AAED,IAAK,MAIJ;AAJD,WAAK,MAAM;IACV,uCAAU,CAAA;IACV,2CAAY,CAAA;IACZ,yCAAW,CAAA;AACZ,CAAC,EAJI,MAAM,KAAN,MAAM,QAIV;AAED,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACpD,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;QACvC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;YACvB,CAAC,IAAI,EAAE,IAAI,CAAC;YACZ,CAAC,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,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=function.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"function.test.d.ts","sourceRoot":"","sources":["../../src/function/function.test.ts"],"names":[],"mappings":""}