inferred-types 0.54.8 → 0.55.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 +81 -36
- package/modules/constants/dist/index.cjs +118 -1
- package/modules/constants/dist/index.cjs.map +1 -1
- package/modules/constants/dist/index.d.ts +29 -1
- package/modules/constants/dist/index.js +113 -1
- package/modules/constants/dist/index.js.map +1 -1
- package/modules/inferred-types/dist/index.cjs +423 -24
- package/modules/inferred-types/dist/index.cjs.map +1 -1
- package/modules/inferred-types/dist/index.d.ts +19949 -19238
- package/modules/inferred-types/dist/index.js +403 -24
- package/modules/inferred-types/dist/index.js.map +1 -1
- package/modules/runtime/dist/index.cjs +327 -23
- package/modules/runtime/dist/index.cjs.map +1 -1
- package/modules/runtime/dist/index.d.ts +5485 -5155
- package/modules/runtime/dist/index.js +312 -23
- package/modules/runtime/dist/index.js.map +1 -1
- package/modules/types/dist/index.d.ts +9680 -9327
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -70,6 +70,20 @@ const people = pluralize("person");
|
|
|
70
70
|
#### Data Patterns
|
|
71
71
|
|
|
72
72
|
- types like `Url`, `IpAddress`, `CSV`, `DotPath`, `Hexadecimal`, `ZipCode`, and `DomainName` attempt to provide an out of the box type for common data structure patterns we find in the real world
|
|
73
|
+
- ISO3166 support (aka, countries):
|
|
74
|
+
- `Iso3166_Alpha2`, `Iso3166_Alpha3`, ...
|
|
75
|
+
- `isIso3166Alpha2()`, `isIsoAlpha3()`, type guards ...
|
|
76
|
+
- ISO8601 support (aka, datetime)
|
|
77
|
+
- `Iso8601DateTime`, `Iso8601Date`, `Iso8601Time`, ...
|
|
78
|
+
- `isIsoDateTime()`, `isIsoDate()`, `isIsoTime()`, ...
|
|
79
|
+
|
|
80
|
+
#### String Literal Matching at design time and run time
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const matcher = infer("{{ string }} is a {{ infer foo }} utility, that {{ infer bar }}");
|
|
84
|
+
// { foo: "fancy"; bar: "thinks it's better than you!"}
|
|
85
|
+
const fooBar = matcher("infer is a fancy utility, that thinks it's better than you!")
|
|
86
|
+
```
|
|
73
87
|
|
|
74
88
|
### Numeric Literals
|
|
75
89
|
|
|
@@ -89,42 +103,73 @@ const people = pluralize("person");
|
|
|
89
103
|
|
|
90
104
|
### Object / Dictionaries
|
|
91
105
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
106
|
+
#### Reduce Object to Keys with a knownValue
|
|
107
|
+
|
|
108
|
+
Assume a base type of `Obj`:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
type Obj = {
|
|
112
|
+
n1: number;
|
|
113
|
+
n2: 2;
|
|
114
|
+
n3: 3;
|
|
115
|
+
success: true;
|
|
116
|
+
s1: string;
|
|
117
|
+
s2: "hello";
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
We can get a union of string literals representing the _keys_ on the object whose value _extends_ some value:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import type { KeysWithValue, KeysWithoutValue } from "inferred-types";
|
|
125
|
+
// "s1" | "s2"
|
|
126
|
+
type S = KeysWithValue<Obj, string>;
|
|
127
|
+
// "success" | "n1" | "n2"
|
|
128
|
+
type N = KeysWithoutValue<Obj, string>;
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
> though less used, you can also use `KeysEqualValue` and `KeysNotEqualValue` for equality matching
|
|
132
|
+
|
|
133
|
+
If you'd prefer to mutate the object's type rather than just identify the _keys_ which extend a value you can do this with: `WithValue` and `WithoutValue`:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import type { WithValue, WithoutValue } from "inferred-types";
|
|
137
|
+
// { s1: string; s2: "hello" }
|
|
138
|
+
type S = WithValue<Obj, string>;
|
|
139
|
+
// { success: true; n1: number; n2: 2; n3: 3 }
|
|
140
|
+
type N = WithoutValue<Obj, string>;
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
And at runtime:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
// { foo: "hi" }
|
|
147
|
+
const foo = withoutValue("number")({ foo: "hi", bar: 42, baz: 99 });
|
|
148
|
+
// { bar: 42 }
|
|
149
|
+
const bar = withoutValue("number(42,55,66)")({ foo: "hi", bar: 42, baz: 99 });
|
|
150
|
+
|
|
151
|
+
// { foo: "hi", bar: 42 }
|
|
152
|
+
const fooBar = withoutKeys("baz")({ foo: "hi", bar: 42, baz: 99 });
|
|
153
|
+
// { foo: "hi", bar: 42 }
|
|
154
|
+
const fooBar2 = withKeys("foo", "bar")({ foo: "hi", bar: 42, baz: 99 })
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### Reduce Object's to only `Required` or `Optional` keys
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
type Obj = { foo: string; bar?: string; baz?: number };
|
|
161
|
+
// "foo"
|
|
162
|
+
type ReqKeys = RequiredKeys<Obj>;
|
|
163
|
+
// ["foo"]
|
|
164
|
+
type ReqKeyTup = RequiredKeysTuple<Obj>;
|
|
165
|
+
// "bar" | "baz"
|
|
166
|
+
type OptKeys = OptionalKeys<Obj>;
|
|
167
|
+
// ["bar", "baz"]
|
|
168
|
+
type OptKeyTup = OptionalKeysTuple<Obj>;
|
|
169
|
+
|
|
170
|
+
type Reduced =
|
|
171
|
+
|
|
172
|
+
```
|
|
128
173
|
|
|
129
174
|
## Contributing
|
|
130
175
|
|
|
@@ -79,10 +79,14 @@ __export(src_exports, {
|
|
|
79
79
|
MARKED: () => MARKED,
|
|
80
80
|
MASS_METRICS_LOOKUP: () => MASS_METRICS_LOOKUP,
|
|
81
81
|
MEXICAN_NEWS: () => MEXICAN_NEWS,
|
|
82
|
+
MIME_TYPES: () => MIME_TYPES,
|
|
82
83
|
MONTH_ABBR: () => MONTH_ABBR,
|
|
83
84
|
MONTH_NAME: () => MONTH_NAME,
|
|
84
85
|
NARROW_CONTAINER_TYPE_KINDS: () => NARROW_CONTAINER_TYPE_KINDS,
|
|
86
|
+
NETWORK_PROTOCOL: () => NETWORK_PROTOCOL,
|
|
87
|
+
NETWORK_PROTOCOL_INSECURE: () => NETWORK_PROTOCOL_INSECURE,
|
|
85
88
|
NETWORK_PROTOCOL_LOOKUP: () => NETWORK_PROTOCOL_LOOKUP,
|
|
89
|
+
NETWORK_PROTOCOL_SECURE: () => NETWORK_PROTOCOL_SECURE,
|
|
86
90
|
NIKE_DNS: () => NIKE_DNS,
|
|
87
91
|
NON_ZERO_NUMERIC_CHAR: () => NON_ZERO_NUMERIC_CHAR,
|
|
88
92
|
NORWEGIAN_NEWS: () => NORWEGIAN_NEWS,
|
|
@@ -99,6 +103,7 @@ __export(src_exports, {
|
|
|
99
103
|
PLURAL_EXCEPTIONS_OLD: () => PLURAL_EXCEPTIONS_OLD,
|
|
100
104
|
POWER_METRICS_LOOKUP: () => POWER_METRICS_LOOKUP,
|
|
101
105
|
PRESSURE_METRICS_LOOKUP: () => PRESSURE_METRICS_LOOKUP,
|
|
106
|
+
PROTOCOL_DEFAULT_PORTS: () => PROTOCOL_DEFAULT_PORTS,
|
|
102
107
|
PROXMOX_CT_STATE: () => PROXMOX_CT_STATE,
|
|
103
108
|
REPO_PAGE_TYPES: () => REPO_PAGE_TYPES,
|
|
104
109
|
REPO_SOURCES: () => REPO_SOURCES,
|
|
@@ -740,6 +745,75 @@ var HASH_TABLE_CHAR = {
|
|
|
740
745
|
};
|
|
741
746
|
var HASH_TABLE_OTHER = "999";
|
|
742
747
|
|
|
748
|
+
// src/Http.ts
|
|
749
|
+
var MIME_TYPES = [
|
|
750
|
+
// Application MIME Types
|
|
751
|
+
"application/json",
|
|
752
|
+
"application/xml",
|
|
753
|
+
"application/javascript",
|
|
754
|
+
"application/pdf",
|
|
755
|
+
"application/ld+json",
|
|
756
|
+
"application/octet-stream",
|
|
757
|
+
"application/x-www-form-urlencoded",
|
|
758
|
+
"application/vnd.api+json",
|
|
759
|
+
"application/msword",
|
|
760
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
761
|
+
"application/vnd.ms-excel",
|
|
762
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
763
|
+
"application/vnd.ms-powerpoint",
|
|
764
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
765
|
+
// Text MIME Types
|
|
766
|
+
"text/plain",
|
|
767
|
+
"text/html",
|
|
768
|
+
"text/css",
|
|
769
|
+
"text/csv",
|
|
770
|
+
"text/javascript",
|
|
771
|
+
"text/markdown",
|
|
772
|
+
// Image MIME Types
|
|
773
|
+
"image/jpeg",
|
|
774
|
+
"image/png",
|
|
775
|
+
"image/gif",
|
|
776
|
+
"image/bmp",
|
|
777
|
+
"image/webp",
|
|
778
|
+
"image/svg+xml",
|
|
779
|
+
"image/tiff",
|
|
780
|
+
// Audio MIME Types
|
|
781
|
+
"audio/mpeg",
|
|
782
|
+
"audio/ogg",
|
|
783
|
+
"audio/wav",
|
|
784
|
+
"audio/webm",
|
|
785
|
+
"audio/flac",
|
|
786
|
+
// Video MIME Types
|
|
787
|
+
"video/mp4",
|
|
788
|
+
"video/mpeg",
|
|
789
|
+
"video/ogg",
|
|
790
|
+
"video/webm",
|
|
791
|
+
"video/quicktime",
|
|
792
|
+
// Multipart MIME Types
|
|
793
|
+
"multipart/form-data",
|
|
794
|
+
"multipart/mixed",
|
|
795
|
+
"multipart/alternative",
|
|
796
|
+
"multipart/related",
|
|
797
|
+
// Font MIME Types
|
|
798
|
+
"font/woff",
|
|
799
|
+
"font/woff2",
|
|
800
|
+
"font/ttf",
|
|
801
|
+
"font/otf",
|
|
802
|
+
// Other Common MIME Types
|
|
803
|
+
"application/rss+xml",
|
|
804
|
+
"application/atom+xml",
|
|
805
|
+
"application/x-pkcs12",
|
|
806
|
+
"application/x-shockwave-flash",
|
|
807
|
+
"application/x-www-form-urlencoded",
|
|
808
|
+
"application/x-font-ttf",
|
|
809
|
+
"application/x-font-opentype",
|
|
810
|
+
"application/x-font-woff",
|
|
811
|
+
"application/x-font-woff2",
|
|
812
|
+
"application/vnd.rar",
|
|
813
|
+
"application/zip",
|
|
814
|
+
"application/x-7z-compressed"
|
|
815
|
+
];
|
|
816
|
+
|
|
743
817
|
// src/Images.ts
|
|
744
818
|
var IMAGE_FORMAT_LOOKUP = [
|
|
745
819
|
{ ext: "jpg", webFormat: true, other_ext: ["jpeg"] },
|
|
@@ -1091,13 +1165,51 @@ var IPv6 = {
|
|
|
1091
1165
|
var IPv4 = {
|
|
1092
1166
|
Loopback: "127.0.0.1"
|
|
1093
1167
|
};
|
|
1168
|
+
var NETWORK_PROTOCOL_INSECURE = [
|
|
1169
|
+
"http",
|
|
1170
|
+
"ftp",
|
|
1171
|
+
"ws",
|
|
1172
|
+
"dns",
|
|
1173
|
+
"telnet",
|
|
1174
|
+
"imap",
|
|
1175
|
+
"pop3",
|
|
1176
|
+
"smtp"
|
|
1177
|
+
];
|
|
1178
|
+
var NETWORK_PROTOCOL_SECURE = [
|
|
1179
|
+
"https",
|
|
1180
|
+
"sftp",
|
|
1181
|
+
"wss",
|
|
1182
|
+
"sdns",
|
|
1183
|
+
"ssh"
|
|
1184
|
+
];
|
|
1185
|
+
var NETWORK_PROTOCOL = [
|
|
1186
|
+
...NETWORK_PROTOCOL_INSECURE,
|
|
1187
|
+
...NETWORK_PROTOCOL_SECURE
|
|
1188
|
+
];
|
|
1094
1189
|
var NETWORK_PROTOCOL_LOOKUP = {
|
|
1095
1190
|
http: ["http", "https"],
|
|
1096
1191
|
ftp: ["ftp", "sftp"],
|
|
1097
1192
|
file: ["", "file"],
|
|
1098
1193
|
ws: ["ws", "wss"],
|
|
1099
1194
|
ssh: ["", "ssh"],
|
|
1100
|
-
scp: ["", "scp"]
|
|
1195
|
+
scp: ["", "scp"],
|
|
1196
|
+
telnet: ["telnet", ""],
|
|
1197
|
+
dns: ["dns", "sdns"]
|
|
1198
|
+
};
|
|
1199
|
+
var PROTOCOL_DEFAULT_PORTS = {
|
|
1200
|
+
http: 80,
|
|
1201
|
+
https: 443,
|
|
1202
|
+
ws: 80,
|
|
1203
|
+
wss: 443,
|
|
1204
|
+
ssh: 22,
|
|
1205
|
+
telnet: 23,
|
|
1206
|
+
dns: 53,
|
|
1207
|
+
sdns: 853,
|
|
1208
|
+
smtp: 25,
|
|
1209
|
+
imap: 142,
|
|
1210
|
+
pop3: 110,
|
|
1211
|
+
ftp: 21,
|
|
1212
|
+
sftp: 22
|
|
1101
1213
|
};
|
|
1102
1214
|
var TOP_LEVEL_DOMAINS = [
|
|
1103
1215
|
"com",
|
|
@@ -2844,10 +2956,14 @@ var TYPE_TRANSFORMS = {
|
|
|
2844
2956
|
MARKED,
|
|
2845
2957
|
MASS_METRICS_LOOKUP,
|
|
2846
2958
|
MEXICAN_NEWS,
|
|
2959
|
+
MIME_TYPES,
|
|
2847
2960
|
MONTH_ABBR,
|
|
2848
2961
|
MONTH_NAME,
|
|
2849
2962
|
NARROW_CONTAINER_TYPE_KINDS,
|
|
2963
|
+
NETWORK_PROTOCOL,
|
|
2964
|
+
NETWORK_PROTOCOL_INSECURE,
|
|
2850
2965
|
NETWORK_PROTOCOL_LOOKUP,
|
|
2966
|
+
NETWORK_PROTOCOL_SECURE,
|
|
2851
2967
|
NIKE_DNS,
|
|
2852
2968
|
NON_ZERO_NUMERIC_CHAR,
|
|
2853
2969
|
NORWEGIAN_NEWS,
|
|
@@ -2864,6 +2980,7 @@ var TYPE_TRANSFORMS = {
|
|
|
2864
2980
|
PLURAL_EXCEPTIONS_OLD,
|
|
2865
2981
|
POWER_METRICS_LOOKUP,
|
|
2866
2982
|
PRESSURE_METRICS_LOOKUP,
|
|
2983
|
+
PROTOCOL_DEFAULT_PORTS,
|
|
2867
2984
|
PROXMOX_CT_STATE,
|
|
2868
2985
|
REPO_PAGE_TYPES,
|
|
2869
2986
|
REPO_SOURCES,
|