ts-fortress 2.4.0 → 2.6.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 CHANGED
@@ -71,11 +71,9 @@ if (User.is(userData)) {
71
71
  console.log(`User: ${userData.name}, Age: ${userData.age}`);
72
72
  }
73
73
 
74
- import { Result } from 'ts-data-forge';
75
-
76
74
  // Get validation result with error details
77
75
  const result = User.validate(userData);
78
- if (Result.isOk(result)) {
76
+ if (t.Result.isOk(result)) {
79
77
  const user = result.value; // typed as User
80
78
  } else {
81
79
  console.error('Validation errors:', result.value); // readonly ValidationError[] showing error information
@@ -132,7 +130,7 @@ const completeUser: UserProfile = UserProfile.fill(anyPartialData);
132
130
  // The is() and validate() functions can still detect missing keys
133
131
  console.log(UserProfile.is(partialData)); // false - missing required keys
134
132
  const result = UserProfile.validate(partialData);
135
- if (Result.isErr(result)) {
133
+ if (t.Result.isErr(result)) {
136
134
  console.log(result.value); // ValidationError[] showing missing keys
137
135
  }
138
136
  ```
@@ -413,7 +411,7 @@ const C = t.partial(
413
411
  const UnionBA = t.union([B, A]);
414
412
  const result = UnionBA.validate({ A: 1 });
415
413
 
416
- if (Result.isOk(result)) {
414
+ if (t.Result.isOk(result)) {
417
415
  console.log(result.value); // { A: 1 } <- ✅ Correct! No unexpected fields
418
416
  console.log(A.is(result.value)); // true <- ✅ Correct
419
417
  console.log(B.is(result.value)); // false <- ✅ Correct! B requires field B
@@ -425,7 +423,7 @@ const C = t.partial(
425
423
  const UnionCA = t.union([C, A]);
426
424
  const result = UnionCA.validate({ A: 1 });
427
425
 
428
- if (Result.isOk(result)) {
426
+ if (t.Result.isOk(result)) {
429
427
  console.log(result.value); // { A: 1 } <- ✅ Correct and consistent
430
428
  console.log(A.is(result.value)); // true <- ✅ Correct
431
429
  console.log(C.is(result.value)); // true <- ✅ Consistent! ts-fortress partial types allow extra fields
@@ -496,7 +494,6 @@ The `validate` method performs comprehensive validation and returns a `Result` t
496
494
 
497
495
  ```typescript
498
496
  import * as t from 'ts-fortress';
499
- import { Result } from 'ts-data-forge';
500
497
 
501
498
  const User = t.record({
502
499
  name: t.string(''),
@@ -507,7 +504,7 @@ const User = t.record({
507
504
  const validData = { name: 'Alice', age: 30 };
508
505
  const result = User.validate(validData);
509
506
 
510
- if (Result.isOk(result)) {
507
+ if (t.Result.isOk(result)) {
511
508
  console.log(result.value === validData); // true - same reference!
512
509
  console.log(result.value); // { name: 'Alice', age: 30 }
513
510
  }
@@ -516,7 +513,7 @@ if (Result.isOk(result)) {
516
513
  const invalidData = { name: 'Bob', age: 'thirty' };
517
514
  const errorResult = User.validate(invalidData);
518
515
 
519
- if (Result.isErr(errorResult)) {
516
+ if (t.Result.isErr(errorResult)) {
520
517
  console.log(errorResult.value);
521
518
  // [
522
519
  // {
@@ -749,7 +746,7 @@ const UInt16 = t.uint16(0);
749
746
 
750
747
  // Usage
751
748
  const userIdResult = UserId.validate('user_123');
752
- if (Result.isOk(userIdResult)) {
749
+ if (t.Result.isOk(userIdResult)) {
753
750
  const id: UserId = userIdResult.value;
754
751
  }
755
752
  ```
@@ -815,7 +812,7 @@ const UserType = t.record({
815
812
  const invalidData = { name: 123, age: 'not a number' };
816
813
 
817
814
  const result = UserType.validate(invalidData);
818
- if (Result.isErr(result)) {
815
+ if (t.Result.isErr(result)) {
819
816
  // result.value is an array of ValidationError objects
820
817
  for (const error of result.value) {
821
818
  console.log('Path:', error.path); // ['name'] or ['age']
@@ -851,7 +848,7 @@ const StrictType = t.record(
851
848
  const dataWithExcess = { name: 'John', age: 30, extra: 'not allowed' };
852
849
  const strictResult = StrictType.validate(dataWithExcess);
853
850
 
854
- if (Result.isErr(strictResult)) {
851
+ if (t.Result.isErr(strictResult)) {
855
852
  console.log(strictResult.value);
856
853
  // [{
857
854
  // path: ['extra'],
@@ -0,0 +1,3 @@
1
+ export { FiniteNumber, Int, Int16, Int32, Int8, NonNegativeFiniteNumber, NonNegativeInt16, NonNegativeInt32, NonZeroFiniteNumber, NonZeroInt, NonZeroInt16, NonZeroInt32, NonZeroSafeInt, NonZeroUint16, NonZeroUint32, PositiveFiniteNumber, PositiveInt, PositiveInt16, PositiveInt32, PositiveSafeInt, PositiveUint16, PositiveUint32, Result, SafeInt, SafeUint, Uint, Uint16, Uint32, Uint8, asFiniteNumber, asInt, asInt16, asInt32, asInt8, asNonNegativeFiniteNumber, asNonNegativeInt16, asNonNegativeInt32, asNonZeroFiniteNumber, asNonZeroInt, asNonZeroInt16, asNonZeroInt32, asNonZeroSafeInt, asNonZeroUint16, asNonZeroUint32, asPositiveFiniteNumber, asPositiveInt, asPositiveInt16, asPositiveInt32, asPositiveSafeInt, asPositiveUint16, asPositiveUint32, asSafeInt, asSafeUint, asUint, asUint16, asUint32, asUint8, isBigint, isFiniteNumber, isInt, isInt16, isInt32, isInt8, isNonNegativeFiniteNumber, isNonNegativeInt16, isNonNegativeInt32, isNonZeroFiniteNumber, isNonZeroInt, isNonZeroInt16, isNonZeroInt32, isNonZeroSafeInt, isNonZeroUint16, isNonZeroUint32, isPositiveFiniteNumber, isPositiveInt, isPositiveInt16, isPositiveInt32, isPositiveSafeInt, isPositiveUint16, isPositiveUint32, isSafeInt, isSafeUint, isUint, isUint16, isUint32, isUint8, } from 'ts-data-forge';
2
+ export * from './index.mjs';
3
+ //# sourceMappingURL=entry-point.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-point.d.mts","sourceRoot":"","sources":["../src/entry-point.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,GAAG,EACH,KAAK,EACL,KAAK,EACL,IAAI,EACJ,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,cAAc,EACd,cAAc,EACd,MAAM,EACN,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,MAAM,EACN,KAAK,EACL,cAAc,EACd,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,cAAc,EACd,KAAK,EACL,OAAO,EACP,OAAO,EACP,MAAM,EACN,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,OAAO,GACR,MAAM,eAAe,CAAC;AACvB,cAAc,aAAa,CAAC"}
@@ -0,0 +1,56 @@
1
+ export { FiniteNumber, Int, Int16, Int32, Int8, NonNegativeFiniteNumber, NonNegativeInt16, NonNegativeInt32, NonZeroFiniteNumber, NonZeroInt, NonZeroInt16, NonZeroInt32, NonZeroSafeInt, NonZeroUint16, NonZeroUint32, PositiveFiniteNumber, PositiveInt, PositiveInt16, PositiveInt32, PositiveSafeInt, PositiveUint16, PositiveUint32, Result, SafeInt, SafeUint, Uint, Uint16, Uint32, Uint8, asFiniteNumber, asInt, asInt16, asInt32, asInt8, asNonNegativeFiniteNumber, asNonNegativeInt16, asNonNegativeInt32, asNonZeroFiniteNumber, asNonZeroInt, asNonZeroInt16, asNonZeroInt32, asNonZeroSafeInt, asNonZeroUint16, asNonZeroUint32, asPositiveFiniteNumber, asPositiveInt, asPositiveInt16, asPositiveInt32, asPositiveSafeInt, asPositiveUint16, asPositiveUint32, asSafeInt, asSafeUint, asUint, asUint16, asUint32, asUint8, isBigint, isFiniteNumber, isInt, isInt16, isInt32, isInt8, isNonNegativeFiniteNumber, isNonNegativeInt16, isNonNegativeInt32, isNonZeroFiniteNumber, isNonZeroInt, isNonZeroInt16, isNonZeroInt32, isNonZeroSafeInt, isNonZeroUint16, isNonZeroUint32, isPositiveFiniteNumber, isPositiveInt, isPositiveInt16, isPositiveInt32, isPositiveSafeInt, isPositiveUint16, isPositiveUint32, isSafeInt, isSafeUint, isUint, isUint16, isUint32, isUint8 } from 'ts-data-forge';
2
+ export { arrayOfLength } from './array/array-of-length.mjs';
3
+ export { array } from './array/array.mjs';
4
+ export { nonEmptyArray } from './array/non-empty-array.mjs';
5
+ export { tuple } from './array/tuple.mjs';
6
+ export { brand } from './branded/brand.mjs';
7
+ export { finiteNumber } from './branded/number/finite-number.mjs';
8
+ export { int } from './branded/number/int.mjs';
9
+ export { int16 } from './branded/number/int16.mjs';
10
+ export { int32 } from './branded/number/int32.mjs';
11
+ export { nonNegativeFiniteNumber } from './branded/number/non-negative-finite-number.mjs';
12
+ export { nonZeroFiniteNumber } from './branded/number/non-zero-finite-number.mjs';
13
+ export { nonZeroInt } from './branded/number/non-zero-int.mjs';
14
+ export { nonZeroSafeInt } from './branded/number/non-zero-safe-int.mjs';
15
+ export { positiveFiniteNumber } from './branded/number/positive-finite-number.mjs';
16
+ export { positiveInt } from './branded/number/positive-int.mjs';
17
+ export { positiveSafeInt } from './branded/number/positive-safe-int.mjs';
18
+ export { safeInt } from './branded/number/safe-int.mjs';
19
+ export { safeUint } from './branded/number/safe-uint.mjs';
20
+ export { uint } from './branded/number/uint.mjs';
21
+ export { uint16 } from './branded/number/uint16.mjs';
22
+ export { uint32 } from './branded/number/uint32.mjs';
23
+ export { simpleBrandedNumber } from './branded/simple-branded-number.mjs';
24
+ export { simpleBrandedString } from './branded/simple-branded-string.mjs';
25
+ export { intersection } from './compose/intersection.mjs';
26
+ export { mergeRecords } from './compose/merge-records.mjs';
27
+ export { recursion } from './compose/recursion.mjs';
28
+ export { union } from './compose/union.mjs';
29
+ export { enumType } from './enum/enum.mjs';
30
+ export { intRange } from './enum/int-range.mjs';
31
+ export { uintRange } from './enum/uint-range.mjs';
32
+ export { int8 } from './predefined/int8.mjs';
33
+ export { JsonObject, JsonPrimitive, JsonValue } from './predefined/json.mjs';
34
+ export { uint8 } from './predefined/uint8.mjs';
35
+ export { bigint, bigintLiteral } from './primitives/bigint.mjs';
36
+ export { boolean, booleanLiteral } from './primitives/boolean.mjs';
37
+ export { nullType } from './primitives/null.mjs';
38
+ export { number, numberLiteral } from './primitives/number.mjs';
39
+ export { string, stringLiteral } from './primitives/string.mjs';
40
+ export { symbol } from './primitives/symbol.mjs';
41
+ export { undefinedType } from './primitives/undefined.mjs';
42
+ export { keyValueRecord } from './record/key-value-record.mjs';
43
+ export { keyof } from './record/keyof.mjs';
44
+ export { omit } from './record/omit.mjs';
45
+ export { isOptionalProperty, optional } from './record/optional.mjs';
46
+ export { partial } from './record/partial.mjs';
47
+ export { pick } from './record/pick.mjs';
48
+ export { record, strictRecord } from './record/record.mjs';
49
+ export { unknown } from './unknown.mjs';
50
+ export { createAssertFn } from './utils/create-assert-fn.mjs';
51
+ export { createCastFn } from './utils/create-cast-fn.mjs';
52
+ export { createIsFn } from './utils/create-is-fn.mjs';
53
+ export { createPrimitiveType } from './utils/create-primitive-type.mjs';
54
+ export { createType } from './utils/create-type.mjs';
55
+ export { createPrimitiveValidationError, prependIndexToValidationErrors, prependPathToValidationErrors, validationErrorToMessage, validationErrorsToMessages } from './utils/validation-error.mjs';
56
+ //# sourceMappingURL=entry-point.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry-point.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,4 @@
1
1
  export * from './enum.mjs';
2
+ export * from './int-range.mjs';
2
3
  export * from './uint-range.mjs';
3
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/enum/index.mts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/enum/index.mts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export { enumType } from './enum.mjs';
2
+ export { intRange } from './int-range.mjs';
2
3
  export { uintRange } from './uint-range.mjs';
3
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,13 @@
1
+ import { type Type } from '../type.mjs';
2
+ export declare const intRange: <Start extends Int8 | -128, End extends Int8 | 128>({ start, end, ...options }: Readonly<{
3
+ typeName?: string;
4
+ start: Start;
5
+ end: End;
6
+ defaultValue?: IntRange<Start, End>;
7
+ }>) => Type<IntRange<Start, End>>;
8
+ type NegativeRange = NegativeIndex<128>;
9
+ type PositiveRange = IndexInclusive<128>;
10
+ type IntRange<Start extends Int8 | -128, End extends Int8 | 128> = BoolAnd<TypeExtends<Start, PositiveRange>, TypeExtends<End, PositiveRange>> extends true ? UintRange<Start, End> : BoolAnd<TypeExtends<Start, NegativeRange>, TypeExtends<End, PositiveRange>> extends true ? NegativeIndex<NegativeToPositive<Start>> | Index<End> : BoolAnd<TypeExtends<Start, PositiveRange>, TypeExtends<End, NegativeRange>> extends true ? never : BoolAnd<TypeExtends<Start, NegativeRange>, TypeExtends<End, NegativeRange>> extends true ? Exclude<NegativeIndex<NegativeToPositive<Start>>, NegativeIndex<NegativeToPositive<End>>> : never;
11
+ type NegativeToPositive<N extends number> = `${N}` extends `-${infer D extends number}` ? D : never;
12
+ export {};
13
+ //# sourceMappingURL=int-range.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"int-range.d.mts","sourceRoot":"","sources":["../../src/enum/int-range.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAQxC,eAAO,MAAM,QAAQ,GAAI,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,SAAS,IAAI,GAAG,GAAG,EAAE,4BAIzE,QAAQ,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,YAAY,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;CACrC,CAAC,KAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAwC7B,CAAC;AAEF,KAAK,aAAa,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;AACxC,KAAK,aAAa,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;AAEzC,KAAK,QAAQ,CAAC,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,SAAS,IAAI,GAAG,GAAG,IAC7D,OAAO,CACL,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,EACjC,WAAW,CAAC,GAAG,EAAE,aAAa,CAAC,CAChC,SAAS,IAAI,GACV,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,GACrB,OAAO,CACH,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,EACjC,WAAW,CAAC,GAAG,EAAE,aAAa,CAAC,CAChC,SAAS,IAAI,GACd,aAAa,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,GACrD,OAAO,CACH,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,EACjC,WAAW,CAAC,GAAG,EAAE,aAAa,CAAC,CAChC,SAAS,IAAI,GACd,KAAK,GACL,OAAO,CACH,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,EACjC,WAAW,CAAC,GAAG,EAAE,aAAa,CAAC,CAChC,SAAS,IAAI,GACd,OAAO,CACL,aAAa,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,EACxC,aAAa,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,CACvC,GACD,KAAK,CAAC;AAElB,KAAK,kBAAkB,CAAC,CAAC,SAAS,MAAM,IACtC,GAAG,CAAC,EAAE,SAAS,IAAI,MAAM,CAAC,SAAS,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { isNumber, Num, Result } from 'ts-data-forge';
2
+ import { createAssertFn } from '../utils/create-assert-fn.mjs';
3
+ import { createCastFn } from '../utils/create-cast-fn.mjs';
4
+ import { createIsFn } from '../utils/create-is-fn.mjs';
5
+
6
+ const intRange = ({ start, end, ...options }) => {
7
+ const typeNameFilled = options.typeName ?? `intRange(${start}, ${end})`;
8
+ const defaultValue = options.defaultValue ??
9
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
10
+ start;
11
+ const validate = (a) => {
12
+ if (!(isNumber(a) && Number.isInteger(a) && Num.isInRange(start, end)(a))) {
13
+ return Result.err([
14
+ {
15
+ path: [],
16
+ actualValue: a,
17
+ expectedType: typeNameFilled,
18
+ message: `The value is expected to be an integer between ${start} and ${end - 1}`,
19
+ typeName: typeNameFilled,
20
+ },
21
+ ]);
22
+ }
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
24
+ return Result.ok(a);
25
+ };
26
+ const is = createIsFn(validate);
27
+ const fill = (a) => (is(a) ? a : defaultValue);
28
+ return {
29
+ typeName: typeNameFilled,
30
+ defaultValue,
31
+ fill,
32
+ validate,
33
+ is,
34
+ assertIs: createAssertFn(validate),
35
+ cast: createCastFn(validate),
36
+ };
37
+ };
38
+
39
+ export { intRange };
40
+ //# sourceMappingURL=int-range.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"int-range.mjs","sources":["../../src/enum/int-range.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AASO,MAAM,QAAQ,GAAG,CAAoD,EAC1E,KAAK,EACL,GAAG,EACH,GAAG,OAAO,EAMV,KAAgC;IAGhC,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAA,SAAA,EAAY,KAAK,CAAA,EAAA,EAAK,GAAG,CAAA,CAAA,CAAG;AAEvE,IAAA,MAAM,YAAY,GAChB,OAAO,CAAC,YAAY;;AAEnB,QAAA,KAAW;AAEd,IAAA,MAAM,QAAQ,GAAwB,CAAC,CAAC,KAAI;QAC1C,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YACzE,OAAO,MAAM,CAAC,GAAG,CAAC;AAChB,gBAAA;AACE,oBAAA,IAAI,EAAE,EAAE;AACR,oBAAA,WAAW,EAAE,CAAC;AACd,oBAAA,YAAY,EAAE,cAAc;AAC5B,oBAAA,OAAO,EAAE,CAAA,+CAAA,EAAkD,KAAK,QAAQ,GAAG,GAAG,CAAC,CAAA,CAAE;AACjF,oBAAA,QAAQ,EAAE,cAAc;AACY,iBAAA;AACvC,aAAA,CAAC;;;AAIJ,QAAA,OAAO,MAAM,CAAC,EAAE,CAAC,CAAM,CAAC;AAC1B,IAAA,CAAC;AAED,IAAA,MAAM,EAAE,GAAG,UAAU,CAAI,QAAQ,CAAC;IAElC,MAAM,IAAI,GAAoB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;IAE/D,OAAO;AACL,QAAA,QAAQ,EAAE,cAAc;QACxB,YAAY;QACZ,IAAI;QACJ,QAAQ;QACR,EAAE;AACF,QAAA,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;AAClC,QAAA,IAAI,EAAE,YAAY,CAAC,QAAQ,CAAC;KAC7B;AACH;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { type Type } from '../type.mjs';
2
- export declare const uintRange: <Start extends Uint8, End extends Exclude<Uint8, Start>>({ start, end, ...options }: Readonly<{
2
+ export declare const uintRange: <Start extends Uint8, End extends Exclude<Uint8 | 256, Start>>({ start, end, ...options }: Readonly<{
3
3
  typeName?: string;
4
4
  start: Start;
5
5
  end: End;
@@ -1 +1 @@
1
- {"version":3,"file":"uint-range.d.mts","sourceRoot":"","sources":["../../src/enum/uint-range.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAQxC,eAAO,MAAM,SAAS,GACpB,KAAK,SAAS,KAAK,EACnB,GAAG,SAAS,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,EACjC,4BAIC,QAAQ,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,YAAY,CAAC,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;CACtC,CAAC,KAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAwC9B,CAAC"}
1
+ {"version":3,"file":"uint-range.d.mts","sourceRoot":"","sources":["../../src/enum/uint-range.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAQxC,eAAO,MAAM,SAAS,GACpB,KAAK,SAAS,KAAK,EACnB,GAAG,SAAS,OAAO,CAAC,KAAK,GAAG,GAAG,EAAE,KAAK,CAAC,EACvC,4BAIC,QAAQ,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,YAAY,CAAC,EAAE,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;CACtC,CAAC,KAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAwC9B,CAAC"}
package/dist/index.mjs CHANGED
@@ -26,8 +26,11 @@ export { mergeRecords } from './compose/merge-records.mjs';
26
26
  export { recursion } from './compose/recursion.mjs';
27
27
  export { union } from './compose/union.mjs';
28
28
  export { enumType } from './enum/enum.mjs';
29
+ export { intRange } from './enum/int-range.mjs';
29
30
  export { uintRange } from './enum/uint-range.mjs';
31
+ export { int8 } from './predefined/int8.mjs';
30
32
  export { JsonObject, JsonPrimitive, JsonValue } from './predefined/json.mjs';
33
+ export { uint8 } from './predefined/uint8.mjs';
31
34
  export { bigint, bigintLiteral } from './primitives/bigint.mjs';
32
35
  export { boolean, booleanLiteral } from './primitives/boolean.mjs';
33
36
  export { nullType } from './primitives/null.mjs';
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,2 +1,4 @@
1
+ export * from './int8.mjs';
1
2
  export * from './json.mjs';
3
+ export * from './uint8.mjs';
2
4
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/predefined/index.mts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/predefined/index.mts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
@@ -1,2 +1,4 @@
1
+ export { int8 } from './int8.mjs';
1
2
  export { JsonObject, JsonPrimitive, JsonValue } from './json.mjs';
3
+ export { uint8 } from './uint8.mjs';
2
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,3 @@
1
+ import { type Type } from '../type.mjs';
2
+ export declare const int8: (defaultValue?: Int8) => Type<Int8>;
3
+ //# sourceMappingURL=int8.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"int8.d.mts","sourceRoot":"","sources":["../../src/predefined/int8.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,eAAO,MAAM,IAAI,GAAI,eAAc,IAAQ,KAAG,IAAI,CAAC,IAAI,CAKnD,CAAC"}
@@ -0,0 +1,11 @@
1
+ import 'ts-data-forge';
2
+ import { intRange } from '../enum/int-range.mjs';
3
+
4
+ const int8 = (defaultValue = 0) => intRange({
5
+ start: -128,
6
+ end: 128,
7
+ defaultValue,
8
+ });
9
+
10
+ export { int8 };
11
+ //# sourceMappingURL=int8.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"int8.mjs","sources":["../../src/predefined/int8.mts"],"sourcesContent":[null],"names":[],"mappings":";;;AAGO,MAAM,IAAI,GAAG,CAAC,YAAA,GAAqB,CAAC,KACzC,QAAQ,CAAC;IACP,KAAK,EAAE,IAAI;AACX,IAAA,GAAG,EAAE,GAAG;IACR,YAAY;AACb,CAAA;;;;"}
@@ -0,0 +1,3 @@
1
+ import { type Type } from '../type.mjs';
2
+ export declare const uint8: (defaultValue?: Uint8) => Type<Uint8>;
3
+ //# sourceMappingURL=uint8.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint8.d.mts","sourceRoot":"","sources":["../../src/predefined/uint8.mts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAExC,eAAO,MAAM,KAAK,GAAI,eAAc,KAAS,KAAG,IAAI,CAAC,KAAK,CAKtD,CAAC"}
@@ -0,0 +1,11 @@
1
+ import 'ts-data-forge';
2
+ import { uintRange } from '../enum/uint-range.mjs';
3
+
4
+ const uint8 = (defaultValue = 0) => uintRange({
5
+ start: 0,
6
+ end: 256,
7
+ defaultValue,
8
+ });
9
+
10
+ export { uint8 };
11
+ //# sourceMappingURL=uint8.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint8.mjs","sources":["../../src/predefined/uint8.mts"],"sourcesContent":[null],"names":[],"mappings":";;;AAGO,MAAM,KAAK,GAAG,CAAC,YAAA,GAAsB,CAAC,KAC3C,SAAS,CAAC;AACR,IAAA,KAAK,EAAE,CAAC;AACR,IAAA,GAAG,EAAE,GAAG;IACR,YAAY;AACb,CAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-fortress",
3
- "version": "2.4.0",
3
+ "version": "2.6.0",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "typescript"
@@ -17,11 +17,11 @@
17
17
  ".": {
18
18
  "import": {
19
19
  "types": "./dist/types.d.mts",
20
- "default": "./dist/index.mjs"
20
+ "default": "./dist/entry-point.mjs"
21
21
  }
22
22
  }
23
23
  },
24
- "module": "./dist/index.mjs",
24
+ "module": "./dist/entry-point.mjs",
25
25
  "types": "./dist/types.d.mts",
26
26
  "files": [
27
27
  "src",
@@ -37,7 +37,7 @@
37
37
  "doc": "tsx ./scripts/cmd/gen-docs.mjs",
38
38
  "fmt": "format-diff-from origin/main",
39
39
  "fmt:full": "prettier --write .",
40
- "gi": "gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --fmt 'npm run fmt'",
40
+ "gi": "gen-index-ts ./src --index-ext .mts --export-ext .mjs --target-ext .mts --target-ext .tsx --exclude entry-point.mts --fmt 'npm run fmt'",
41
41
  "lint": "eslint .",
42
42
  "lint:fix": "eslint . --fix",
43
43
  "md": "markdownlint-cli2",
@@ -57,7 +57,7 @@
57
57
  "ts-type-forge": "^2.2.0"
58
58
  },
59
59
  "devDependencies": {
60
- "@eslint/js": "^9.33.0",
60
+ "@eslint/js": "^9.34.0",
61
61
  "@rollup/plugin-replace": "^6.0.2",
62
62
  "@rollup/plugin-strip": "^3.0.4",
63
63
  "@rollup/plugin-typescript": "^12.1.4",
@@ -73,7 +73,7 @@
73
73
  "@vitest/ui": "^3.2.4",
74
74
  "conventional-changelog-conventionalcommits": "^9.1.0",
75
75
  "cspell": "^9.2.0",
76
- "eslint": "^9.33.0",
76
+ "eslint": "^9.34.0",
77
77
  "eslint-import-resolver-typescript": "4.4.4",
78
78
  "eslint-plugin-array-func": "5.0.2",
79
79
  "eslint-plugin-functional": "9.0.2",
@@ -89,7 +89,7 @@
89
89
  "prettier": "^3.6.2",
90
90
  "prettier-plugin-organize-imports": "^4.2.0",
91
91
  "prettier-plugin-packagejson": "^2.5.19",
92
- "rollup": "^4.46.2",
92
+ "rollup": "^4.48.0",
93
93
  "semantic-release": "^24.2.7",
94
94
  "ts-repo-utils": "^6.0.3",
95
95
  "tslib": "^2.8.1",
@@ -97,8 +97,8 @@
97
97
  "typedoc": "^0.28.10",
98
98
  "typedoc-plugin-markdown": "^4.8.1",
99
99
  "typescript": "^5.9.2",
100
- "typescript-eslint": "^8.39.1",
100
+ "typescript-eslint": "^8.40.0",
101
101
  "vitest": "^3.2.4",
102
- "zod": "^4.0.17"
102
+ "zod": "^4.1.0"
103
103
  }
104
104
  }
@@ -0,0 +1,89 @@
1
+ export {
2
+ FiniteNumber,
3
+ Int,
4
+ Int16,
5
+ Int32,
6
+ Int8,
7
+ NonNegativeFiniteNumber,
8
+ NonNegativeInt16,
9
+ NonNegativeInt32,
10
+ NonZeroFiniteNumber,
11
+ NonZeroInt,
12
+ NonZeroInt16,
13
+ NonZeroInt32,
14
+ NonZeroSafeInt,
15
+ NonZeroUint16,
16
+ NonZeroUint32,
17
+ PositiveFiniteNumber,
18
+ PositiveInt,
19
+ PositiveInt16,
20
+ PositiveInt32,
21
+ PositiveSafeInt,
22
+ PositiveUint16,
23
+ PositiveUint32,
24
+ Result,
25
+ SafeInt,
26
+ SafeUint,
27
+ Uint,
28
+ Uint16,
29
+ Uint32,
30
+ Uint8,
31
+ asFiniteNumber,
32
+ asInt,
33
+ asInt16,
34
+ asInt32,
35
+ asInt8,
36
+ asNonNegativeFiniteNumber,
37
+ asNonNegativeInt16,
38
+ asNonNegativeInt32,
39
+ asNonZeroFiniteNumber,
40
+ asNonZeroInt,
41
+ asNonZeroInt16,
42
+ asNonZeroInt32,
43
+ asNonZeroSafeInt,
44
+ asNonZeroUint16,
45
+ asNonZeroUint32,
46
+ asPositiveFiniteNumber,
47
+ asPositiveInt,
48
+ asPositiveInt16,
49
+ asPositiveInt32,
50
+ asPositiveSafeInt,
51
+ asPositiveUint16,
52
+ asPositiveUint32,
53
+ asSafeInt,
54
+ asSafeUint,
55
+ asUint,
56
+ asUint16,
57
+ asUint32,
58
+ asUint8,
59
+ isBigint,
60
+ isFiniteNumber,
61
+ isInt,
62
+ isInt16,
63
+ isInt32,
64
+ isInt8,
65
+ isNonNegativeFiniteNumber,
66
+ isNonNegativeInt16,
67
+ isNonNegativeInt32,
68
+ isNonZeroFiniteNumber,
69
+ isNonZeroInt,
70
+ isNonZeroInt16,
71
+ isNonZeroInt32,
72
+ isNonZeroSafeInt,
73
+ isNonZeroUint16,
74
+ isNonZeroUint32,
75
+ isPositiveFiniteNumber,
76
+ isPositiveInt,
77
+ isPositiveInt16,
78
+ isPositiveInt32,
79
+ isPositiveSafeInt,
80
+ isPositiveUint16,
81
+ isPositiveUint32,
82
+ isSafeInt,
83
+ isSafeUint,
84
+ isUint,
85
+ isUint16,
86
+ isUint32,
87
+ isUint8,
88
+ } from 'ts-data-forge';
89
+ export * from './index.mjs';
@@ -1,2 +1,3 @@
1
1
  export * from './enum.mjs';
2
+ export * from './int-range.mjs';
2
3
  export * from './uint-range.mjs';
@@ -0,0 +1,98 @@
1
+ import { expectType, isNumber, Num, Result } from 'ts-data-forge';
2
+ import { type Type } from '../type.mjs';
3
+ import {
4
+ createAssertFn,
5
+ createCastFn,
6
+ createIsFn,
7
+ type ValidationErrorWithMessage,
8
+ } from '../utils/index.mjs';
9
+
10
+ export const intRange = <Start extends Int8 | -128, End extends Int8 | 128>({
11
+ start,
12
+ end,
13
+ ...options
14
+ }: Readonly<{
15
+ typeName?: string;
16
+ start: Start;
17
+ end: End;
18
+ defaultValue?: IntRange<Start, End>;
19
+ }>): Type<IntRange<Start, End>> => {
20
+ type T = IntRange<Start, End>;
21
+
22
+ const typeNameFilled = options.typeName ?? `intRange(${start}, ${end})`;
23
+
24
+ const defaultValue: T =
25
+ options.defaultValue ??
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
27
+ (start as T);
28
+
29
+ const validate: Type<T>['validate'] = (a) => {
30
+ if (!(isNumber(a) && Number.isInteger(a) && Num.isInRange(start, end)(a))) {
31
+ return Result.err([
32
+ {
33
+ path: [],
34
+ actualValue: a,
35
+ expectedType: typeNameFilled,
36
+ message: `The value is expected to be an integer between ${start} and ${end - 1}`,
37
+ typeName: typeNameFilled,
38
+ } satisfies ValidationErrorWithMessage,
39
+ ]);
40
+ }
41
+
42
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
43
+ return Result.ok(a as T);
44
+ };
45
+
46
+ const is = createIsFn<T>(validate);
47
+
48
+ const fill: Type<T>['fill'] = (a) => (is(a) ? a : defaultValue);
49
+
50
+ return {
51
+ typeName: typeNameFilled,
52
+ defaultValue,
53
+ fill,
54
+ validate,
55
+ is,
56
+ assertIs: createAssertFn(validate),
57
+ cast: createCastFn(validate),
58
+ };
59
+ };
60
+
61
+ type NegativeRange = NegativeIndex<128>;
62
+ type PositiveRange = IndexInclusive<128>;
63
+
64
+ type IntRange<Start extends Int8 | -128, End extends Int8 | 128> =
65
+ BoolAnd<
66
+ TypeExtends<Start, PositiveRange>,
67
+ TypeExtends<End, PositiveRange>
68
+ > extends true
69
+ ? UintRange<Start, End>
70
+ : BoolAnd<
71
+ TypeExtends<Start, NegativeRange>,
72
+ TypeExtends<End, PositiveRange>
73
+ > extends true
74
+ ? NegativeIndex<NegativeToPositive<Start>> | Index<End>
75
+ : BoolAnd<
76
+ TypeExtends<Start, PositiveRange>,
77
+ TypeExtends<End, NegativeRange>
78
+ > extends true
79
+ ? never
80
+ : BoolAnd<
81
+ TypeExtends<Start, NegativeRange>,
82
+ TypeExtends<End, NegativeRange>
83
+ > extends true
84
+ ? Exclude<
85
+ NegativeIndex<NegativeToPositive<Start>>,
86
+ NegativeIndex<NegativeToPositive<End>>
87
+ >
88
+ : never;
89
+
90
+ type NegativeToPositive<N extends number> =
91
+ `${N}` extends `-${infer D extends number}` ? D : never;
92
+
93
+ expectType<NegativeToPositive<-3>, 3>('=');
94
+
95
+ expectType<IntRange<1, 5>, 1 | 2 | 3 | 4>('=');
96
+ expectType<IntRange<-3, 3>, -3 | -2 | -1 | 0 | 1 | 2>('=');
97
+ expectType<IntRange<3, -3>, never>('=');
98
+ expectType<IntRange<-5, -1>, -5 | -4 | -3 | -2>('=');
@@ -9,7 +9,7 @@ import {
9
9
 
10
10
  export const uintRange = <
11
11
  Start extends Uint8,
12
- End extends Exclude<Uint8, Start>,
12
+ End extends Exclude<Uint8 | 256, Start>,
13
13
  >({
14
14
  start,
15
15
  end,
@@ -1 +1,3 @@
1
+ export * from './int8.mjs';
1
2
  export * from './json.mjs';
3
+ export * from './uint8.mjs';
@@ -0,0 +1,9 @@
1
+ import { intRange } from '../enum/index.mjs';
2
+ import { type Type } from '../type.mjs';
3
+
4
+ export const int8 = (defaultValue: Int8 = 0): Type<Int8> =>
5
+ intRange({
6
+ start: -128,
7
+ end: 128,
8
+ defaultValue,
9
+ });
@@ -0,0 +1,9 @@
1
+ import { uintRange } from '../enum/index.mjs';
2
+ import { type Type } from '../type.mjs';
3
+
4
+ export const uint8 = (defaultValue: Uint8 = 0): Type<Uint8> =>
5
+ uintRange({
6
+ start: 0,
7
+ end: 256,
8
+ defaultValue,
9
+ });