ts-data-forge 1.5.0 → 1.5.2
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/dist/array/array-utils.d.mts +137 -358
- package/dist/array/array-utils.d.mts.map +1 -1
- package/dist/array/array-utils.mjs +191 -1966
- package/dist/array/array-utils.mjs.map +1 -1
- package/dist/array/tuple-utils.d.mts +9 -23
- package/dist/array/tuple-utils.d.mts.map +1 -1
- package/dist/array/tuple-utils.mjs +10 -56
- package/dist/array/tuple-utils.mjs.map +1 -1
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/collections/queue.mjs.map +1 -1
- package/dist/collections/stack.mjs.map +1 -1
- package/dist/functional/match.d.mts +2 -33
- package/dist/functional/match.d.mts.map +1 -1
- package/dist/functional/match.mjs +2 -119
- package/dist/functional/match.mjs.map +1 -1
- package/dist/functional/optional.d.mts +34 -197
- package/dist/functional/optional.d.mts.map +1 -1
- package/dist/functional/optional.mjs +40 -312
- package/dist/functional/optional.mjs.map +1 -1
- package/dist/functional/pipe.d.mts +2 -15
- package/dist/functional/pipe.d.mts.map +1 -1
- package/dist/functional/pipe.mjs +2 -110
- package/dist/functional/pipe.mjs.map +1 -1
- package/dist/functional/result.d.mts +18 -209
- package/dist/functional/result.d.mts.map +1 -1
- package/dist/functional/result.mjs +40 -360
- package/dist/functional/result.mjs.map +1 -1
- package/dist/guard/has-key.d.mts +1 -1
- package/dist/guard/has-key.mjs +1 -1
- package/dist/iterator/range.d.mts +2 -6
- package/dist/iterator/range.d.mts.map +1 -1
- package/dist/iterator/range.mjs +2 -93
- package/dist/iterator/range.mjs.map +1 -1
- package/dist/json/json.d.mts +14 -438
- package/dist/json/json.d.mts.map +1 -1
- package/dist/json/json.mjs +14 -438
- package/dist/json/json.mjs.map +1 -1
- package/dist/number/num.d.mts +7 -107
- package/dist/number/num.d.mts.map +1 -1
- package/dist/number/num.mjs +7 -122
- package/dist/number/num.mjs.map +1 -1
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +4 -10
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +8 -140
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/map-nullable.d.mts +2 -6
- package/dist/others/map-nullable.d.mts.map +1 -1
- package/dist/others/map-nullable.mjs +2 -146
- package/dist/others/map-nullable.mjs.map +1 -1
- package/dist/others/memoize-function.mjs.map +1 -1
- package/dist/others/unknown-to-string.mjs.map +1 -1
- package/package.json +11 -11
- package/src/array/array-utils.mts +707 -881
- package/src/array/tuple-utils.mts +20 -41
- package/src/functional/match.mts +18 -44
- package/src/functional/optional.mts +93 -248
- package/src/functional/pipe.mts +25 -20
- package/src/functional/result.mts +114 -288
- package/src/guard/has-key.mts +1 -1
- package/src/iterator/range.mts +14 -17
- package/src/json/json.mts +14 -438
- package/src/number/num.mts +20 -113
- package/src/object/object.mts +30 -45
- package/src/others/map-nullable.mts +13 -15
package/dist/number/num.d.mts
CHANGED
|
@@ -39,10 +39,7 @@ export declare namespace Num {
|
|
|
39
39
|
* @returns The numeric representation of `n`.
|
|
40
40
|
* @example
|
|
41
41
|
* ```typescript
|
|
42
|
-
* Num.from('123'); // 123
|
|
43
42
|
* Num.from('123.45'); // 123.45
|
|
44
|
-
* Num.from(true); // 1
|
|
45
|
-
* Num.from(false); // 0
|
|
46
43
|
* Num.from('hello'); // NaN
|
|
47
44
|
* ```
|
|
48
45
|
*/
|
|
@@ -204,15 +201,6 @@ export declare namespace Num {
|
|
|
204
201
|
*
|
|
205
202
|
* @example
|
|
206
203
|
* ```typescript
|
|
207
|
-
* // Array index validation
|
|
208
|
-
* const isValidIndex = Num.isUintInRange(0, 10);
|
|
209
|
-
* const index: number = getUserInput();
|
|
210
|
-
*
|
|
211
|
-
* if (isValidIndex(index)) {
|
|
212
|
-
* // index is typed as 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
213
|
-
* const value = array[index]; // Safe array access
|
|
214
|
-
* }
|
|
215
|
-
*
|
|
216
204
|
* // Custom range validation
|
|
217
205
|
* const isValidPercentage = Num.isUintInRange(0, 101);
|
|
218
206
|
* if (isValidPercentage(value)) {
|
|
@@ -239,20 +227,12 @@ export declare namespace Num {
|
|
|
239
227
|
*
|
|
240
228
|
* @example
|
|
241
229
|
* ```typescript
|
|
242
|
-
* // Score validation (0-100)
|
|
243
230
|
* const isValidScore = Num.isUintInRangeInclusive(0, 100);
|
|
244
231
|
* const score: number = getTestScore();
|
|
245
|
-
*
|
|
246
232
|
* if (isValidScore(score)) {
|
|
247
233
|
* // score is typed as 0 | 1 | 2 | ... | 100
|
|
248
234
|
* const grade = calculateGrade(score);
|
|
249
235
|
* }
|
|
250
|
-
*
|
|
251
|
-
* // Day of month validation
|
|
252
|
-
* const isValidDay = Num.isUintInRangeInclusive(1, 31);
|
|
253
|
-
* if (isValidDay(day)) {
|
|
254
|
-
* // day is typed as 1 | 2 | ... | 31
|
|
255
|
-
* }
|
|
256
236
|
* ```
|
|
257
237
|
*/
|
|
258
238
|
export const isUintInRangeInclusive: <L extends SmallUint, U extends SmallUint>(lowerBound: L, upperBound: U) => (x: number) => x is RelaxedExclude<LEQ[U], LT[Min<L>]>;
|
|
@@ -264,44 +244,18 @@ export declare namespace Num {
|
|
|
264
244
|
* - **Curried usage**: Pass bounds to get a reusable clamping function
|
|
265
245
|
*
|
|
266
246
|
* @example
|
|
267
|
-
* Direct usage:
|
|
268
247
|
* ```typescript
|
|
248
|
+
* // Direct usage
|
|
269
249
|
* Num.clamp(15, 0, 10); // 10 (clamped to upper bound)
|
|
270
|
-
* Num.clamp(-5, 0, 10); // 0 (clamped to lower bound)
|
|
271
250
|
* Num.clamp(5, 0, 10); // 5 (within bounds)
|
|
272
|
-
* Num.clamp(NaN, 0, 10); // 0 (invalid values default to lower bound)
|
|
273
|
-
* ```
|
|
274
251
|
*
|
|
275
|
-
*
|
|
276
|
-
* Curried usage for reusable functions:
|
|
277
|
-
* ```typescript
|
|
252
|
+
* // Curried usage
|
|
278
253
|
* const clampToPercent = Num.clamp(0, 100);
|
|
279
254
|
* clampToPercent(150); // 100
|
|
280
|
-
* clampToPercent(-10); // 0
|
|
281
|
-
* clampToPercent(75); // 75
|
|
282
|
-
*
|
|
283
|
-
* // Perfect for pipe composition
|
|
284
|
-
* const result = pipe(userInput)
|
|
285
|
-
* .map(Number)
|
|
286
|
-
* .map(clampToPercent).value;
|
|
287
|
-
* ```
|
|
288
|
-
*
|
|
289
|
-
* @example
|
|
290
|
-
* Working with arrays and functional programming:
|
|
291
|
-
* ```typescript
|
|
292
|
-
* const clampTo0_1 = Num.clamp(0, 1);
|
|
293
|
-
* const normalizedValues = values.map(clampTo0_1);
|
|
294
|
-
*
|
|
295
|
-
* // Temperature clamping
|
|
296
|
-
* const clampTemperature = Num.clamp(-40, 50);
|
|
297
|
-
* const safeTemperatures = readings.map(clampTemperature);
|
|
298
255
|
* ```
|
|
299
256
|
*/
|
|
300
|
-
export
|
|
301
|
-
|
|
302
|
-
(target: number, lowerBound: number, upperBound: number): number;
|
|
303
|
-
(lowerBound: number, upperBound: number): (target: number) => number;
|
|
304
|
-
};
|
|
257
|
+
export function clamp(target: number, lowerBound: number, upperBound: number): number;
|
|
258
|
+
export function clamp(lowerBound: number, upperBound: number): (target: number) => number;
|
|
305
259
|
/**
|
|
306
260
|
* Performs type-safe division with compile-time zero-check.
|
|
307
261
|
*
|
|
@@ -315,11 +269,7 @@ export declare namespace Num {
|
|
|
315
269
|
*
|
|
316
270
|
* @example
|
|
317
271
|
* ```typescript
|
|
318
|
-
*
|
|
319
|
-
* const result1 = Num.div(10, 2); // 5
|
|
320
|
-
* const result2 = Num.div(7, 3); // 2.3333...
|
|
321
|
-
*
|
|
322
|
-
* // Compile-time error prevention
|
|
272
|
+
* const result = Num.div(10, 2); // 5
|
|
323
273
|
* // Num.div(10, 0); // ❌ TypeScript error: Type '0' is not assignable
|
|
324
274
|
*
|
|
325
275
|
* // With type guards
|
|
@@ -351,9 +301,6 @@ export declare namespace Num {
|
|
|
351
301
|
* ```typescript
|
|
352
302
|
* Num.divInt(10, 3); // 3
|
|
353
303
|
* Num.divInt(10, -3); // -4 (floor division)
|
|
354
|
-
* Num.divInt(-10, 3); // -4
|
|
355
|
-
* Num.divInt(10.7, 3.2); // 3 (floors both inputs first)
|
|
356
|
-
* Num.divInt(10, 0); // NaN
|
|
357
304
|
* ```
|
|
358
305
|
*/
|
|
359
306
|
export const divInt: (a: number, b: NonZeroNumber | SmallInt<"!=0">) => number;
|
|
@@ -370,10 +317,7 @@ export declare namespace Num {
|
|
|
370
317
|
* @example
|
|
371
318
|
* ```typescript
|
|
372
319
|
* Num.roundAt(3.14159, 2); // 3.14
|
|
373
|
-
* Num.roundAt(3.14159, 4); // 3.1416
|
|
374
320
|
* Num.roundAt(10.5, 0); // 11
|
|
375
|
-
* Num.roundAt(-10.5, 0); // -10
|
|
376
|
-
* Num.roundAt(0.005, 2); // 0.01
|
|
377
321
|
* ```
|
|
378
322
|
*/
|
|
379
323
|
export const roundAt: (num: number, precision: PositiveSafeIntWithSmallInt) => number;
|
|
@@ -391,9 +335,6 @@ export declare namespace Num {
|
|
|
391
335
|
* ```typescript
|
|
392
336
|
* Num.roundToInt(3.2); // 3
|
|
393
337
|
* Num.roundToInt(3.5); // 4
|
|
394
|
-
* Num.roundToInt(3.8); // 4
|
|
395
|
-
* Num.roundToInt(-3.2); // -3
|
|
396
|
-
* Num.roundToInt(-3.8); // -3
|
|
397
338
|
* ```
|
|
398
339
|
*/
|
|
399
340
|
export const roundToInt: (num: number) => Int;
|
|
@@ -409,19 +350,9 @@ export declare namespace Num {
|
|
|
409
350
|
*
|
|
410
351
|
* @example
|
|
411
352
|
* ```typescript
|
|
412
|
-
* // Create specialized rounding functions
|
|
413
353
|
* const roundTo2 = Num.round(2);
|
|
414
|
-
* const roundTo4 = Num.round(4);
|
|
415
|
-
*
|
|
416
354
|
* roundTo2(3.14159); // 3.14
|
|
417
355
|
* roundTo2(2.71828); // 2.72
|
|
418
|
-
* roundTo2(10); // 10
|
|
419
|
-
*
|
|
420
|
-
* roundTo4(3.14159); // 3.1416
|
|
421
|
-
*
|
|
422
|
-
* // Use with array operations
|
|
423
|
-
* const values = [1.234, 5.678, 9.012];
|
|
424
|
-
* const rounded = values.map(roundTo2); // [1.23, 5.68, 9.01]
|
|
425
356
|
* ```
|
|
426
357
|
*/
|
|
427
358
|
export const round: (digit: PositiveSafeIntWithSmallInt) => ((num: number) => number);
|
|
@@ -438,20 +369,8 @@ export declare namespace Num {
|
|
|
438
369
|
*
|
|
439
370
|
* @example
|
|
440
371
|
* ```typescript
|
|
441
|
-
* Num.mapNaN2Undefined(42);
|
|
442
|
-
* Num.mapNaN2Undefined(
|
|
443
|
-
* Num.mapNaN2Undefined(NaN); // undefined
|
|
444
|
-
* Num.mapNaN2Undefined(Math.sqrt(-1)); // undefined
|
|
445
|
-
*
|
|
446
|
-
* // Useful in chains
|
|
447
|
-
* const result = Num.mapNaN2Undefined(parseFloat(userInput)) ?? 0;
|
|
448
|
-
*
|
|
449
|
-
* // Type narrowing
|
|
450
|
-
* const value = Math.sqrt(x);
|
|
451
|
-
* const safe = Num.mapNaN2Undefined(value);
|
|
452
|
-
* if (safe !== undefined) {
|
|
453
|
-
* // safe is typed without NaN
|
|
454
|
-
* }
|
|
372
|
+
* Num.mapNaN2Undefined(42); // 42
|
|
373
|
+
* Num.mapNaN2Undefined(NaN); // undefined
|
|
455
374
|
* ```
|
|
456
375
|
*/
|
|
457
376
|
export const mapNaN2Undefined: <N extends number>(num: N) => RelaxedExclude<N, NaNType> | undefined;
|
|
@@ -470,15 +389,6 @@ export declare namespace Num {
|
|
|
470
389
|
* ```typescript
|
|
471
390
|
* const zero = 0 as 0;
|
|
472
391
|
* const one = Num.increment(zero); // type is 1, value is 1
|
|
473
|
-
*
|
|
474
|
-
* const five = 5 as 5;
|
|
475
|
-
* const six = Num.increment(five); // type is 6, value is 6
|
|
476
|
-
*
|
|
477
|
-
* // Type-safe counter
|
|
478
|
-
* type Counter<N extends SmallUint> = {
|
|
479
|
-
* value: N;
|
|
480
|
-
* next(): Counter<Increment<N>>;
|
|
481
|
-
* };
|
|
482
392
|
* ```
|
|
483
393
|
*/
|
|
484
394
|
export const increment: <N extends SmallUint>(n: N) => Increment<N>;
|
|
@@ -497,16 +407,6 @@ export declare namespace Num {
|
|
|
497
407
|
* ```typescript
|
|
498
408
|
* const three = 3 as 3;
|
|
499
409
|
* const two = Num.decrement(three); // type is 2, value is 2
|
|
500
|
-
*
|
|
501
|
-
* const one = 1 as 1;
|
|
502
|
-
* const zero = Num.decrement(one); // type is 0, value is 0
|
|
503
|
-
*
|
|
504
|
-
* // Type-safe countdown
|
|
505
|
-
* function countdown<N extends PositiveSmallInt>(
|
|
506
|
-
* n: N
|
|
507
|
-
* ): N extends 1 ? 0 : Decrement<N> {
|
|
508
|
-
* return Num.decrement(n);
|
|
509
|
-
* }
|
|
510
410
|
* ```
|
|
511
411
|
*/
|
|
512
412
|
export const decrement: <N extends PositiveSmallInt>(n: N) => Decrement<N>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"num.d.mts","sourceRoot":"","sources":["../../src/number/num.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,yBAAiB,GAAG,CAAC;IACnB
|
|
1
|
+
{"version":3,"file":"num.d.mts","sourceRoot":"","sources":["../../src/number/num.mts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,yBAAiB,GAAG,CAAC;IACnB;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,MAAe,CAAC;IAEnD;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,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KAAK,GAChB,OAAO,2BAA2B,KACjC,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAI1B,CAAC;IAEF;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,EAC/C,KAAK,CAAC,KACL,cAAc,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,SAIS,CAAC;IAE1C;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,MAAM,SAAS,GAAI,CAAC,SAAS,SAAS,EAAE,GAAG,CAAC,KAAG,SAAS,CAAC,CAAC,CAExC,CAAC;IAE1B;;;;;;;;;;;;;;;;OAgBG;IACH,MAAM,CAAC,MAAM,SAAS,GAAI,CAAC,SAAS,gBAAgB,EAAE,GAAG,CAAC,KAAG,SAAS,CAAC,CAAC,CAE/C,CAAC;;CAC3B"}
|
package/dist/number/num.mjs
CHANGED
|
@@ -40,10 +40,7 @@ var Num;
|
|
|
40
40
|
* @returns The numeric representation of `n`.
|
|
41
41
|
* @example
|
|
42
42
|
* ```typescript
|
|
43
|
-
* Num.from('123'); // 123
|
|
44
43
|
* Num.from('123.45'); // 123.45
|
|
45
|
-
* Num.from(true); // 1
|
|
46
|
-
* Num.from(false); // 0
|
|
47
44
|
* Num.from('hello'); // NaN
|
|
48
45
|
* ```
|
|
49
46
|
*/
|
|
@@ -177,15 +174,6 @@ var Num;
|
|
|
177
174
|
*
|
|
178
175
|
* @example
|
|
179
176
|
* ```typescript
|
|
180
|
-
* // Array index validation
|
|
181
|
-
* const isValidIndex = Num.isUintInRange(0, 10);
|
|
182
|
-
* const index: number = getUserInput();
|
|
183
|
-
*
|
|
184
|
-
* if (isValidIndex(index)) {
|
|
185
|
-
* // index is typed as 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
186
|
-
* const value = array[index]; // Safe array access
|
|
187
|
-
* }
|
|
188
|
-
*
|
|
189
177
|
* // Custom range validation
|
|
190
178
|
* const isValidPercentage = Num.isUintInRange(0, 101);
|
|
191
179
|
* if (isValidPercentage(value)) {
|
|
@@ -212,66 +200,16 @@ var Num;
|
|
|
212
200
|
*
|
|
213
201
|
* @example
|
|
214
202
|
* ```typescript
|
|
215
|
-
* // Score validation (0-100)
|
|
216
203
|
* const isValidScore = Num.isUintInRangeInclusive(0, 100);
|
|
217
204
|
* const score: number = getTestScore();
|
|
218
|
-
*
|
|
219
205
|
* if (isValidScore(score)) {
|
|
220
206
|
* // score is typed as 0 | 1 | 2 | ... | 100
|
|
221
207
|
* const grade = calculateGrade(score);
|
|
222
208
|
* }
|
|
223
|
-
*
|
|
224
|
-
* // Day of month validation
|
|
225
|
-
* const isValidDay = Num.isUintInRangeInclusive(1, 31);
|
|
226
|
-
* if (isValidDay(day)) {
|
|
227
|
-
* // day is typed as 1 | 2 | ... | 31
|
|
228
|
-
* }
|
|
229
209
|
* ```
|
|
230
210
|
*/
|
|
231
211
|
Num.isUintInRangeInclusive = (lowerBound, upperBound) => (x) => Number.isSafeInteger(x) && lowerBound <= x && x <= upperBound;
|
|
232
|
-
|
|
233
|
-
* Clamps a value within the given range. If the target value is invalid (not finite), returns the lower bound.
|
|
234
|
-
*
|
|
235
|
-
* Provides two usage patterns for maximum flexibility:
|
|
236
|
-
* - **Direct usage**: Pass all three arguments to get the clamped value immediately
|
|
237
|
-
* - **Curried usage**: Pass bounds to get a reusable clamping function
|
|
238
|
-
*
|
|
239
|
-
* @example
|
|
240
|
-
* Direct usage:
|
|
241
|
-
* ```typescript
|
|
242
|
-
* Num.clamp(15, 0, 10); // 10 (clamped to upper bound)
|
|
243
|
-
* Num.clamp(-5, 0, 10); // 0 (clamped to lower bound)
|
|
244
|
-
* Num.clamp(5, 0, 10); // 5 (within bounds)
|
|
245
|
-
* Num.clamp(NaN, 0, 10); // 0 (invalid values default to lower bound)
|
|
246
|
-
* ```
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* Curried usage for reusable functions:
|
|
250
|
-
* ```typescript
|
|
251
|
-
* const clampToPercent = Num.clamp(0, 100);
|
|
252
|
-
* clampToPercent(150); // 100
|
|
253
|
-
* clampToPercent(-10); // 0
|
|
254
|
-
* clampToPercent(75); // 75
|
|
255
|
-
*
|
|
256
|
-
* // Perfect for pipe composition
|
|
257
|
-
* const result = pipe(userInput)
|
|
258
|
-
* .map(Number)
|
|
259
|
-
* .map(clampToPercent).value;
|
|
260
|
-
* ```
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* Working with arrays and functional programming:
|
|
264
|
-
* ```typescript
|
|
265
|
-
* const clampTo0_1 = Num.clamp(0, 1);
|
|
266
|
-
* const normalizedValues = values.map(clampTo0_1);
|
|
267
|
-
*
|
|
268
|
-
* // Temperature clamping
|
|
269
|
-
* const clampTemperature = Num.clamp(-40, 50);
|
|
270
|
-
* const safeTemperatures = readings.map(clampTemperature);
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
274
|
-
Num.clamp = ((...args) => {
|
|
212
|
+
function clamp(...args) {
|
|
275
213
|
switch (args.length) {
|
|
276
214
|
case 3: {
|
|
277
215
|
const [target, lowerBound, upperBound] = args;
|
|
@@ -281,10 +219,11 @@ var Num;
|
|
|
281
219
|
}
|
|
282
220
|
case 2: {
|
|
283
221
|
const [lowerBound, upperBound] = args;
|
|
284
|
-
return (target) =>
|
|
222
|
+
return (target) => clamp(target, lowerBound, upperBound);
|
|
285
223
|
}
|
|
286
224
|
}
|
|
287
|
-
}
|
|
225
|
+
}
|
|
226
|
+
Num.clamp = clamp;
|
|
288
227
|
/**
|
|
289
228
|
* Performs type-safe division with compile-time zero-check.
|
|
290
229
|
*
|
|
@@ -298,11 +237,7 @@ var Num;
|
|
|
298
237
|
*
|
|
299
238
|
* @example
|
|
300
239
|
* ```typescript
|
|
301
|
-
*
|
|
302
|
-
* const result1 = Num.div(10, 2); // 5
|
|
303
|
-
* const result2 = Num.div(7, 3); // 2.3333...
|
|
304
|
-
*
|
|
305
|
-
* // Compile-time error prevention
|
|
240
|
+
* const result = Num.div(10, 2); // 5
|
|
306
241
|
* // Num.div(10, 0); // ❌ TypeScript error: Type '0' is not assignable
|
|
307
242
|
*
|
|
308
243
|
* // With type guards
|
|
@@ -334,9 +269,6 @@ var Num;
|
|
|
334
269
|
* ```typescript
|
|
335
270
|
* Num.divInt(10, 3); // 3
|
|
336
271
|
* Num.divInt(10, -3); // -4 (floor division)
|
|
337
|
-
* Num.divInt(-10, 3); // -4
|
|
338
|
-
* Num.divInt(10.7, 3.2); // 3 (floors both inputs first)
|
|
339
|
-
* Num.divInt(10, 0); // NaN
|
|
340
272
|
* ```
|
|
341
273
|
*/
|
|
342
274
|
Num.divInt = (a, b) => Math.floor(Math.floor(a) / Math.floor(b));
|
|
@@ -353,10 +285,7 @@ var Num;
|
|
|
353
285
|
* @example
|
|
354
286
|
* ```typescript
|
|
355
287
|
* Num.roundAt(3.14159, 2); // 3.14
|
|
356
|
-
* Num.roundAt(3.14159, 4); // 3.1416
|
|
357
288
|
* Num.roundAt(10.5, 0); // 11
|
|
358
|
-
* Num.roundAt(-10.5, 0); // -10
|
|
359
|
-
* Num.roundAt(0.005, 2); // 0.01
|
|
360
289
|
* ```
|
|
361
290
|
*/
|
|
362
291
|
Num.roundAt = (num, precision) => {
|
|
@@ -377,9 +306,6 @@ var Num;
|
|
|
377
306
|
* ```typescript
|
|
378
307
|
* Num.roundToInt(3.2); // 3
|
|
379
308
|
* Num.roundToInt(3.5); // 4
|
|
380
|
-
* Num.roundToInt(3.8); // 4
|
|
381
|
-
* Num.roundToInt(-3.2); // -3
|
|
382
|
-
* Num.roundToInt(-3.8); // -3
|
|
383
309
|
* ```
|
|
384
310
|
*/
|
|
385
311
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
@@ -396,19 +322,9 @@ var Num;
|
|
|
396
322
|
*
|
|
397
323
|
* @example
|
|
398
324
|
* ```typescript
|
|
399
|
-
* // Create specialized rounding functions
|
|
400
325
|
* const roundTo2 = Num.round(2);
|
|
401
|
-
* const roundTo4 = Num.round(4);
|
|
402
|
-
*
|
|
403
326
|
* roundTo2(3.14159); // 3.14
|
|
404
327
|
* roundTo2(2.71828); // 2.72
|
|
405
|
-
* roundTo2(10); // 10
|
|
406
|
-
*
|
|
407
|
-
* roundTo4(3.14159); // 3.1416
|
|
408
|
-
*
|
|
409
|
-
* // Use with array operations
|
|
410
|
-
* const values = [1.234, 5.678, 9.012];
|
|
411
|
-
* const rounded = values.map(roundTo2); // [1.23, 5.68, 9.01]
|
|
412
328
|
* ```
|
|
413
329
|
*/
|
|
414
330
|
Num.round = (digit) => {
|
|
@@ -428,20 +344,8 @@ var Num;
|
|
|
428
344
|
*
|
|
429
345
|
* @example
|
|
430
346
|
* ```typescript
|
|
431
|
-
* Num.mapNaN2Undefined(42);
|
|
432
|
-
* Num.mapNaN2Undefined(
|
|
433
|
-
* Num.mapNaN2Undefined(NaN); // undefined
|
|
434
|
-
* Num.mapNaN2Undefined(Math.sqrt(-1)); // undefined
|
|
435
|
-
*
|
|
436
|
-
* // Useful in chains
|
|
437
|
-
* const result = Num.mapNaN2Undefined(parseFloat(userInput)) ?? 0;
|
|
438
|
-
*
|
|
439
|
-
* // Type narrowing
|
|
440
|
-
* const value = Math.sqrt(x);
|
|
441
|
-
* const safe = Num.mapNaN2Undefined(value);
|
|
442
|
-
* if (safe !== undefined) {
|
|
443
|
-
* // safe is typed without NaN
|
|
444
|
-
* }
|
|
347
|
+
* Num.mapNaN2Undefined(42); // 42
|
|
348
|
+
* Num.mapNaN2Undefined(NaN); // undefined
|
|
445
349
|
* ```
|
|
446
350
|
*/
|
|
447
351
|
Num.mapNaN2Undefined = (num) => Number.isNaN(num)
|
|
@@ -463,15 +367,6 @@ var Num;
|
|
|
463
367
|
* ```typescript
|
|
464
368
|
* const zero = 0 as 0;
|
|
465
369
|
* const one = Num.increment(zero); // type is 1, value is 1
|
|
466
|
-
*
|
|
467
|
-
* const five = 5 as 5;
|
|
468
|
-
* const six = Num.increment(five); // type is 6, value is 6
|
|
469
|
-
*
|
|
470
|
-
* // Type-safe counter
|
|
471
|
-
* type Counter<N extends SmallUint> = {
|
|
472
|
-
* value: N;
|
|
473
|
-
* next(): Counter<Increment<N>>;
|
|
474
|
-
* };
|
|
475
370
|
* ```
|
|
476
371
|
*/
|
|
477
372
|
Num.increment = (n) =>
|
|
@@ -492,16 +387,6 @@ var Num;
|
|
|
492
387
|
* ```typescript
|
|
493
388
|
* const three = 3 as 3;
|
|
494
389
|
* const two = Num.decrement(three); // type is 2, value is 2
|
|
495
|
-
*
|
|
496
|
-
* const one = 1 as 1;
|
|
497
|
-
* const zero = Num.decrement(one); // type is 0, value is 0
|
|
498
|
-
*
|
|
499
|
-
* // Type-safe countdown
|
|
500
|
-
* function countdown<N extends PositiveSmallInt>(
|
|
501
|
-
* n: N
|
|
502
|
-
* ): N extends 1 ? 0 : Decrement<N> {
|
|
503
|
-
* return Num.decrement(n);
|
|
504
|
-
* }
|
|
505
390
|
* ```
|
|
506
391
|
*/
|
|
507
392
|
Num.decrement = (n) =>
|
package/dist/number/num.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"num.mjs","sources":["../../src/number/num.mts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCG;IACc;AAAjB,CAAA,UAAiB,GAAG,EAAA;AAClB
|
|
1
|
+
{"version":3,"file":"num.mjs","sources":["../../src/number/num.mts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCG;IACc;AAAjB,CAAA,UAAiB,GAAG,EAAA;AAClB;;;;;;;;;AASG;IACU,GAAA,CAAA,IAAI,GAA2B,MAAM;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;IACU,GAAA,CAAA,SAAS,GAAG,CACvB,G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;;;;;;;;;AAgBG;IACU,GAAA,CAAA,gBAAgB,GAAG,CAC9B,GAAM,KAEN,MAAM,CAAC,KAAK,CAAC,GAAG;AACd,UAAE;AACF;AACG,YAAA,GAAkC;AAEzC;;;;;;;;;;;;;;;;AAgBG;AACU,IAAA,GAAA,CAAA,SAAS,GAAG,CAAsB,CAAI;;AAEjD,KAAC,CAAC,GAAG,CAAC,CAAiB;AAEzB;;;;;;;;;;;;;;;;AAgBG;AACU,IAAA,GAAA,CAAA,SAAS,GAAG,CAA6B,CAAI;;AAExD,KAAC,CAAC,GAAG,CAAC,CAAiB;AAC3B,CAAC,EA5dgB,GAAG,KAAH,GAAG,GAAA,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refined-number-utils.mjs","sources":["../../src/number/refined-number-utils.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAIA;IACiB;AAAjB,CAAA,UAAiB,oBAAoB,EAAA;AAoBnC,IAAA,CAAA,UAAiB,kBAAkB,EAAA;AACjC,QAAA,MAAM,YAAY,GAChB,CACE,EAAmC,EACnC,sBAA8B,KAEhC,CAAmB,CAAI,KAAqB;AAC1C,YAAA,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;gBACV,MAAM,IAAI,SAAS,CAAC,CAAA,SAAA,EAAY,sBAAsB,CAAA,OAAA,EAAU,CAAC,CAAA,CAAE,CAAC;;AAEtE,YAAA,OAAO,CAAC;AACV,
|
|
1
|
+
{"version":3,"file":"refined-number-utils.mjs","sources":["../../src/number/refined-number-utils.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAIA;IACiB;AAAjB,CAAA,UAAiB,oBAAoB,EAAA;AAoBnC,IAAA,CAAA,UAAiB,kBAAkB,EAAA;AACjC,QAAA,MAAM,YAAY,GAChB,CACE,EAAmC,EACnC,sBAA8B,KAEhC,CAAmB,CAAI,KAAqB;AAC1C,YAAA,IAAI,CAAC,EAAE,CAAC,CAAC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GAAA,GAAc,SAAS,EACvB,GAAA,GAAc,SAAS,KACZ,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE;AAE7D,YAAA,MAAM,MAAM,GAAG,CAAC,GAAiB,EAAE,GAAiB,KAClD,aAAa,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAErC,YAAA,MAAM,aAAa,GAAG,CACpB,GAAiB,EACjB,GAAiB,KACF;gBACf,OAAO,IAAI,EAAE;oBACX,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC;oBAC1B,IAAI,SAAS,CAAC,CAAC,CAAC;AAAE,wBAAA,OAAO,CAAC;;AAE9B,YAAA,CAAC;YAED,OAAO;gBACL,SAAS;gBACT,SAAS;gBACT,EAAE;gBACF,GAAG;AACH,gBAAA,GAAG,EAAE,IAAI;AACT,gBAAA,GAAG,EAAE,IAAI;gBACT,GAAG;gBACH,GAAG;gBACH,GAAG;gBACH,GAAG;gBACH,GAAG;gBACH,MAAM;gBACN,aAAa;gBACb,QAAQ;;AAGR,gBAAA,KAAK,EAAE,KAEuB;aACtB;AACZ,QAAA,CAAC;AACH,IAAA,CAAC,EAhiBgB,oBAAA,CAAA,kBAAkB,KAAlB,uCAAkB,GAAA,EAAA,CAAA,CAAA;AAiiBrC,CAAC,EArjBgB,oBAAoB,KAApB,oBAAoB,GAAA,EAAA,CAAA,CAAA;;;;"}
|
package/dist/object/object.d.mts
CHANGED
|
@@ -101,11 +101,8 @@ export declare namespace Obj {
|
|
|
101
101
|
* const visible = pickVisible(partialUser); // { name: "Alice" } (age omitted)
|
|
102
102
|
* ```
|
|
103
103
|
*/
|
|
104
|
-
export const
|
|
105
|
-
|
|
106
|
-
<const R extends UnknownRecord, const Keys extends readonly (keyof R)[]>(record: R, keys: Keys): Pick<R, ArrayElement<Keys>>;
|
|
107
|
-
<const Keys extends readonly PropertyKey[]>(keys: Keys): <const R extends UnknownRecord>(record: R) => RelaxedPick<R, ArrayElement<Keys>>;
|
|
108
|
-
};
|
|
104
|
+
export function pick<const R extends UnknownRecord, const Keys extends readonly (keyof R)[]>(record: R, keys: Keys): Pick<R, ArrayElement<Keys>>;
|
|
105
|
+
export function pick<const Keys extends readonly PropertyKey[]>(keys: Keys): <const R extends UnknownRecord>(record: R) => RelaxedPick<R, ArrayElement<Keys>>;
|
|
109
106
|
/**
|
|
110
107
|
* Creates a new record that excludes the specified keys from the source record.
|
|
111
108
|
* This function supports both direct usage and curried form for functional composition.
|
|
@@ -179,11 +176,8 @@ export declare namespace Obj {
|
|
|
179
176
|
* const cleaned = omitCredentials(partialUser); // { id: 1, name: "Alice" }
|
|
180
177
|
* ```
|
|
181
178
|
*/
|
|
182
|
-
export const
|
|
183
|
-
|
|
184
|
-
<const R extends UnknownRecord, const Keys extends readonly (keyof R)[]>(record: R, keys: Keys): Omit<R, ArrayElement<Keys>>;
|
|
185
|
-
<const Keys extends readonly PropertyKey[]>(keys: Keys): <const R extends UnknownRecord>(record: R) => Omit<R, ArrayElement<Keys>>;
|
|
186
|
-
};
|
|
179
|
+
export function omit<const R extends UnknownRecord, const Keys extends readonly (keyof R)[]>(record: R, keys: Keys): Omit<R, ArrayElement<Keys>>;
|
|
180
|
+
export function omit<const Keys extends readonly PropertyKey[]>(keys: Keys): <const R extends UnknownRecord>(record: R) => Omit<R, ArrayElement<Keys>>;
|
|
187
181
|
/**
|
|
188
182
|
* Creates an object from an array of key-value pairs with precise TypeScript typing.
|
|
189
183
|
* This is a type-safe wrapper around `Object.fromEntries` that provides better type inference
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.mts","sourceRoot":"","sources":["../../src/object/object.mts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,yBAAiB,GAAG,CAAC;IACnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,MAAM,CAAC,MA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