@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.
- package/README.md +1 -118
- package/build/array/array-chunk.d.ts +10 -4
- package/build/array/array-chunk.d.ts.map +1 -1
- package/build/array/array-chunk.js +10 -4
- package/build/array/array-chunk.js.map +1 -1
- package/build/array/array-contains.d.ts +11 -3
- package/build/array/array-contains.d.ts.map +1 -1
- package/build/array/array-contains.js +11 -3
- package/build/array/array-contains.js.map +1 -1
- package/build/array/array-group-by.d.ts +14 -5
- package/build/array/array-group-by.d.ts.map +1 -1
- package/build/array/array-group-by.js +14 -5
- package/build/array/array-group-by.js.map +1 -1
- package/build/array/array-shuffle.d.ts +12 -3
- package/build/array/array-shuffle.d.ts.map +1 -1
- package/build/array/array-shuffle.js +12 -3
- package/build/array/array-shuffle.js.map +1 -1
- package/build/array/unique.d.ts +13 -3
- package/build/array/unique.d.ts.map +1 -1
- package/build/array/unique.js +13 -3
- package/build/array/unique.js.map +1 -1
- package/build/asserts/errors.d.ts +91 -7
- package/build/asserts/errors.d.ts.map +1 -1
- package/build/asserts/errors.js +91 -7
- package/build/asserts/errors.js.map +1 -1
- package/build/asserts/generic.d.ts +8 -4
- package/build/asserts/generic.d.ts.map +1 -1
- package/build/asserts/generic.js +8 -4
- package/build/asserts/generic.js.map +1 -1
- package/build/enum/enum-entries.d.ts +8 -3
- package/build/enum/enum-entries.d.ts.map +1 -1
- package/build/enum/enum-entries.js +8 -3
- package/build/enum/enum-entries.js.map +1 -1
- package/build/enum/enum-key-by-value.d.ts +10 -5
- package/build/enum/enum-key-by-value.d.ts.map +1 -1
- package/build/enum/enum-key-by-value.js +10 -5
- package/build/enum/enum-key-by-value.js.map +1 -1
- package/build/enum/enum-keys.d.ts +12 -3
- package/build/enum/enum-keys.d.ts.map +1 -1
- package/build/enum/enum-keys.js +12 -3
- package/build/enum/enum-keys.js.map +1 -1
- package/build/enum/enum-safe-value.d.ts +11 -6
- package/build/enum/enum-safe-value.d.ts.map +1 -1
- package/build/enum/enum-safe-value.js +11 -6
- package/build/enum/enum-safe-value.js.map +1 -1
- package/build/enum/validate-enum-value.d.ts +10 -5
- package/build/enum/validate-enum-value.d.ts.map +1 -1
- package/build/enum/validate-enum-value.js +10 -5
- package/build/enum/validate-enum-value.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/number/assert.d.ts +14 -14
- package/build/number/assert.d.ts.map +1 -1
- package/build/object/clone.d.ts +17 -6
- package/build/object/clone.d.ts.map +1 -1
- package/build/object/clone.js +17 -6
- package/build/object/clone.js.map +1 -1
- package/build/object/filter-cached.d.ts +15 -3
- package/build/object/filter-cached.d.ts.map +1 -1
- package/build/object/filter-cached.js +15 -3
- package/build/object/filter-cached.js.map +1 -1
- package/build/object/has-circular-reference.d.ts +12 -3
- package/build/object/has-circular-reference.d.ts.map +1 -1
- package/build/object/has-circular-reference.js +12 -3
- package/build/object/has-circular-reference.js.map +1 -1
- package/build/object/key-value-pairs.d.ts +11 -3
- package/build/object/key-value-pairs.d.ts.map +1 -1
- package/build/object/key-value-pairs.js +11 -3
- package/build/object/key-value-pairs.js.map +1 -1
- package/build/object/map-cached.d.ts +14 -3
- package/build/object/map-cached.d.ts.map +1 -1
- package/build/object/map-cached.js +14 -3
- package/build/object/map-cached.js.map +1 -1
- package/build/object/merge.d.ts +18 -7
- package/build/object/merge.d.ts.map +1 -1
- package/build/object/merge.js +18 -7
- package/build/object/merge.js.map +1 -1
- package/build/object/omit.d.ts +13 -4
- package/build/object/omit.d.ts.map +1 -1
- package/build/object/omit.js +13 -4
- package/build/object/omit.js.map +1 -1
- package/build/string/formatting.d.ts +10 -3
- package/build/string/formatting.d.ts.map +1 -1
- package/build/string/formatting.js +10 -3
- package/build/string/formatting.js.map +1 -1
- package/package.json +9 -5
- package/build/array/array.test.d.ts +0 -2
- package/build/array/array.test.d.ts.map +0 -1
- package/build/array/array.test.js +0 -347
- package/build/array/array.test.js.map +0 -1
- package/build/asserts/object.d.ts +0 -138
- package/build/asserts/object.d.ts.map +0 -1
- package/build/asserts/object.js +0 -204
- package/build/asserts/object.js.map +0 -1
- package/build/asserts/string.d.ts +0 -100
- package/build/asserts/string.d.ts.map +0 -1
- package/build/asserts/string.js +0 -185
- package/build/asserts/string.js.map +0 -1
- package/build/enum/enum.test.d.ts +0 -2
- package/build/enum/enum.test.d.ts.map +0 -1
- package/build/enum/enum.test.js +0 -122
- package/build/enum/enum.test.js.map +0 -1
- package/build/function/function.test.d.ts +0 -2
- package/build/function/function.test.d.ts.map +0 -1
- package/build/function/function.test.js +0 -158
- package/build/function/function.test.js.map +0 -1
- package/build/object/object.test.d.ts +0 -2
- package/build/object/object.test.d.ts.map +0 -1
- package/build/object/object.test.js +0 -432
- package/build/object/object.test.js.map +0 -1
- package/build/string/string.test.d.ts +0 -2
- package/build/string/string.test.d.ts.map +0 -1
- package/build/string/string.test.js +0 -321
- package/build/string/string.test.js.map +0 -1
- package/build/time/time.test.d.ts +0 -2
- package/build/time/time.test.d.ts.map +0 -1
- package/build/time/time.test.js +0 -211
- package/build/time/time.test.js.map +0 -1
package/README.md
CHANGED
|
@@ -186,124 +186,7 @@ Cross-cutting assertions not tied to a single type, plus the shared assertion in
|
|
|
186
186
|
|
|
187
187
|
```bash
|
|
188
188
|
yarn install # Install dependencies
|
|
189
|
-
yarn build # Compile TypeScript → ./build/
|
|
190
|
-
yarn dev # Build + run
|
|
191
|
-
yarn watch # Watch mode
|
|
192
|
-
yarn typecheck # Type check without building
|
|
193
|
-
yarn lint # ESLint
|
|
194
|
-
yarn lint:fix # ESLint with auto-fix
|
|
195
|
-
yarn test # Run tests
|
|
196
|
-
yarn test:ui # Interactive Vitest UI
|
|
197
|
-
yarn test:coverage # Tests with coverage report
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
## Requirements
|
|
201
|
-
|
|
202
|
-
- Node.js >= 24.0.0
|
|
203
|
-
|
|
204
|
-
## License
|
|
205
|
-
|
|
206
|
-
MIT — See [LICENSE](./LICENSE) for details.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
## API
|
|
210
|
-
|
|
211
|
-
### Array utilities — `ArrayUtils`
|
|
212
|
-
|
|
213
|
-
| Export | Description |
|
|
214
|
-
|--------|-------------|
|
|
215
|
-
| `ArrayChunk(array, size)` | Split an array into chunks of a given size |
|
|
216
|
-
| `ArrayContains(array, predicate)` | Check if any element satisfies a predicate |
|
|
217
|
-
| `ArrayFilter(array, predicate)` | Type-safe array filter |
|
|
218
|
-
| `ArrayGroupBy(array, keyFn)` | Group array elements by a key function |
|
|
219
|
-
| `ArrayIntersection(a, b)` | Return elements present in both arrays |
|
|
220
|
-
| `ArrayShuffle(array)` | Return a shuffled copy of an array |
|
|
221
|
-
| `Unique(array)` | Remove duplicate values |
|
|
222
|
-
| `ArrayDifference(a, b)` | Elements in `a` not present in `b` |
|
|
223
|
-
| `ArrayFlatten(array, depth?)` | Flatten a nested array to a given depth |
|
|
224
|
-
| `ArrayCompact(array)` | Remove `null`/`undefined`, narrowing the type |
|
|
225
|
-
| `ArrayPartition(array, predicate)` | Split into `[matches, rest]` |
|
|
226
|
-
| `ArrayZip(...arrays)` | Zip multiple arrays into tuples |
|
|
227
|
-
| `ArrayRange(start, end, step?)` | Generate a numeric sequence |
|
|
228
|
-
| `ArraySortBy(array, keyFn, direction?)` | Immutable sort by a computed key |
|
|
229
|
-
| `ArrayCountBy(array, keyFn)` | Count elements per group key |
|
|
230
|
-
| `ArraySample(array, n?)` | Random element or `n` random elements |
|
|
231
|
-
|
|
232
|
-
### Object utilities — `ObjectUtils`
|
|
233
|
-
|
|
234
|
-
| Export | Description |
|
|
235
|
-
|--------|-------------|
|
|
236
|
-
| `AssertObject(value)` | Assert a value is a non-null object |
|
|
237
|
-
| `ObjectClone(obj)` | Deep-clone an object |
|
|
238
|
-
| `ObjectEquals(a, b)` | Deep equality check |
|
|
239
|
-
| `ObjectFilter(obj, predicate)` | Filter object entries by predicate |
|
|
240
|
-
| `FilterObject(obj, keys)` | Keep only specified keys |
|
|
241
|
-
| `ObjectPick(obj, keys)` | Pick a subset of keys |
|
|
242
|
-
| `ObjectOmit(obj, keys)` | Omit specified keys |
|
|
243
|
-
| `ObjectMerge(target, ...sources)` | Deep merge objects |
|
|
244
|
-
| `MapObject(obj, fn)` | Map over object values |
|
|
245
|
-
| `TransformObject(obj, fn)` | Transform object entries |
|
|
246
|
-
| `ObjectHash(obj)` | Compute a stable hash of an object |
|
|
247
|
-
| `ObjectSortKeys(obj)` | Return object with keys sorted |
|
|
248
|
-
| `ObjectFromKeyValuePairs(pairs)` | Build an object from `[key, value]` pairs |
|
|
249
|
-
| `ObjectToKeyValuePairs(obj)` | Convert an object to `[key, value]` pairs |
|
|
250
|
-
| `ObjectGetPropertyByPath(obj, path)` | Get a nested property by dot-path |
|
|
251
|
-
| `ObjectSetPropertyByPath(obj, path, value)` | Set a nested property by dot-path |
|
|
252
|
-
| `ObjectInvert(obj)` | Swap keys and values |
|
|
253
|
-
| `ObjectFlatten(obj, separator?)` | Flatten nested object to dot-separated keys |
|
|
254
|
-
| `ObjectDiff(objA, objB)` | Compute added/removed/changed keys between two objects |
|
|
255
|
-
|
|
256
|
-
### String utilities — `StringUtils`
|
|
257
|
-
|
|
258
|
-
| Export | Description |
|
|
259
|
-
|--------|-------------|
|
|
260
|
-
| `CamelCase(str)` | Convert a string to camelCase |
|
|
261
|
-
| `PASCAL_CASE(str)` | Convert a string to PascalCase |
|
|
262
|
-
| `KEBAB_CASE(str)` | Convert a string to kebab-case |
|
|
263
|
-
| `SNAKE_CASE(str)` | Convert a string to snake_case |
|
|
264
|
-
| `SCREAMING_SNAKE_CASE(str)` | Convert a string to SCREAMING_SNAKE_CASE |
|
|
265
|
-
| `FormatString(template, values)` | Simple string template formatting |
|
|
266
|
-
| `EscapeHTML(str)` | Escape HTML special characters |
|
|
267
|
-
| `StripHTML(str)` | Remove all HTML tags from a string |
|
|
268
|
-
| `Pluralize(word, count, plural?)` | Return singular or plural form based on count |
|
|
269
|
-
| `WordCount(str)` | Count the number of words in a string |
|
|
270
|
-
| `CountOccurrences(str, substr)` | Count non-overlapping occurrences of a substring |
|
|
271
|
-
|
|
272
|
-
### Time utilities — `TimeUtils`
|
|
273
|
-
|
|
274
|
-
| Export | Description |
|
|
275
|
-
|--------|-------------|
|
|
276
|
-
| `ElapsedTime` | Measure elapsed time with human-readable output |
|
|
277
|
-
| `Stopwatch` | Lap-based stopwatch for benchmarking |
|
|
278
|
-
|
|
279
|
-
### Enum utilities — `EnumUtils`
|
|
280
|
-
|
|
281
|
-
| Export | Description |
|
|
282
|
-
|--------|-------------|
|
|
283
|
-
| `EnumKeys(enumObj)` | Get keys of a TypeScript enum |
|
|
284
|
-
| `EnumValues(enumObj)` | Get values of a TypeScript enum |
|
|
285
|
-
| `EnumEntries(enumObj)` | Get key-value pairs of a TypeScript enum |
|
|
286
|
-
| `ValidateEnumValue(enumObj, value)` | Check if a value is a valid enum member |
|
|
287
|
-
| `EnumKeyByValue(enumObj, value)` | Look up an enum key by its value |
|
|
288
|
-
| `EnumSafeValue(enumObj, value)` | Return the value if valid, or `undefined` |
|
|
289
|
-
|
|
290
|
-
### Function utilities — `FunctionUtils`
|
|
291
|
-
|
|
292
|
-
| Export | Description |
|
|
293
|
-
|--------|-------------|
|
|
294
|
-
| `Debounce(fn, ms)` | Delay execution until `ms` ms after the last call |
|
|
295
|
-
| `Throttle(fn, ms)` | Limit execution to at most once per `ms` ms |
|
|
296
|
-
| `Memoize(fn, keyFn?)` | Cache results by serialised arguments |
|
|
297
|
-
| `Once(fn)` | Execute a function at most once, caching the result |
|
|
298
|
-
| `Pipe(...fns)` | Compose functions left-to-right |
|
|
299
|
-
| `Compose(...fns)` | Compose functions right-to-left |
|
|
300
|
-
| `Sleep(ms)` | Return a `Promise` that resolves after `ms` ms |
|
|
301
|
-
|
|
302
|
-
## Development
|
|
303
|
-
|
|
304
|
-
```bash
|
|
305
|
-
yarn install # Install dependencies
|
|
306
|
-
yarn build # Compile TypeScript → ./build/
|
|
189
|
+
yarn build # Compile TypeScript (tsconfig.build.json) → ./build/
|
|
307
190
|
yarn dev # Build + run
|
|
308
191
|
yarn watch # Watch mode
|
|
309
192
|
yarn typecheck # Type check without building
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Chunks an array into smaller arrays of a specified size.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The array to split
|
|
6
|
+
* @param size - Size of each chunk (last chunk may be smaller)
|
|
7
|
+
* @returns Array of arrays, each of the specified size
|
|
8
|
+
*
|
|
6
9
|
* @example
|
|
7
|
-
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* ArrayChunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
12
|
+
* ArrayChunk(['a', 'b', 'c'], 2); // [['a', 'b'], ['c']]
|
|
13
|
+
* ```
|
|
8
14
|
*/
|
|
9
15
|
export declare function ArrayChunk<T>(array: T[], size: number): T[][];
|
|
10
16
|
//# sourceMappingURL=array-chunk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-chunk.d.ts","sourceRoot":"","sources":["../../src/array/array-chunk.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"array-chunk.d.ts","sourceRoot":"","sources":["../../src/array/array-chunk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAY7D"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Chunks an array into smaller arrays of a specified size.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The array to split
|
|
6
|
+
* @param size - Size of each chunk (last chunk may be smaller)
|
|
7
|
+
* @returns Array of arrays, each of the specified size
|
|
8
|
+
*
|
|
6
9
|
* @example
|
|
7
|
-
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* ArrayChunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
12
|
+
* ArrayChunk(['a', 'b', 'c'], 2); // [['a', 'b'], ['c']]
|
|
13
|
+
* ```
|
|
8
14
|
*/
|
|
9
15
|
export function ArrayChunk(array, size) {
|
|
10
16
|
if (!array || size <= 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-chunk.js","sourceRoot":"","sources":["../../src/array/array-chunk.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"array-chunk.js","sourceRoot":"","sources":["../../src/array/array-chunk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,UAAU,CAAI,KAAU,EAAE,IAAY;IACrD,IAAI,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,MAAM,GAAU,EAAE,CAAC;IAEzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { TPredicate } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if an array contains at least one element that passes a predicate test.
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of array elements
|
|
6
|
+
* @param array - The array to check
|
|
7
|
+
* @param predicate - A function that tests each element; returns `true` to signal a match
|
|
8
|
+
* @returns `true` if at least one element passes the test, `false` otherwise
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* ArrayContains([1, 2, 3], (n) => n > 2); // true
|
|
13
|
+
* ArrayContains([1, 2, 3], (n) => n > 10); // false
|
|
14
|
+
* ```
|
|
7
15
|
*/
|
|
8
16
|
export declare function ArrayContains<T>(array: T[], predicate: TPredicate<T>): boolean;
|
|
9
17
|
//# sourceMappingURL=array-contains.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-contains.d.ts","sourceRoot":"","sources":["../../src/array/array-contains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C
|
|
1
|
+
{"version":3,"file":"array-contains.d.ts","sourceRoot":"","sources":["../../src/array/array-contains.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAM9E"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if an array contains at least one element that passes a predicate test.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The array to check
|
|
6
|
+
* @param predicate - A function that tests each element; returns `true` to signal a match
|
|
7
|
+
* @returns `true` if at least one element passes the test, `false` otherwise
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* ArrayContains([1, 2, 3], (n) => n > 2); // true
|
|
12
|
+
* ArrayContains([1, 2, 3], (n) => n > 10); // false
|
|
13
|
+
* ```
|
|
6
14
|
*/
|
|
7
15
|
export function ArrayContains(array, predicate) {
|
|
8
16
|
if (!array || array.length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-contains.js","sourceRoot":"","sources":["../../src/array/array-contains.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"array-contains.js","sourceRoot":"","sources":["../../src/array/array-contains.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAI,KAAU,EAAE,SAAwB;IACpE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import type { TTransform } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Groups array elements by a key generated by a provided function.
|
|
4
|
-
*
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of array elements
|
|
6
|
+
* @template K - The key type (string, number, or symbol)
|
|
7
|
+
* @param array - The array to group
|
|
8
|
+
* @param keyFn - Function that returns the grouping key for each element
|
|
9
|
+
* @returns A record where each key maps to an array of matching elements
|
|
10
|
+
*
|
|
7
11
|
* @example
|
|
12
|
+
* ```typescript
|
|
8
13
|
* const items = [{ category: 'fruit', name: 'apple' }, { category: 'vegetable', name: 'carrot' }];
|
|
9
|
-
*
|
|
10
|
-
* //
|
|
14
|
+
* ArrayGroupBy(items, (item) => item.category);
|
|
15
|
+
* // { fruit: [{ category: 'fruit', name: 'apple' }], vegetable: [{ category: 'vegetable', name: 'carrot' }] }
|
|
16
|
+
*
|
|
17
|
+
* ArrayGroupBy(['one', 'two', 'three'], (s) => s.length);
|
|
18
|
+
* // { 3: ['one', 'two'], 5: ['three'] }
|
|
19
|
+
* ```
|
|
11
20
|
*/
|
|
12
21
|
export declare function ArrayGroupBy<T, K extends string | number | symbol>(array: T[], keyFn: TTransform<T, K>): Record<K, T[]>;
|
|
13
22
|
//# sourceMappingURL=array-group-by.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-group-by.d.ts","sourceRoot":"","sources":["../../src/array/array-group-by.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C
|
|
1
|
+
{"version":3,"file":"array-group-by.d.ts","sourceRoot":"","sources":["../../src/array/array-group-by.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAavH"}
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Groups array elements by a key generated by a provided function.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @template K - The key type (string, number, or symbol)
|
|
6
|
+
* @param array - The array to group
|
|
7
|
+
* @param keyFn - Function that returns the grouping key for each element
|
|
8
|
+
* @returns A record where each key maps to an array of matching elements
|
|
9
|
+
*
|
|
6
10
|
* @example
|
|
11
|
+
* ```typescript
|
|
7
12
|
* const items = [{ category: 'fruit', name: 'apple' }, { category: 'vegetable', name: 'carrot' }];
|
|
8
|
-
*
|
|
9
|
-
* //
|
|
13
|
+
* ArrayGroupBy(items, (item) => item.category);
|
|
14
|
+
* // { fruit: [{ category: 'fruit', name: 'apple' }], vegetable: [{ category: 'vegetable', name: 'carrot' }] }
|
|
15
|
+
*
|
|
16
|
+
* ArrayGroupBy(['one', 'two', 'three'], (s) => s.length);
|
|
17
|
+
* // { 3: ['one', 'two'], 5: ['three'] }
|
|
18
|
+
* ```
|
|
10
19
|
*/
|
|
11
20
|
export function ArrayGroupBy(array, keyFn) {
|
|
12
21
|
if (!array) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-group-by.js","sourceRoot":"","sources":["../../src/array/array-group-by.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"array-group-by.js","sourceRoot":"","sources":["../../src/array/array-group-by.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY,CAAwC,KAAU,EAAE,KAAuB;IACtG,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,EAAoB,CAAC;IAC7B,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACjC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACf,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACf,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,GAAG,CAAC;IACZ,CAAC,EAAE,EAAoB,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a shuffled copy of the array using the Fisher-Yates algorithm.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The array to shuffle
|
|
6
|
+
* @returns A new shuffled array (original is not mutated)
|
|
7
|
+
*
|
|
8
|
+
* @remarks Uses `Math.random()` — not cryptographically secure. Do not use for
|
|
9
|
+
* security-sensitive operations.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* ArrayShuffle([1, 2, 3, 4, 5]); // e.g. [3, 1, 5, 2, 4]
|
|
14
|
+
* ```
|
|
6
15
|
*/
|
|
7
16
|
export declare function ArrayShuffle<T>(array: T[]): T[];
|
|
8
17
|
//# sourceMappingURL=array-shuffle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-shuffle.d.ts","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"array-shuffle.d.ts","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAa/C"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a shuffled copy of the array using the Fisher-Yates algorithm.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The array to shuffle
|
|
6
|
+
* @returns A new shuffled array (original is not mutated)
|
|
7
|
+
*
|
|
8
|
+
* @remarks Uses `Math.random()` — not cryptographically secure. Do not use for
|
|
9
|
+
* security-sensitive operations.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* ArrayShuffle([1, 2, 3, 4, 5]); // e.g. [3, 1, 5, 2, 4]
|
|
14
|
+
* ```
|
|
6
15
|
*/
|
|
7
16
|
export function ArrayShuffle(array) {
|
|
8
17
|
if (!array)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-shuffle.js","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"array-shuffle.js","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,YAAY,CAAI,KAAU;IACzC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAE1B,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAM,CAAC;QAC3B,MAAM,CAAC,CAAC,CAAC,GAAG,IAAS,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
package/build/array/unique.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a new array with duplicate values removed.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The input array
|
|
6
|
+
* @returns A new array containing only unique values (preserves first occurrence order)
|
|
7
|
+
*
|
|
8
|
+
* @remarks Uses reference equality for objects. Two distinct objects with
|
|
9
|
+
* identical property values are **not** considered equal and will both be kept.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* Unique([1, 2, 2, 3, 1]); // [1, 2, 3]
|
|
14
|
+
* Unique(['a', 'b', 'a']); // ['a', 'b']
|
|
15
|
+
* ```
|
|
6
16
|
*/
|
|
7
17
|
export declare function Unique<T>(array: T[]): T[];
|
|
8
18
|
//# sourceMappingURL=unique.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unique.d.ts","sourceRoot":"","sources":["../../src/array/unique.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"unique.d.ts","sourceRoot":"","sources":["../../src/array/unique.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAMzC"}
|
package/build/array/unique.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a new array with duplicate values removed.
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of array elements
|
|
5
|
+
* @param array - The input array
|
|
6
|
+
* @returns A new array containing only unique values (preserves first occurrence order)
|
|
7
|
+
*
|
|
8
|
+
* @remarks Uses reference equality for objects. Two distinct objects with
|
|
9
|
+
* identical property values are **not** considered equal and will both be kept.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* Unique([1, 2, 2, 3, 1]); // [1, 2, 3]
|
|
14
|
+
* Unique(['a', 'b', 'a']); // ['a', 'b']
|
|
15
|
+
* ```
|
|
6
16
|
*/
|
|
7
17
|
export function Unique(array) {
|
|
8
18
|
if (!array) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unique.js","sourceRoot":"","sources":["../../src/array/unique.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"unique.js","sourceRoot":"","sources":["../../src/array/unique.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,MAAM,CAAI,KAAU;IACnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;IACX,CAAC;IAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -1,45 +1,129 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Base error class for all custom errors
|
|
2
|
+
* Base error class for all custom errors in the assertion library.
|
|
3
|
+
*
|
|
4
|
+
* Extends the built-in `Error` with a machine-readable `Code` string and an
|
|
5
|
+
* optional `Context` bag for structured diagnostic metadata. All other error
|
|
6
|
+
* classes in this module extend `BaseError`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* class MyError extends BaseError {
|
|
11
|
+
* constructor(message: string) {
|
|
12
|
+
* super(message, 'MY_ERROR');
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* throw new MyError('Something went wrong');
|
|
16
|
+
* ```
|
|
3
17
|
*/
|
|
4
18
|
export declare class BaseError extends Error {
|
|
5
19
|
readonly Code: string;
|
|
6
20
|
readonly Context: Record<string, unknown> | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* @param message - Human-readable description of the error
|
|
23
|
+
* @param code - Machine-readable error code (e.g. `'VALIDATION_ERROR'`)
|
|
24
|
+
* @param context - Optional structured metadata for diagnostics
|
|
25
|
+
*/
|
|
7
26
|
constructor(message: string, code: string, context?: Record<string, unknown>);
|
|
8
27
|
}
|
|
9
28
|
/**
|
|
10
|
-
* Error thrown when validation
|
|
29
|
+
* Error thrown when input data fails a validation rule.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* throw new ValidationError('Email address is not valid', { field: 'email' });
|
|
34
|
+
* ```
|
|
11
35
|
*/
|
|
12
36
|
export declare class ValidationError extends BaseError {
|
|
37
|
+
/**
|
|
38
|
+
* @param message - Description of the validation failure
|
|
39
|
+
* @param context - Optional structured metadata for diagnostics
|
|
40
|
+
*/
|
|
13
41
|
constructor(message: string, context?: Record<string, unknown>);
|
|
14
42
|
}
|
|
15
43
|
/**
|
|
16
|
-
* Error thrown when a type assertion fails
|
|
44
|
+
* Error thrown when a runtime type assertion fails.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* throw new AssertionError('Expected string but received number');
|
|
49
|
+
* ```
|
|
17
50
|
*/
|
|
18
51
|
export declare class AssertionError extends BaseError {
|
|
52
|
+
/**
|
|
53
|
+
* @param message - Description of the failed assertion
|
|
54
|
+
* @param context - Optional structured metadata for diagnostics
|
|
55
|
+
*/
|
|
19
56
|
constructor(message: string, context?: Record<string, unknown>);
|
|
20
57
|
}
|
|
21
58
|
/**
|
|
22
|
-
* Error thrown when
|
|
59
|
+
* Error thrown when a function argument is invalid.
|
|
60
|
+
* The error message is auto-formatted as
|
|
61
|
+
* `"Invalid argument '<argumentName>': <reason>"`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* throw new InvalidArgumentError('userId', 'must be a positive integer');
|
|
66
|
+
* // message: "Invalid argument 'userId': must be a positive integer"
|
|
67
|
+
* ```
|
|
23
68
|
*/
|
|
24
69
|
export declare class InvalidArgumentError extends BaseError {
|
|
70
|
+
/**
|
|
71
|
+
* @param argumentName - Name of the invalid argument
|
|
72
|
+
* @param reason - Explanation of why the argument is invalid
|
|
73
|
+
* @param context - Optional structured metadata for diagnostics
|
|
74
|
+
*/
|
|
25
75
|
constructor(argumentName: string, reason: string, context?: Record<string, unknown>);
|
|
26
76
|
}
|
|
27
77
|
/**
|
|
28
|
-
* Error thrown when
|
|
78
|
+
* Error thrown when a requested operation is not supported in the current context.
|
|
79
|
+
* The error message is auto-formatted as `"Operation not supported: <operation>"`.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* throw new NotSupportedError('bulk delete in read-only mode');
|
|
84
|
+
* // message: "Operation not supported: bulk delete in read-only mode"
|
|
85
|
+
* ```
|
|
29
86
|
*/
|
|
30
87
|
export declare class NotSupportedError extends BaseError {
|
|
88
|
+
/**
|
|
89
|
+
* @param operation - Description of the unsupported operation
|
|
90
|
+
* @param context - Optional structured metadata for diagnostics
|
|
91
|
+
*/
|
|
31
92
|
constructor(operation: string, context?: Record<string, unknown>);
|
|
32
93
|
}
|
|
33
94
|
/**
|
|
34
|
-
* Error thrown when a required value
|
|
95
|
+
* Error thrown when a required resource or value cannot be found.
|
|
96
|
+
* The error message is auto-formatted as `"Not found: <item>"`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* throw new NotFoundError('user with id 42');
|
|
101
|
+
* // message: "Not found: user with id 42"
|
|
102
|
+
* ```
|
|
35
103
|
*/
|
|
36
104
|
export declare class NotFoundError extends BaseError {
|
|
105
|
+
/**
|
|
106
|
+
* @param item - Description of the resource that was not found
|
|
107
|
+
* @param context - Optional structured metadata for diagnostics
|
|
108
|
+
*/
|
|
37
109
|
constructor(item: string, context?: Record<string, unknown>);
|
|
38
110
|
}
|
|
39
111
|
/**
|
|
40
|
-
* Error thrown when buffer
|
|
112
|
+
* Error thrown when a buffer or collection exceeds its maximum capacity.
|
|
113
|
+
* The error message is auto-formatted as
|
|
114
|
+
* `"Buffer overflow: maximum size <maxSize> exceeded"`.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* throw new BufferOverflowError(1000);
|
|
119
|
+
* // message: "Buffer overflow: maximum size 1000 exceeded"
|
|
120
|
+
* ```
|
|
41
121
|
*/
|
|
42
122
|
export declare class BufferOverflowError extends BaseError {
|
|
123
|
+
/**
|
|
124
|
+
* @param maxSize - The maximum capacity that was exceeded
|
|
125
|
+
* @param context - Optional structured metadata for diagnostics
|
|
126
|
+
*/
|
|
43
127
|
constructor(maxSize: number, context?: Record<string, unknown>);
|
|
44
128
|
}
|
|
45
129
|
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/asserts/errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/asserts/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,SAAU,SAAQ,KAAK;IACnC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAE7D;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAS5E;AAED;;;;;;;GAOG;AACH,qBAAa,eAAgB,SAAQ,SAAS;IAC7C;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG9D;AAED;;;;;;;GAOG;AACH,qBAAa,cAAe,SAAQ,SAAS;IAC5C;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG9D;AAED;;;;;;;;;;GAUG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;IAClD;;;;OAIG;gBACS,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAGnF;AAED;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC/C;;;OAGG;gBACS,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAGhE;AAED;;;;;;;;;GASG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAC3C;;;OAGG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG3D;AAED;;;;;;;;;;GAUG;AACH,qBAAa,mBAAoB,SAAQ,SAAS;IACjD;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG9D"}
|