@avstantso/ts 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +44 -46
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ The `@avstantso/ts` package provides a comprehensive suite of type-level utiliti
|
|
|
82
82
|
- [TS.Union.ToIntersection](#tsuniontointersectionu) — Union → intersection
|
|
83
83
|
- [TS.Union.Pop](#tsunionpopu) — Pop last from union
|
|
84
84
|
- [TS.Union.ToTuple](#tsuniontotupleu) — Union → tuple
|
|
85
|
-
|
|
85
|
+
- [TS.IsUnion](#tsisuniont-iftrue--true-iffalse--false) — Test if union
|
|
86
86
|
- [TS.Array](#tsarray) — Array type utilities
|
|
87
87
|
- Creation
|
|
88
88
|
- [TS.Array.Create](#tsarraycreatel-item) — Create array of length
|
|
@@ -137,11 +137,11 @@ The `@avstantso/ts` package provides a comprehensive suite of type-level utiliti
|
|
|
137
137
|
- [TS.ASCII.Map.Control](#tsasciimapcontrol) / [.Printable](#tsasciimapprintable) / [.Extended](#tsasciimapextended) — Subset maps
|
|
138
138
|
- [TS.ASCII.Code](#tsasciicode) — Character → code lookup
|
|
139
139
|
- [TS.ASCII.Character](#tsasciicharacter) — All ASCII characters union
|
|
140
|
-
-
|
|
141
|
-
- [TS.
|
|
142
|
-
- [TS.
|
|
143
|
-
- [TS.
|
|
144
|
-
- [TS.
|
|
140
|
+
- **Type-level comparisons**
|
|
141
|
+
- [TS.LT](#tslt) — Less than
|
|
142
|
+
- [TS.LTE](#tslte) — Less than or equal
|
|
143
|
+
- [TS.GT](#tsgt) — Greater than
|
|
144
|
+
- [TS.GTE](#tsgte) — Greater than or equal
|
|
145
145
|
- [TS.String](#tsstring) — String type manipulation
|
|
146
146
|
- [TS.String\<T, D\>](#tsstring-1) — Cast to string literal
|
|
147
147
|
- [TS.String.Possible](#tsstringpossible) — Convertible types
|
|
@@ -189,11 +189,11 @@ The `@avstantso/ts` package provides a comprehensive suite of type-level utiliti
|
|
|
189
189
|
- [Object.keysEx](#objectkeyso)
|
|
190
190
|
- [Object.valuesEx](#objectvaluesexo)
|
|
191
191
|
- [Object.entriesEx](#objectentriesexo)
|
|
192
|
-
-
|
|
192
|
+
- **Boolean logic types**
|
|
193
193
|
- [TS.If](#tsifcondition-iftrue--true-iffalse--false) — Conditional
|
|
194
|
-
- [TS.
|
|
195
|
-
- [TS.
|
|
196
|
-
- [TS.
|
|
194
|
+
- [TS.And](#tsandconditions-iftrue--true-iffalse--false) — Logical AND
|
|
195
|
+
- [TS.Or](#tsorconditions-iftrue--true-iffalse--false) — Logical OR
|
|
196
|
+
- [TS.Xor](#tsxorconditions-iftrue--true-iffalse--false) — Logical XOR
|
|
197
197
|
- [TS.Numeric](#tsnumeric) — Numeric literal utilities
|
|
198
198
|
- Domain-Independent
|
|
199
199
|
- [TS.Numeric.IsPositive](#tsnumericispositive) / [.IsNegative](#tsnumericisnegative) — Sign tests
|
|
@@ -239,7 +239,7 @@ The `@avstantso/ts` package provides a comprehensive suite of type-level utiliti
|
|
|
239
239
|
- [TS.Type.KeyDef()](#tstypekeydefkey-type) — Create keyed def (runtime)
|
|
240
240
|
- [TS.Type.KLD()](#tstypekldkey-type-def) — Create KLD (runtime)
|
|
241
241
|
- [TS.Resolve](#tsresolve) — Type literal resolution
|
|
242
|
-
-
|
|
242
|
+
- **Utility Types** — Miscellaneous utility types
|
|
243
243
|
- [TS.Alt](#tsaltt) — Alternative fields
|
|
244
244
|
- [TS.Flat](#tsflatt-depth--1) — Flatten structure
|
|
245
245
|
- [TS.IfDef](#tsifdef) / [TS.IfDefKey](#tsifdefkey) — Defined selection
|
|
@@ -419,7 +419,7 @@ type Union = 'a' | 'b' | 'c';
|
|
|
419
419
|
type Tuple = TS.Union.ToTuple<Union>; // ['a', 'b', 'c'] (order may vary)
|
|
420
420
|
```
|
|
421
421
|
|
|
422
|
-
### `TS.
|
|
422
|
+
### `TS.IsUnion<T, IfTrue = true, IfFalse = false>`
|
|
423
423
|
|
|
424
424
|
Test if type is a union.
|
|
425
425
|
|
|
@@ -430,10 +430,10 @@ import { TS } from '@avstantso/ts';
|
|
|
430
430
|
type MyUnion = 'a' | 'b' | 'c';
|
|
431
431
|
type NotUnion = string;
|
|
432
432
|
|
|
433
|
-
type Check1 = TS.
|
|
434
|
-
type Check2 = TS.
|
|
435
|
-
type Check3 = TS.
|
|
436
|
-
type Check4 = TS.
|
|
433
|
+
type Check1 = TS.IsUnion<MyUnion>; // true
|
|
434
|
+
type Check2 = TS.IsUnion<NotUnion>; // false
|
|
435
|
+
type Check3 = TS.IsUnion<never>; // false
|
|
436
|
+
type Check4 = TS.IsUnion<number | boolean>; // true
|
|
437
437
|
```
|
|
438
438
|
|
|
439
439
|
---
|
|
@@ -804,7 +804,7 @@ type Idx2 = TS.Array.Max.Index<[1, undefined, 2]>; // 2
|
|
|
804
804
|
|
|
805
805
|
#### `TS.Array.Sort<TArr, Asc = true>`
|
|
806
806
|
|
|
807
|
-
Sort array items. Allows sorting array of `Sort.Pair<K>` to sort any data by key. Based on [
|
|
807
|
+
Sort array items. Allows sorting array of `Sort.Pair<K>` to sort any data by key. Based on [type-level comparisons](#type-level-comparisons).
|
|
808
808
|
|
|
809
809
|
**Example:**
|
|
810
810
|
```typescript
|
|
@@ -867,7 +867,7 @@ if (Field.version === field) {
|
|
|
867
867
|
|
|
868
868
|
## TS.ASCII
|
|
869
869
|
|
|
870
|
-
ASCII character types and utilities based on [ascii-code.com](https://www.ascii-code.com/). Used in [
|
|
870
|
+
ASCII character types and utilities based on [ascii-code.com](https://www.ascii-code.com/). Used in [type-level comparisons](#type-level-comparisons) for string comparison operations.
|
|
871
871
|
|
|
872
872
|
### ASCII Types
|
|
873
873
|
|
|
@@ -976,15 +976,13 @@ console.log(TS.ASCII.length); // 256
|
|
|
976
976
|
|
|
977
977
|
---
|
|
978
978
|
|
|
979
|
-
##
|
|
979
|
+
## Type-level Comparisons
|
|
980
980
|
|
|
981
981
|
Type-level number and string comparisons.
|
|
982
982
|
|
|
983
983
|
String comparison is based on [TS.ASCII](#tsascii) character-to-number conversion. Number comparison splits numbers into digit arrays, compares lengths, then iterates through digits from most to least significant.
|
|
984
984
|
|
|
985
|
-
###
|
|
986
|
-
|
|
987
|
-
#### `TS.Comparisons.LT<A, B, IfTrue = true, IfFalse = false>`
|
|
985
|
+
### `TS.LT<A, B, IfTrue = true, IfFalse = false>`
|
|
988
986
|
|
|
989
987
|
Test if `A < B`.
|
|
990
988
|
|
|
@@ -992,12 +990,12 @@ Test if `A < B`.
|
|
|
992
990
|
```typescript
|
|
993
991
|
import { TS } from '@avstantso/ts';
|
|
994
992
|
|
|
995
|
-
type NumLess = TS.
|
|
996
|
-
type NumNotLess = TS.
|
|
997
|
-
type StrLess = TS.
|
|
993
|
+
type NumLess = TS.LT<1, 2>; // true
|
|
994
|
+
type NumNotLess = TS.LT<2, 1>; // false
|
|
995
|
+
type StrLess = TS.LT<'a', 'b'>; // true
|
|
998
996
|
```
|
|
999
997
|
|
|
1000
|
-
|
|
998
|
+
### `TS.LTE<A, B, IfTrue = true, IfFalse = false>`
|
|
1001
999
|
|
|
1002
1000
|
Test if `A <= B`.
|
|
1003
1001
|
|
|
@@ -1005,11 +1003,11 @@ Test if `A <= B`.
|
|
|
1005
1003
|
```typescript
|
|
1006
1004
|
import { TS } from '@avstantso/ts';
|
|
1007
1005
|
|
|
1008
|
-
type NumLessEq = TS.
|
|
1009
|
-
type StrLessEq = TS.
|
|
1006
|
+
type NumLessEq = TS.LTE<1, 1>; // true
|
|
1007
|
+
type StrLessEq = TS.LTE<'a', 'a'>; // true
|
|
1010
1008
|
```
|
|
1011
1009
|
|
|
1012
|
-
|
|
1010
|
+
### `TS.GT<A, B, IfTrue = true, IfFalse = false>`
|
|
1013
1011
|
|
|
1014
1012
|
Test if `A > B`.
|
|
1015
1013
|
|
|
@@ -1017,11 +1015,11 @@ Test if `A > B`.
|
|
|
1017
1015
|
```typescript
|
|
1018
1016
|
import { TS } from '@avstantso/ts';
|
|
1019
1017
|
|
|
1020
|
-
type NumGreater = TS.
|
|
1021
|
-
type StrGreater = TS.
|
|
1018
|
+
type NumGreater = TS.GT<2, 1>; // true
|
|
1019
|
+
type StrGreater = TS.GT<'b', 'a'>; // true
|
|
1022
1020
|
```
|
|
1023
1021
|
|
|
1024
|
-
|
|
1022
|
+
### `TS.GTE<A, B, IfTrue = true, IfFalse = false>`
|
|
1025
1023
|
|
|
1026
1024
|
Test if `A >= B`.
|
|
1027
1025
|
|
|
@@ -1029,8 +1027,8 @@ Test if `A >= B`.
|
|
|
1029
1027
|
```typescript
|
|
1030
1028
|
import { TS } from '@avstantso/ts';
|
|
1031
1029
|
|
|
1032
|
-
type NumGreaterEq = TS.
|
|
1033
|
-
type StrGreaterEq = TS.
|
|
1030
|
+
type NumGreaterEq = TS.GTE<2, 2>; // true
|
|
1031
|
+
type StrGreaterEq = TS.GTE<'b', 'b'>; // true
|
|
1034
1032
|
```
|
|
1035
1033
|
|
|
1036
1034
|
---
|
|
@@ -1711,7 +1709,7 @@ const stringified = mapObjectValues(user, (key, value) => {
|
|
|
1711
1709
|
|
|
1712
1710
|
---
|
|
1713
1711
|
|
|
1714
|
-
##
|
|
1712
|
+
## Boolean Logic Types
|
|
1715
1713
|
|
|
1716
1714
|
Boolean type utilities and logical operations.
|
|
1717
1715
|
|
|
@@ -1727,7 +1725,7 @@ type Yes = TS.If<true, 'yes', 'no'>; // 'yes'
|
|
|
1727
1725
|
type No = TS.If<false, 'yes', 'no'>; // 'no'
|
|
1728
1726
|
```
|
|
1729
1727
|
|
|
1730
|
-
### `TS.
|
|
1728
|
+
### `TS.And<Conditions, IfTrue = true, IfFalse = false>`
|
|
1731
1729
|
|
|
1732
1730
|
Logical AND on array of conditions.
|
|
1733
1731
|
|
|
@@ -1735,11 +1733,11 @@ Logical AND on array of conditions.
|
|
|
1735
1733
|
```typescript
|
|
1736
1734
|
import { TS } from '@avstantso/ts';
|
|
1737
1735
|
|
|
1738
|
-
type AllTrue = TS.
|
|
1739
|
-
type OneFalse = TS.
|
|
1736
|
+
type AllTrue = TS.And<[true, true, true]>; // true
|
|
1737
|
+
type OneFalse = TS.And<[true, false, true]>; // false
|
|
1740
1738
|
```
|
|
1741
1739
|
|
|
1742
|
-
### `TS.
|
|
1740
|
+
### `TS.Or<Conditions, IfTrue = true, IfFalse = false>`
|
|
1743
1741
|
|
|
1744
1742
|
Logical OR on array of conditions.
|
|
1745
1743
|
|
|
@@ -1747,11 +1745,11 @@ Logical OR on array of conditions.
|
|
|
1747
1745
|
```typescript
|
|
1748
1746
|
import { TS } from '@avstantso/ts';
|
|
1749
1747
|
|
|
1750
|
-
type HasTrue = TS.
|
|
1751
|
-
type AllFalse = TS.
|
|
1748
|
+
type HasTrue = TS.Or<[false, true, false]>; // true
|
|
1749
|
+
type AllFalse = TS.Or<[false, false, false]>; // false
|
|
1752
1750
|
```
|
|
1753
1751
|
|
|
1754
|
-
### `TS.
|
|
1752
|
+
### `TS.Xor<Conditions, IfTrue = true, IfFalse = false>`
|
|
1755
1753
|
|
|
1756
1754
|
Logical XOR on array of conditions (true if exactly one condition is true).
|
|
1757
1755
|
|
|
@@ -1759,9 +1757,9 @@ Logical XOR on array of conditions (true if exactly one condition is true).
|
|
|
1759
1757
|
```typescript
|
|
1760
1758
|
import { TS } from '@avstantso/ts';
|
|
1761
1759
|
|
|
1762
|
-
type OnlyOne = TS.
|
|
1763
|
-
type Multiple = TS.
|
|
1764
|
-
type None = TS.
|
|
1760
|
+
type OnlyOne = TS.Xor<[false, true, false]>; // true
|
|
1761
|
+
type Multiple = TS.Xor<[true, true, false]>; // false
|
|
1762
|
+
type None = TS.Xor<[false, false, false]>; // false
|
|
1765
1763
|
```
|
|
1766
1764
|
|
|
1767
1765
|
---
|
|
@@ -2398,7 +2396,7 @@ type OnlyType = TS.Resolve<{ T: Function }>; // Function
|
|
|
2398
2396
|
|
|
2399
2397
|
---
|
|
2400
2398
|
|
|
2401
|
-
##
|
|
2399
|
+
## Utility Types
|
|
2402
2400
|
|
|
2403
2401
|
Miscellaneous utility types for advanced type manipulation.
|
|
2404
2402
|
|