ts-data-forge 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +145 -97
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/dist/number/branded-types/finite-number.d.mts +6 -6
- package/dist/number/branded-types/finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/finite-number.mjs +4 -4
- package/dist/number/branded-types/finite-number.mjs.map +1 -1
- package/dist/number/branded-types/int.d.mts +3 -3
- package/dist/number/branded-types/int.d.mts.map +1 -1
- package/dist/number/branded-types/int.mjs +4 -4
- package/dist/number/branded-types/int.mjs.map +1 -1
- package/dist/number/branded-types/int16.d.mts +3 -3
- package/dist/number/branded-types/int16.d.mts.map +1 -1
- package/dist/number/branded-types/int16.mjs +2 -2
- package/dist/number/branded-types/int16.mjs.map +1 -1
- package/dist/number/branded-types/int32.d.mts +3 -3
- package/dist/number/branded-types/int32.d.mts.map +1 -1
- package/dist/number/branded-types/int32.mjs +2 -2
- package/dist/number/branded-types/int32.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.d.mts +5 -5
- package/dist/number/branded-types/non-negative-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-negative-finite-number.mjs +3 -3
- package/dist/number/branded-types/non-negative-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int16.d.mts +1 -1
- package/dist/number/branded-types/non-negative-int16.mjs +2 -2
- package/dist/number/branded-types/non-negative-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-negative-int32.d.mts +1 -1
- package/dist/number/branded-types/non-negative-int32.mjs +2 -2
- package/dist/number/branded-types/non-negative-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.d.mts +6 -6
- package/dist/number/branded-types/non-zero-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-finite-number.mjs +4 -4
- package/dist/number/branded-types/non-zero-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int.d.mts +3 -3
- package/dist/number/branded-types/non-zero-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int.mjs +4 -4
- package/dist/number/branded-types/non-zero-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int16.d.mts +3 -3
- package/dist/number/branded-types/non-zero-int16.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int16.mjs +2 -2
- package/dist/number/branded-types/non-zero-int16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-int32.d.mts +3 -3
- package/dist/number/branded-types/non-zero-int32.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-int32.mjs +2 -2
- package/dist/number/branded-types/non-zero-int32.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.d.mts +3 -3
- package/dist/number/branded-types/non-zero-safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/non-zero-safe-int.mjs +2 -2
- package/dist/number/branded-types/non-zero-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint16.d.mts +1 -1
- package/dist/number/branded-types/non-zero-uint16.mjs +2 -2
- package/dist/number/branded-types/non-zero-uint16.mjs.map +1 -1
- package/dist/number/branded-types/non-zero-uint32.d.mts +1 -1
- package/dist/number/branded-types/non-zero-uint32.mjs +2 -2
- package/dist/number/branded-types/non-zero-uint32.mjs.map +1 -1
- package/dist/number/branded-types/positive-finite-number.d.mts +5 -5
- package/dist/number/branded-types/positive-finite-number.d.mts.map +1 -1
- package/dist/number/branded-types/positive-finite-number.mjs +3 -3
- package/dist/number/branded-types/positive-finite-number.mjs.map +1 -1
- package/dist/number/branded-types/positive-int.d.mts +1 -1
- package/dist/number/branded-types/positive-int.mjs +3 -3
- package/dist/number/branded-types/positive-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-int16.d.mts +1 -1
- package/dist/number/branded-types/positive-int16.mjs +2 -2
- package/dist/number/branded-types/positive-int16.mjs.map +1 -1
- package/dist/number/branded-types/positive-int32.d.mts +1 -1
- package/dist/number/branded-types/positive-int32.mjs +2 -2
- package/dist/number/branded-types/positive-int32.mjs.map +1 -1
- package/dist/number/branded-types/positive-safe-int.d.mts +1 -1
- package/dist/number/branded-types/positive-safe-int.mjs +2 -2
- package/dist/number/branded-types/positive-safe-int.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint16.d.mts +1 -1
- package/dist/number/branded-types/positive-uint16.mjs +2 -2
- package/dist/number/branded-types/positive-uint16.mjs.map +1 -1
- package/dist/number/branded-types/positive-uint32.d.mts +1 -1
- package/dist/number/branded-types/positive-uint32.mjs +2 -2
- package/dist/number/branded-types/positive-uint32.mjs.map +1 -1
- package/dist/number/branded-types/safe-int.d.mts +3 -3
- package/dist/number/branded-types/safe-int.d.mts.map +1 -1
- package/dist/number/branded-types/safe-int.mjs +2 -2
- package/dist/number/branded-types/safe-int.mjs.map +1 -1
- package/dist/number/branded-types/safe-uint.d.mts +1 -1
- package/dist/number/branded-types/safe-uint.mjs +2 -2
- package/dist/number/branded-types/safe-uint.mjs.map +1 -1
- package/dist/number/branded-types/uint.d.mts +1 -1
- package/dist/number/branded-types/uint.mjs +3 -3
- package/dist/number/branded-types/uint.mjs.map +1 -1
- package/dist/number/branded-types/uint16.d.mts +1 -1
- package/dist/number/branded-types/uint16.mjs +2 -2
- package/dist/number/branded-types/uint16.mjs.map +1 -1
- package/dist/number/branded-types/uint32.d.mts +1 -1
- package/dist/number/branded-types/uint32.mjs +2 -2
- package/dist/number/branded-types/uint32.mjs.map +1 -1
- package/dist/number/enum/int8.mjs +2 -2
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/enum/uint8.d.mts.map +1 -1
- package/dist/number/enum/uint8.mjs +2 -2
- package/dist/number/enum/uint8.mjs.map +1 -1
- package/dist/number/index.mjs +1 -1
- package/dist/number/refined-number-utils.d.mts +8 -8
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +8 -7
- package/dist/number/refined-number-utils.mjs.map +1 -1
- package/dist/object/object.d.mts +2 -2
- package/dist/object/object.d.mts.map +1 -1
- package/dist/promise/index.d.mts +2 -0
- package/dist/promise/index.d.mts.map +1 -0
- package/dist/promise/index.mjs +2 -0
- package/dist/promise/index.mjs.map +1 -0
- package/dist/promise/promise.d.mts +32 -0
- package/dist/promise/promise.d.mts.map +1 -0
- package/dist/promise/promise.mjs +38 -0
- package/dist/promise/promise.mjs.map +1 -0
- package/package.json +18 -9
- package/src/index.mts +1 -0
- package/src/number/branded-types/finite-number.mts +18 -16
- package/src/number/branded-types/int.mts +8 -8
- package/src/number/branded-types/int16.mts +4 -4
- package/src/number/branded-types/int32.mts +4 -4
- package/src/number/branded-types/non-negative-finite-number.mts +13 -13
- package/src/number/branded-types/non-negative-int16.mts +4 -4
- package/src/number/branded-types/non-negative-int32.mts +4 -4
- package/src/number/branded-types/non-zero-finite-number.mts +18 -18
- package/src/number/branded-types/non-zero-int.mts +8 -8
- package/src/number/branded-types/non-zero-int16.mts +4 -4
- package/src/number/branded-types/non-zero-int32.mts +4 -4
- package/src/number/branded-types/non-zero-safe-int.mts +4 -4
- package/src/number/branded-types/non-zero-uint16.mts +4 -4
- package/src/number/branded-types/non-zero-uint32.mts +4 -4
- package/src/number/branded-types/positive-finite-number.mts +23 -19
- package/src/number/branded-types/positive-int.mts +6 -6
- package/src/number/branded-types/positive-int16.mts +4 -4
- package/src/number/branded-types/positive-int32.mts +4 -4
- package/src/number/branded-types/positive-safe-int.mts +4 -4
- package/src/number/branded-types/positive-uint16.mts +4 -4
- package/src/number/branded-types/positive-uint32.mts +4 -4
- package/src/number/branded-types/safe-int.mts +4 -4
- package/src/number/branded-types/safe-uint.mts +4 -4
- package/src/number/branded-types/uint.mts +6 -6
- package/src/number/branded-types/uint16.mts +4 -4
- package/src/number/branded-types/uint32.mts +4 -4
- package/src/number/enum/int8.mts +3 -3
- package/src/number/enum/uint8.mts +10 -8
- package/src/number/refined-number-utils.mts +28 -23
- package/src/object/object.mts +6 -6
- package/src/promise/index.mts +1 -0
- package/src/promise/promise.mts +38 -0
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ expectType<{ x: number }, { x: number }>('=');
|
|
|
139
139
|
// The following would cause a compile-time error:
|
|
140
140
|
// expectType<User, Admin>("="); // Error: Type 'User' is not strictly equal to type 'Admin'.
|
|
141
141
|
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
142
143
|
expectType<User, any>('!='); // Error: Comparisons with `any` are also strictly checked.
|
|
143
144
|
```
|
|
144
145
|
|
|
@@ -147,55 +148,53 @@ expectType<User, any>('!='); // Error: Comparisons with `any` are also strictly
|
|
|
147
148
|
Handle nullable values and error-prone operations safely.
|
|
148
149
|
|
|
149
150
|
```typescript
|
|
150
|
-
import {
|
|
151
|
+
import { match, Optional, pipe, Result } from 'ts-data-forge';
|
|
151
152
|
|
|
152
153
|
// Optional for nullable values
|
|
153
154
|
const maybeValue = Optional.some(42);
|
|
154
|
-
const nothing = Optional.none;
|
|
155
155
|
|
|
156
156
|
const doubled = Optional.map(maybeValue, (x) => x * 2);
|
|
157
|
-
|
|
157
|
+
|
|
158
|
+
assert.strictEqual(Optional.unwrapOr(doubled, 0), 84);
|
|
158
159
|
|
|
159
160
|
// Result for error handling
|
|
160
161
|
const success = Result.ok(42);
|
|
161
|
-
const failure = Result.err('Something went wrong');
|
|
162
162
|
|
|
163
163
|
const mapped = Result.map(success, (x) => x * 2);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
164
|
+
|
|
165
|
+
assert.deepStrictEqual(mapped, Result.ok(84));
|
|
167
166
|
|
|
168
167
|
// Advanced pipe usage
|
|
169
|
-
const processNumber = (input: number) =>
|
|
168
|
+
const processNumber = (input: number): Optional<number> =>
|
|
170
169
|
pipe(input)
|
|
171
170
|
.map((x) => x * 2) // Regular transformation
|
|
172
171
|
.map((x) => x + 10) // Chain transformations
|
|
173
|
-
.map((x) => (x > 50 ? Optional.some(x) : Optional.none)) //
|
|
174
|
-
|
|
172
|
+
.map((x) => (x > 50 ? Optional.some(x / 2) : Optional.none)).value; // Get the result
|
|
173
|
+
|
|
174
|
+
assert.deepStrictEqual(processNumber(30), Optional.some(35));
|
|
175
175
|
|
|
176
|
-
|
|
177
|
-
console.log(processNumber(10)); // Optional.none
|
|
176
|
+
assert.deepStrictEqual(processNumber(10), Optional.none);
|
|
178
177
|
|
|
179
178
|
// Pattern matching with match
|
|
180
179
|
type Status = 'loading' | 'success' | 'error';
|
|
181
180
|
|
|
182
|
-
const handleStatus = (status: Status, data?: string) =>
|
|
181
|
+
const handleStatus = (status: Status, data?: string): string =>
|
|
183
182
|
match(status, {
|
|
184
183
|
loading: 'Please wait...',
|
|
185
184
|
success: `Data: ${data ?? 'No data'}`,
|
|
186
185
|
error: 'An error occurred',
|
|
187
186
|
});
|
|
188
187
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
assert.strictEqual(handleStatus('loading'), 'Please wait...');
|
|
189
|
+
assert.strictEqual(handleStatus('success', 'Hello'), 'Data: Hello');
|
|
190
|
+
assert.strictEqual(handleStatus('error'), 'An error occurred');
|
|
192
191
|
|
|
193
192
|
// Pattern matching with Result
|
|
194
|
-
const processResult = (result: Result<number, string>) =>
|
|
193
|
+
const processResult = (result: Result<number, string>): string =>
|
|
195
194
|
Result.isOk(result) ? `Success: ${result.value}` : `Error: ${result.value}`;
|
|
196
195
|
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
assert.strictEqual(processResult(Result.ok(42)), 'Success: 42');
|
|
197
|
+
assert.strictEqual(processResult(Result.err('Failed')), 'Error: Failed');
|
|
199
198
|
```
|
|
200
199
|
|
|
201
200
|
### 3. Number Utilities with `Num` and Branded Number Types
|
|
@@ -206,32 +205,35 @@ The `Num` object provides safe and convenient functions for numerical operations
|
|
|
206
205
|
import { Num } from 'ts-data-forge';
|
|
207
206
|
|
|
208
207
|
// Basic conversions
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
assert.strictEqual(Num.from('123'), 123);
|
|
209
|
+
assert.strictEqual(Number.isNaN(Num.from('abc')), true);
|
|
211
210
|
|
|
212
211
|
// Range checking
|
|
213
212
|
const inRange = Num.isInRange(0, 10);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
213
|
+
|
|
214
|
+
assert.strictEqual(inRange(5), true);
|
|
215
|
+
assert.strictEqual(inRange(0), true); // (inclusive lower bound)
|
|
216
|
+
assert.strictEqual(inRange(10), false); // (exclusive upper bound)
|
|
217
217
|
|
|
218
218
|
// Clamping values
|
|
219
219
|
const clamp = Num.clamp(0, 100);
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
|
|
221
|
+
assert.strictEqual(clamp(150), 100);
|
|
222
|
+
assert.strictEqual(clamp(-10), 0);
|
|
222
223
|
|
|
223
224
|
// Rounding utilities
|
|
224
225
|
const round2 = Num.round(2);
|
|
225
|
-
console.log(round2(3.14159)); // 3.14
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
assert.strictEqual(round2(3.14159), 3.14);
|
|
228
|
+
assert.strictEqual(Num.roundAt(3.14159, 3), 3.142);
|
|
229
|
+
assert.strictEqual(Num.roundToInt(3.7), 4);
|
|
229
230
|
|
|
230
231
|
// Type guards
|
|
231
|
-
|
|
232
|
+
const value = 5; // example value
|
|
232
233
|
if (Num.isNonZero(value)) {
|
|
233
234
|
// value is guaranteed to be non-zero
|
|
234
235
|
const result = Num.div(10, value); // Safe division
|
|
236
|
+
assert.strictEqual(result, 2);
|
|
235
237
|
}
|
|
236
238
|
```
|
|
237
239
|
|
|
@@ -241,22 +243,16 @@ if (Num.isNonZero(value)) {
|
|
|
241
243
|
|
|
242
244
|
```typescript
|
|
243
245
|
import {
|
|
244
|
-
asInt,
|
|
245
|
-
asUint,
|
|
246
246
|
asFiniteNumber,
|
|
247
|
-
|
|
247
|
+
asInt,
|
|
248
248
|
asInt16,
|
|
249
|
-
asUint32,
|
|
250
249
|
asNonZeroInt,
|
|
251
250
|
asPositiveInt,
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
SafeInt,
|
|
251
|
+
asSafeInt,
|
|
252
|
+
asUint,
|
|
253
|
+
asUint32,
|
|
256
254
|
Int16,
|
|
257
|
-
Uint32,
|
|
258
255
|
NonZeroInt,
|
|
259
|
-
PositiveInt,
|
|
260
256
|
} from 'ts-data-forge';
|
|
261
257
|
|
|
262
258
|
// Basic branded types
|
|
@@ -265,25 +261,42 @@ const unsigned = asUint(42); // Uint - non-negative integer
|
|
|
265
261
|
const finite = asFiniteNumber(3.14); // FiniteNumber - finite floating-point
|
|
266
262
|
const safeInt = asSafeInt(42); // SafeInt - integer in safe range
|
|
267
263
|
|
|
268
|
-
|
|
264
|
+
assert.strictEqual(integer, 42);
|
|
265
|
+
assert.strictEqual(unsigned, 42);
|
|
266
|
+
assert.strictEqual(finite, 3.14);
|
|
267
|
+
assert.strictEqual(safeInt, 42);
|
|
268
|
+
|
|
269
|
+
// This line would cause a runtime error:
|
|
270
|
+
assert.throw(() => {
|
|
271
|
+
asInt(3.14);
|
|
272
|
+
});
|
|
269
273
|
|
|
270
274
|
// Range-constrained types (16-bit, 32-bit)
|
|
271
275
|
const int16 = asInt16(1000); // Int16: [-32768, 32767]
|
|
272
276
|
const uint32 = asUint32(3000000000); // Uint32: [0, 4294967295]
|
|
277
|
+
assert.strictEqual(int16, 1000);
|
|
278
|
+
assert.strictEqual(uint32, 3000000000);
|
|
273
279
|
|
|
274
280
|
// Non-zero and positive variants
|
|
275
281
|
const nonZeroInt = asNonZeroInt(5); // NonZeroInt - excludes zero
|
|
276
282
|
const positiveInt = asPositiveInt(10); // PositiveInt - excludes zero and negatives
|
|
283
|
+
assert.strictEqual(nonZeroInt, 5);
|
|
284
|
+
assert.strictEqual(positiveInt, 10);
|
|
277
285
|
|
|
278
286
|
// Type-safe arithmetic with automatic clamping
|
|
279
287
|
const sum = Int16.add(int16, asInt16(2000)); // Int16 (3000)
|
|
280
288
|
const clamped = Int16.clamp(100000); // Int16 (32767 - clamped to MAX_VALUE)
|
|
289
|
+
assert.strictEqual(sum, 3000);
|
|
290
|
+
assert.strictEqual(clamped, 32767);
|
|
281
291
|
|
|
282
292
|
// Safe division with non-zero types
|
|
283
293
|
const ratio = NonZeroInt.div(asNonZeroInt(10), nonZeroInt); // No division by zero risk
|
|
294
|
+
assert.strictEqual(ratio, 2);
|
|
284
295
|
|
|
285
296
|
// Random generation within type constraints
|
|
286
297
|
const randomInt16 = Int16.random(); // Int16 (random value in valid range)
|
|
298
|
+
assert.strictEqual(-32768 <= randomInt16, true);
|
|
299
|
+
assert.strictEqual(randomInt16 <= 32767, true);
|
|
287
300
|
```
|
|
288
301
|
|
|
289
302
|
### 4. Array Utilities with `Arr`
|
|
@@ -291,39 +304,54 @@ const randomInt16 = Int16.random(); // Int16 (random value in valid range)
|
|
|
291
304
|
The `Arr` object provides a rich set of functions for array manipulation.
|
|
292
305
|
|
|
293
306
|
```typescript
|
|
294
|
-
import { Arr } from 'ts-data-forge';
|
|
307
|
+
import { Arr, expectType, Optional } from 'ts-data-forge';
|
|
295
308
|
|
|
296
309
|
const numbers: readonly number[] = [1, 2, 3, 4, 5, 2, 3];
|
|
297
|
-
const people = [
|
|
298
|
-
{ name: 'Alice', age: 30 },
|
|
299
|
-
{ name: 'Bob', age: 25 },
|
|
300
|
-
{ name: 'Charlie', age: 35 },
|
|
301
|
-
] as const;
|
|
302
310
|
|
|
303
311
|
// Reduction
|
|
304
312
|
const sum = Arr.sum(numbers);
|
|
305
|
-
console.log(sum); // 20
|
|
306
313
|
|
|
307
|
-
|
|
308
|
-
const zeros: readonly [0, 0, 0, 0, 0] = Arr.zeros(5); // [0, 0, 0, 0, 0]
|
|
309
|
-
const range: readonly [1, 2, 3] = Arr.range(1, 4); // [1, 2, 3]
|
|
314
|
+
assert.strictEqual(sum, 20);
|
|
310
315
|
|
|
311
316
|
// Type-safe length checking
|
|
312
317
|
if (Arr.isArrayAtLeastLength(numbers, 2)) {
|
|
313
|
-
// numbers is now guaranteed to have at least
|
|
318
|
+
// numbers is now guaranteed to have at least 2 elements
|
|
314
319
|
expectType<typeof numbers, readonly [number, number, ...number[]]>('=');
|
|
315
|
-
|
|
320
|
+
assert.strictEqual(numbers[1], 2); // Safe access to index 1
|
|
316
321
|
}
|
|
317
322
|
|
|
318
323
|
// Take first n elements
|
|
319
|
-
const firstThree = Arr.take(numbers, 3);
|
|
324
|
+
const firstThree = Arr.take(numbers, 3);
|
|
320
325
|
|
|
321
|
-
|
|
322
|
-
const oldestPerson = Arr.maxBy(people, (person) => person.age);
|
|
323
|
-
console.log(oldestPerson?.name); // 'Charlie'
|
|
326
|
+
assert.deepStrictEqual(firstThree, [1, 2, 3]);
|
|
324
327
|
|
|
325
328
|
// Remove duplicates
|
|
326
|
-
const unique = Arr.uniq(numbers);
|
|
329
|
+
const unique = Arr.uniq(numbers);
|
|
330
|
+
|
|
331
|
+
assert.deepStrictEqual(unique, [1, 2, 3, 4, 5]);
|
|
332
|
+
|
|
333
|
+
// Array creation
|
|
334
|
+
const zeros: readonly [0, 0, 0, 0, 0] = Arr.zeros(5);
|
|
335
|
+
assert.deepStrictEqual(zeros, [0, 0, 0, 0, 0]);
|
|
336
|
+
|
|
337
|
+
const range: readonly [1, 2, 3] = Arr.range(1, 4);
|
|
338
|
+
assert.deepStrictEqual(range, [1, 2, 3]);
|
|
339
|
+
|
|
340
|
+
const people = [
|
|
341
|
+
{ name: 'Alice', age: 30 },
|
|
342
|
+
{ name: 'Bob', age: 25 },
|
|
343
|
+
{ name: 'Charlie', age: 35 },
|
|
344
|
+
] as const;
|
|
345
|
+
|
|
346
|
+
// Find maximum by property
|
|
347
|
+
const oldestPerson = Arr.maxBy(people, (person) => person.age);
|
|
348
|
+
assert.deepStrictEqual(
|
|
349
|
+
oldestPerson,
|
|
350
|
+
Optional.some({ name: 'Charlie', age: 35 } as const),
|
|
351
|
+
);
|
|
352
|
+
if (Optional.isSome(oldestPerson)) {
|
|
353
|
+
assert.strictEqual(oldestPerson.value.name, 'Charlie');
|
|
354
|
+
}
|
|
327
355
|
```
|
|
328
356
|
|
|
329
357
|
### 5. Immutable Collections: `IMap` and `ISet`
|
|
@@ -331,7 +359,7 @@ const unique = Arr.uniq(numbers); // [1, 2, 3, 4, 5]
|
|
|
331
359
|
Type-safe, immutable data structures.
|
|
332
360
|
|
|
333
361
|
```typescript
|
|
334
|
-
import { IMap, ISet,
|
|
362
|
+
import { Arr, IMap, ISet, Optional } from 'ts-data-forge';
|
|
335
363
|
|
|
336
364
|
// IMap usage - immutable operations
|
|
337
365
|
const originalMap = IMap.create<string, number>([]);
|
|
@@ -339,34 +367,37 @@ const mapWithOne = originalMap.set('one', 1);
|
|
|
339
367
|
const mapWithTwo = mapWithOne.set('two', 2);
|
|
340
368
|
|
|
341
369
|
// Original map is unchanged
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
370
|
+
assert.strictEqual(originalMap.size, 0);
|
|
371
|
+
assert.deepStrictEqual(mapWithTwo.get('one'), Optional.some(1));
|
|
372
|
+
|
|
373
|
+
assert.strictEqual(mapWithTwo.has('three'), false);
|
|
345
374
|
|
|
346
375
|
// Using pipe for fluent updates
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
376
|
+
const sequence = Arr.seq(10); // [0, 1, 2, ..., 9]
|
|
377
|
+
const pairs = sequence.map(
|
|
378
|
+
(i) => [i, i.toString()] as readonly [number, string],
|
|
379
|
+
);
|
|
380
|
+
const skipped = Arr.skip(pairs, 1); // [[1, "1"], ..., [9, "9"]]
|
|
381
|
+
const idMap = IMap.create<number, string>(skipped);
|
|
351
382
|
|
|
352
|
-
|
|
383
|
+
assert.strictEqual(idMap.size, 9);
|
|
353
384
|
|
|
354
385
|
// Efficient batch updates with withMutations
|
|
355
386
|
const idMapUpdated = idMap.withMutations([
|
|
356
|
-
{ type: 'set', key: 99, value:
|
|
357
|
-
{ type: 'update', key: 5,
|
|
387
|
+
{ type: 'set', key: 99, value: '99' },
|
|
388
|
+
{ type: 'update', key: 5, updater: () => 'five' },
|
|
358
389
|
{ type: 'delete', key: 4 },
|
|
359
390
|
]);
|
|
360
391
|
|
|
361
|
-
|
|
392
|
+
assert.strictEqual(idMapUpdated.size, 9);
|
|
362
393
|
|
|
363
394
|
// ISet usage
|
|
364
395
|
const originalSet = ISet.create<number>([]);
|
|
365
396
|
const setWithItems = originalSet.add(1).add(2).add(1); // Duplicate ignored
|
|
366
397
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
398
|
+
assert.strictEqual(originalSet.size, 0); // (unchanged)
|
|
399
|
+
assert.strictEqual(setWithItems.has(1), true);
|
|
400
|
+
assert.strictEqual(setWithItems.size, 2);
|
|
370
401
|
```
|
|
371
402
|
|
|
372
403
|
### 6. Type Guards
|
|
@@ -374,9 +405,9 @@ console.log(setWithItems.size); // 2
|
|
|
374
405
|
Safe type narrowing with comprehensive type guards.
|
|
375
406
|
|
|
376
407
|
```typescript
|
|
377
|
-
import { isNonNullObject, isRecord
|
|
408
|
+
import { hasKey, isNonNullObject, isRecord } from 'ts-data-forge';
|
|
378
409
|
|
|
379
|
-
|
|
410
|
+
const processData = (data: unknown): string | undefined => {
|
|
380
411
|
if (isRecord(data)) {
|
|
381
412
|
// data is now UnknownRecord (= Readonly<Record<string, unknown>>)
|
|
382
413
|
if (
|
|
@@ -384,17 +415,24 @@ function processData(data: unknown) {
|
|
|
384
415
|
// data is now ReadonlyRecord<"name", unknown> & UnknownRecord
|
|
385
416
|
typeof data.name === 'string'
|
|
386
417
|
) {
|
|
387
|
-
|
|
418
|
+
return `Hello, ${data.name}!`;
|
|
388
419
|
}
|
|
389
420
|
}
|
|
390
|
-
|
|
421
|
+
return undefined;
|
|
422
|
+
};
|
|
391
423
|
|
|
392
424
|
// Non-null object checking
|
|
393
|
-
|
|
425
|
+
const value: unknown = { key: 'value' };
|
|
426
|
+
|
|
394
427
|
if (isNonNullObject(value)) {
|
|
395
428
|
// value is guaranteed to be a non-null object
|
|
396
|
-
|
|
429
|
+
assert.deepStrictEqual(Object.keys(value), ['key']);
|
|
397
430
|
}
|
|
431
|
+
|
|
432
|
+
// Example usage
|
|
433
|
+
assert.strictEqual(processData({ name: 'Alice' }), 'Hello, Alice!');
|
|
434
|
+
assert.strictEqual(processData({ age: 30 }), undefined);
|
|
435
|
+
assert.strictEqual(processData('not an object'), undefined);
|
|
398
436
|
```
|
|
399
437
|
|
|
400
438
|
### 7. Iteration with `range`
|
|
@@ -405,18 +443,27 @@ Generate ranges for iteration and array creation.
|
|
|
405
443
|
import { range } from 'ts-data-forge';
|
|
406
444
|
|
|
407
445
|
// Traditional for loop using range
|
|
446
|
+
const values: number[] = [];
|
|
408
447
|
for (const i of range(0, 5)) {
|
|
409
|
-
|
|
448
|
+
values.push(i);
|
|
410
449
|
}
|
|
411
450
|
|
|
451
|
+
assert.deepStrictEqual(values, [0, 1, 2, 3, 4]);
|
|
452
|
+
|
|
412
453
|
// Create arrays from ranges
|
|
413
|
-
const numbers = Array.from(range(1, 4));
|
|
414
|
-
const squares = Array.from(range(1, 6), (x) => x * x);
|
|
454
|
+
const numbers = Array.from(range(1, 4));
|
|
455
|
+
const squares = Array.from(range(1, 6), (x) => x * x);
|
|
456
|
+
|
|
457
|
+
assert.deepStrictEqual(numbers, [1, 2, 3]);
|
|
458
|
+
assert.deepStrictEqual(squares, [1, 4, 9, 16, 25]);
|
|
415
459
|
|
|
416
460
|
// Step ranges
|
|
461
|
+
const stepValues: number[] = [];
|
|
417
462
|
for (const i of range(0, 10, 2)) {
|
|
418
|
-
|
|
463
|
+
stepValues.push(i);
|
|
419
464
|
}
|
|
465
|
+
|
|
466
|
+
assert.deepStrictEqual(stepValues, [0, 2, 4, 6, 8]);
|
|
420
467
|
```
|
|
421
468
|
|
|
422
469
|
### 8. Mutability Utilities with `castMutable`
|
|
@@ -424,23 +471,23 @@ for (const i of range(0, 10, 2)) {
|
|
|
424
471
|
Safely work with readonly types when interfacing with mutable APIs.
|
|
425
472
|
|
|
426
473
|
```tsx
|
|
427
|
-
import { Autocomplete } from '@mui/material';
|
|
428
474
|
import { castMutable } from 'ts-data-forge';
|
|
429
475
|
|
|
430
|
-
|
|
476
|
+
// Example: Material-UI Autocomplete
|
|
477
|
+
import { Autocomplete, TextField } from '@mui/material';
|
|
431
478
|
|
|
432
|
-
const SomeComponent: React.FC = () =>
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
479
|
+
export const SomeComponent: React.FC = () => (
|
|
480
|
+
<Autocomplete
|
|
481
|
+
options={castMutable(readonlyOptions)}
|
|
482
|
+
renderInput={(params) => (
|
|
483
|
+
<TextField {...params} placeholder="Select an option" />
|
|
484
|
+
)}
|
|
485
|
+
/>
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
const readonlyOptions: readonly string[] = ['Option 1', 'Option 2', 'Option 3'];
|
|
442
489
|
|
|
443
|
-
// Immer.js example
|
|
490
|
+
// Immer.js example
|
|
444
491
|
import { produce } from 'immer';
|
|
445
492
|
|
|
446
493
|
type State = Readonly<{
|
|
@@ -458,7 +505,8 @@ const updatedState = produce(initialState, (draft) => {
|
|
|
458
505
|
draft.items = castMutable(newItems); // Safe cast for assignment
|
|
459
506
|
});
|
|
460
507
|
|
|
461
|
-
|
|
508
|
+
assert.deepStrictEqual(initialState.items, ['item1', 'item2']);
|
|
509
|
+
assert.deepStrictEqual(updatedState.items, ['newItem1', 'newItem2']);
|
|
462
510
|
```
|
|
463
511
|
|
|
464
512
|
## Modules Overview
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.mts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -49,7 +49,7 @@ export { Uint32, asUint32, isUint32 } from './number/branded-types/uint32.mjs';
|
|
|
49
49
|
export { Int8, asInt8, isInt8 } from './number/enum/int8.mjs';
|
|
50
50
|
export { Uint8, asUint8, isUint8 } from './number/enum/uint8.mjs';
|
|
51
51
|
export { Num } from './number/num.mjs';
|
|
52
|
-
export {
|
|
52
|
+
export { TsDataForgeInternals } from './number/refined-number-utils.mjs';
|
|
53
53
|
export { Obj } from './object/object.mjs';
|
|
54
54
|
export { castDeepMutable, castMutable } from './others/cast-mutable.mjs';
|
|
55
55
|
export { castDeepReadonly, castReadonly } from './others/cast-readonly.mjs';
|
|
@@ -58,4 +58,5 @@ export { mapNullable } from './others/map-nullable.mjs';
|
|
|
58
58
|
export { memoizeFunction } from './others/memoize-function.mjs';
|
|
59
59
|
export { tp } from './others/tuple.mjs';
|
|
60
60
|
export { unknownToString } from './others/unknown-to-string.mjs';
|
|
61
|
+
export { createPromise } from './promise/promise.mjs';
|
|
61
62
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
2
2
|
type ElementType = FiniteNumber;
|
|
3
3
|
/**
|
|
4
4
|
* Type guard that checks if a value is a finite number.
|
|
@@ -115,7 +115,7 @@ export declare const FiniteNumber: {
|
|
|
115
115
|
* FiniteNumber.abs(asFiniteNumber(3.2)); // FiniteNumber (3.2)
|
|
116
116
|
* ```
|
|
117
117
|
*/
|
|
118
|
-
readonly abs: (x: FiniteNumber) =>
|
|
118
|
+
readonly abs: (x: FiniteNumber) => TsDataForgeInternals.RefinedNumberUtils.ToNonNegative<FiniteNumber>;
|
|
119
119
|
/**
|
|
120
120
|
* Returns the minimum value from a list of finite numbers.
|
|
121
121
|
*
|
|
@@ -160,7 +160,7 @@ export declare const FiniteNumber: {
|
|
|
160
160
|
* FiniteNumber.floor(asFiniteNumber(-5.2)); // Int (-6)
|
|
161
161
|
* ```
|
|
162
162
|
*/
|
|
163
|
-
readonly floor: (x: ElementType) =>
|
|
163
|
+
readonly floor: (x: ElementType) => TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;
|
|
164
164
|
/**
|
|
165
165
|
* Returns the smallest integer greater than or equal to the given finite number.
|
|
166
166
|
* @param x - The finite number to ceil
|
|
@@ -171,7 +171,7 @@ export declare const FiniteNumber: {
|
|
|
171
171
|
* FiniteNumber.ceil(asFiniteNumber(-5.8)); // Int (-5)
|
|
172
172
|
* ```
|
|
173
173
|
*/
|
|
174
|
-
readonly ceil: (x: ElementType) =>
|
|
174
|
+
readonly ceil: (x: ElementType) => TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;
|
|
175
175
|
/**
|
|
176
176
|
* Rounds a finite number to the nearest integer.
|
|
177
177
|
* @param x - The finite number to round
|
|
@@ -183,7 +183,7 @@ export declare const FiniteNumber: {
|
|
|
183
183
|
* FiniteNumber.round(asFiniteNumber(5.5)); // Int (6)
|
|
184
184
|
* ```
|
|
185
185
|
*/
|
|
186
|
-
readonly round: (x: ElementType) =>
|
|
186
|
+
readonly round: (x: ElementType) => TsDataForgeInternals.RefinedNumberUtils.ToInt<ElementType>;
|
|
187
187
|
/**
|
|
188
188
|
* Generates a random finite number within the specified range.
|
|
189
189
|
*
|
|
@@ -209,7 +209,7 @@ export declare const FiniteNumber: {
|
|
|
209
209
|
* );
|
|
210
210
|
* ```
|
|
211
211
|
*/
|
|
212
|
-
readonly random: (min
|
|
212
|
+
readonly random: (min?: FiniteNumber | undefined, max?: FiniteNumber | undefined) => FiniteNumber;
|
|
213
213
|
/**
|
|
214
214
|
* Raises a finite number to a power.
|
|
215
215
|
* @param a - The base finite number
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finite-number.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/finite-number.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"finite-number.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/finite-number.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,KAAK,WAAW,GAAG,YAAY,CAAC;AAgDhC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc,kCAAK,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,cAAc;;;;;MAAW,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,eAAO,MAAM,YAAY;IACvB;;;;;;;OAOG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;;;;;;;OAeG;;IAGH;;;;;;;;;;;;;;;OAeG;;IAGH;;;;;;;;;OASG;wBArLA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAuL3D;;;;;;;;;OASG;uBA3LA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IA6L3D;;;;;;;;;;OAUG;wBAlMA,WAAW,KACb,oBAAoB,CAAC,kBAAkB,CAAC,KAAK,CAAC,WAAW,CAAC;IAoM3D;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;;;;;;;;CAEK,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
2
2
|
|
|
3
3
|
const typeNameInMessage = 'a finite number';
|
|
4
|
-
const { abs, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, } =
|
|
5
|
-
MIN_VALUE:
|
|
6
|
-
MAX_VALUE:
|
|
4
|
+
const { abs, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, } = TsDataForgeInternals.RefinedNumberUtils.operatorsForFloat({
|
|
5
|
+
MIN_VALUE: -Number.MAX_VALUE,
|
|
6
|
+
MAX_VALUE: Number.MAX_VALUE,
|
|
7
7
|
typeNameInMessage,
|
|
8
8
|
});
|
|
9
9
|
const floor = (x) =>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"finite-number.mjs","sources":["../../../src/number/branded-types/finite-number.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,iBAAiB;AAE3C,MAAM,EACJ,GAAG,EACH,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,GACT,GAAG,
|
|
1
|
+
{"version":3,"file":"finite-number.mjs","sources":["../../../src/number/branded-types/finite-number.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,iBAAiB;AAE3C,MAAM,EACJ,GAAG,EACH,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,GACT,GAAG,oBAAoB,CAAC,kBAAkB,CAAC,iBAAiB,CAI3D;AACA,IAAA,SAAS,EAAE,CAAC,MAAM,CAAC,SAAS;IAC5B,SAAS,EAAE,MAAM,CAAC,SAAS;IAC3B,iBAAiB;AACT,CAAA,CAAC;AAEX,MAAM,KAAK,GAAG,CACZ,CAAc;AAEd;AACA,IAAI,CAAC,KAAK,CAAC,CAAC,CAA+D;AAE7E,MAAM,IAAI,GAAG,CACX,CAAc;AAEd;AACA,IAAI,CAAC,IAAI,CAAC,CAAC,CAA+D;AAE5E,MAAM,KAAK,GAAG,CACZ,CAAc;AAEd;AACA,IAAI,CAAC,KAAK,CAAC,CAAC,CAA+D;AAM7E;;;;;;;;;;;;;;;;;;;AAmBG;AACI,MAAM,cAAc,GAAG;AAE9B;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACI,MAAM,cAAc,GAAG;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CG;AACI,MAAM,YAAY,GAAG;AAC1B;;;;;;;AAOG;IACH,EAAE;AAEF;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;;;;;;;AAeG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;;;;;;;;;;;AAeG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;;;;;AASG;IACH,KAAK;AAEL;;;;;;;;;AASG;IACH,IAAI;AAEJ;;;;;;;;;;AAUG;IACH,KAAK;AAEL;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;IACH,MAAM;AAEN;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;IACH,GAAG;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
2
2
|
/**
|
|
3
3
|
* Type guard that checks if a value is an integer.
|
|
4
4
|
*
|
|
@@ -114,7 +114,7 @@ export declare const Int: {
|
|
|
114
114
|
* Int.abs(asInt(-0)); // Int (0)
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
|
-
readonly abs: (x: WithSmallInt<Int, 40>) =>
|
|
117
|
+
readonly abs: (x: WithSmallInt<Int, 40>) => TsDataForgeInternals.RefinedNumberUtils.ToNonNegative<Int>;
|
|
118
118
|
/**
|
|
119
119
|
* Returns the minimum value from a list of integers.
|
|
120
120
|
*
|
|
@@ -163,7 +163,7 @@ export declare const Int: {
|
|
|
163
163
|
* const temp = Int.random(asInt(-10), asInt(10));
|
|
164
164
|
* ```
|
|
165
165
|
*/
|
|
166
|
-
readonly random: (min
|
|
166
|
+
readonly random: (min?: WithSmallInt<Int, 40> | undefined, max?: WithSmallInt<Int, 40> | undefined) => Int;
|
|
167
167
|
/**
|
|
168
168
|
* Raises an integer to a power.
|
|
169
169
|
* @param a - The base integer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"int.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AA6BnE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,KAAK,yBAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,KAAK;;;;;;MAAW,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,GAAG;IACd;;;;;;;OAOG;;IAGH;;;;;;;;;;;;;;;;OAgBG;;IAGH;;;;;;;;;;;OAWG;;IAGH;;;;;;;;;;;OAWG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;;;;;;;;;;;;;OAqBG;;;;;;;;;CAEK,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
2
2
|
|
|
3
3
|
const typeNameInMessage = 'an integer';
|
|
4
|
-
const { abs, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, } =
|
|
4
|
+
const { abs, min: min_, max: max_, pow, add, sub, mul, div, random, is, castType, } = TsDataForgeInternals.RefinedNumberUtils.operatorsForInteger({
|
|
5
5
|
integerOrSafeInteger: 'Integer',
|
|
6
|
-
MIN_VALUE:
|
|
7
|
-
MAX_VALUE:
|
|
6
|
+
MIN_VALUE: -Number.MAX_VALUE,
|
|
7
|
+
MAX_VALUE: Number.MAX_VALUE,
|
|
8
8
|
typeNameInMessage,
|
|
9
9
|
});
|
|
10
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int.mjs","sources":["../../../src/number/branded-types/int.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,YAAY;AAEtC,MAAM,EACJ,GAAG,EACH,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,GACT,GAAG,
|
|
1
|
+
{"version":3,"file":"int.mjs","sources":["../../../src/number/branded-types/int.mts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA,MAAM,iBAAiB,GAAG,YAAY;AAEtC,MAAM,EACJ,GAAG,EACH,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,IAAI,EACT,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,MAAM,EACN,EAAE,EACF,QAAQ,GACT,GAAG,oBAAoB,CAAC,kBAAkB,CAAC,mBAAmB,CAI7D;AACA,IAAA,oBAAoB,EAAE,SAAS;AAC/B,IAAA,SAAS,EAAE,CAAC,MAAM,CAAC,SAAS;IAC5B,SAAS,EAAE,MAAM,CAAC,SAAS;IAC3B,iBAAiB;AACT,CAAA,CAAC;AAEX;;;;;;;;;;;;;;;;;;;AAmBG;AACI,MAAM,KAAK,GAAG;AAErB;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACI,MAAM,KAAK,GAAG;AAErB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCG;AACI,MAAM,GAAG,GAAG;AACjB;;;;;;;AAOG;IACH,EAAE;AAEF;;;;;;;;;;;;;;;;AAgBG;IACH,GAAG;AAEH;;;;;;;;;;;AAWG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;;;;;;;AAWG;AACH,IAAA,GAAG,EAAE,IAAI;AAET;;;;;;;;;;;;;;;;;;;;;AAqBG;IACH,MAAM;AAEN;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;AASG;IACH,GAAG;AAEH;;;;;;;;;;;;;;;;;;;;;AAqBG;IACH,GAAG;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TsDataForgeInternals } from '../refined-number-utils.mjs';
|
|
2
2
|
/**
|
|
3
3
|
* Checks if a number is an Int16 (16-bit signed integer in the range [-2^15, 2^15)).
|
|
4
4
|
* @param value The value to check.
|
|
@@ -81,7 +81,7 @@ export declare const Int16: {
|
|
|
81
81
|
* @param a The Int16 value.
|
|
82
82
|
* @returns The absolute value as an Int16, clamped to valid range.
|
|
83
83
|
*/
|
|
84
|
-
readonly abs: (x: WithSmallInt<Int16, 40>) =>
|
|
84
|
+
readonly abs: (x: WithSmallInt<Int16, 40>) => TsDataForgeInternals.RefinedNumberUtils.ToNonNegative<Int16>;
|
|
85
85
|
/**
|
|
86
86
|
* Returns the smaller of two Int16 values.
|
|
87
87
|
* @param a The first Int16.
|
|
@@ -106,7 +106,7 @@ export declare const Int16: {
|
|
|
106
106
|
* Generates a random Int16 value within the valid range.
|
|
107
107
|
* @returns A random Int16 between MIN_VALUE and MAX_VALUE.
|
|
108
108
|
*/
|
|
109
|
-
readonly random: (min
|
|
109
|
+
readonly random: (min?: WithSmallInt<Int16, 40> | undefined, max?: WithSmallInt<Int16, 40> | undefined) => Int16;
|
|
110
110
|
/**
|
|
111
111
|
* Raises an Int16 to the power of another Int16.
|
|
112
112
|
* @param a The base Int16.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int16.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"int16.d.mts","sourceRoot":"","sources":["../../../src/number/branded-types/int16.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAgCnE;;;;GAIG;AACH,eAAO,MAAM,OAAO,2BAAK,CAAC;AAE1B;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;MAAW,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,KAAK;IAChB;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;OAGG;;IAGH;;;;OAIG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;OAIG;;IAGH;;;OAGG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;IAGH;;;;;OAKG;;;;;;;;;;;;;;;;;;CAEK,CAAC"}
|