@webdeveric/utils 0.18.0 → 0.20.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.
Files changed (50) hide show
  1. package/dist/cjs/type-assertion.js +185 -10
  2. package/dist/cjs/type-assertion.js.map +1 -1
  3. package/dist/cjs/type-predicate-factory.js +19 -0
  4. package/dist/cjs/type-predicate-factory.js.map +1 -0
  5. package/dist/cjs/type-predicate.js +53 -20
  6. package/dist/cjs/type-predicate.js.map +1 -1
  7. package/dist/mjs/type-assertion.js +155 -9
  8. package/dist/mjs/type-assertion.js.map +1 -1
  9. package/dist/mjs/type-predicate-factory.js +11 -0
  10. package/dist/mjs/type-predicate-factory.js.map +1 -0
  11. package/dist/mjs/type-predicate.js +38 -14
  12. package/dist/mjs/type-predicate.js.map +1 -1
  13. package/dist/types/type-assertion.d.ts +35 -4
  14. package/dist/types/type-assertion.d.ts.map +1 -1
  15. package/dist/types/type-predicate-factory.d.ts +7 -0
  16. package/dist/types/type-predicate-factory.d.ts.map +1 -0
  17. package/dist/types/type-predicate.d.ts +21 -6
  18. package/dist/types/type-predicate.d.ts.map +1 -1
  19. package/dist/types/types.d.ts +2 -0
  20. package/dist/types/types.d.ts.map +1 -1
  21. package/package.json +23 -22
  22. package/src/asArray.ts +0 -3
  23. package/src/capitalize.ts +0 -1
  24. package/src/clamp.ts +0 -7
  25. package/src/compose.ts +0 -13
  26. package/src/convert.ts +0 -30
  27. package/src/delay.ts +0 -23
  28. package/src/delayAnimationFrame.ts +0 -35
  29. package/src/getMaxValue.ts +0 -16
  30. package/src/getMinValue.ts +0 -16
  31. package/src/getOwnKeys.ts +0 -3
  32. package/src/getOwnProperties.ts +0 -3
  33. package/src/getType.ts +0 -3
  34. package/src/index.ts +0 -24
  35. package/src/isEmpty.ts +0 -21
  36. package/src/isObject.ts +0 -3
  37. package/src/joinStrings.ts +0 -6
  38. package/src/node/fcrdns.ts +0 -37
  39. package/src/node/index.ts +0 -1
  40. package/src/normalize.ts +0 -102
  41. package/src/secToString.ts +0 -45
  42. package/src/toPascalCase.ts +0 -29
  43. package/src/trimEnd.ts +0 -5
  44. package/src/trimIndentation.ts +0 -18
  45. package/src/trimStart.ts +0 -5
  46. package/src/type-assertion.ts +0 -20
  47. package/src/type-predicate.ts +0 -48
  48. package/src/types.ts +0 -42
  49. package/src/uniqueItems.ts +0 -3
  50. package/src/until.ts +0 -130
@@ -1,23 +1,198 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertIsNumericValueArray = exports.assertIsFiniteNumber = exports.assertIsInteger = void 0;
3
+ exports.assertExhaustive = exports.assertIsUndefined = exports.assertIsSymbol = exports.assertIsStringWithLength = exports.assertIsStringRecord = exports.assertIsStringMatching = exports.assertIsString = exports.assertIsPropertyKey = exports.assertIsPromiseRejectedResult = exports.assertIsPromiseFulfilledResult = exports.assertIsPrimitive = exports.assertIsPositiveInteger = exports.assertIsNumberGTEOne = exports.assertIsPositiveFiniteNumber = exports.assertIsOptionalSymbol = exports.assertIsOptionalString = exports.assertIsOptionalNumber = exports.assertIsOptionalNull = exports.assertIsOptionalBoolean = exports.assertIsOptionalBigInt = exports.assertIsObject = exports.assertIsNumericValueArray = exports.assertIsNumericValue = exports.assertIsNumericString = exports.assertIsNumber = exports.assertIsNull = exports.assertIsLengthAware = exports.assertIsIntString = exports.assertIsInteger = exports.assertIsFiniteNumber = exports.assertIsBoolean = exports.assertIsBigInt = void 0;
4
4
  const type_predicate_js_1 = require("./type-predicate.js");
5
- function assertIsInteger(input) {
6
- if (!Number.isInteger(input)) {
7
- throw new TypeError('input is not an integer');
5
+ function getError(error) {
6
+ return error instanceof Error ? error : new TypeError(error);
7
+ }
8
+ function assertIsBigInt(input, error = 'input is not a bigint') {
9
+ if (!(0, type_predicate_js_1.isBigInt)(input)) {
10
+ throw getError(error);
8
11
  }
9
12
  }
10
- exports.assertIsInteger = assertIsInteger;
11
- function assertIsFiniteNumber(input) {
12
- if (!Number.isFinite(input)) {
13
- throw new TypeError('input is not a finite number');
13
+ exports.assertIsBigInt = assertIsBigInt;
14
+ function assertIsBoolean(input, error = 'input is not a boolean') {
15
+ if (!(0, type_predicate_js_1.isBoolean)(input)) {
16
+ throw getError(error);
17
+ }
18
+ }
19
+ exports.assertIsBoolean = assertIsBoolean;
20
+ function assertIsFiniteNumber(input, error = 'input is not a finite number') {
21
+ if (!(0, type_predicate_js_1.isFiniteNumber)(input)) {
22
+ throw getError(error);
14
23
  }
15
24
  }
16
25
  exports.assertIsFiniteNumber = assertIsFiniteNumber;
17
- function assertIsNumericValueArray(input) {
26
+ function assertIsInteger(input, error = 'input is not an integer') {
27
+ if (!(0, type_predicate_js_1.isInteger)(input)) {
28
+ throw getError(error);
29
+ }
30
+ }
31
+ exports.assertIsInteger = assertIsInteger;
32
+ function assertIsIntString(input, error = 'input is not an integer string') {
33
+ if (!(0, type_predicate_js_1.isIntString)(input)) {
34
+ throw getError(error);
35
+ }
36
+ }
37
+ exports.assertIsIntString = assertIsIntString;
38
+ function assertIsLengthAware(input, error = 'input is not length aware') {
39
+ if (!(0, type_predicate_js_1.isLengthAware)(input)) {
40
+ throw getError(error);
41
+ }
42
+ }
43
+ exports.assertIsLengthAware = assertIsLengthAware;
44
+ function assertIsNull(input, error = 'input is not null') {
45
+ if (!(0, type_predicate_js_1.isNull)(input)) {
46
+ throw getError(error);
47
+ }
48
+ }
49
+ exports.assertIsNull = assertIsNull;
50
+ function assertIsNumber(input, error = 'input is not a number') {
51
+ if (!(0, type_predicate_js_1.isNumber)(input)) {
52
+ throw getError(error);
53
+ }
54
+ }
55
+ exports.assertIsNumber = assertIsNumber;
56
+ function assertIsNumericString(input, error = 'input is not a numeric string') {
57
+ if (!(0, type_predicate_js_1.isNumericString)(input)) {
58
+ throw getError(error);
59
+ }
60
+ }
61
+ exports.assertIsNumericString = assertIsNumericString;
62
+ function assertIsNumericValue(input, error = 'input is not a numerical value') {
63
+ if (!(0, type_predicate_js_1.isNumericValue)(input)) {
64
+ throw getError(error);
65
+ }
66
+ }
67
+ exports.assertIsNumericValue = assertIsNumericValue;
68
+ function assertIsNumericValueArray(input, error = 'input is not a numerical value array') {
18
69
  if (!(0, type_predicate_js_1.isNumericValueArray)(input)) {
19
- throw new TypeError('all items must be a NumericValue');
70
+ throw getError(error);
20
71
  }
21
72
  }
22
73
  exports.assertIsNumericValueArray = assertIsNumericValueArray;
74
+ function assertIsObject(input, error = 'input is not an object') {
75
+ if (!(0, type_predicate_js_1.isObject)(input)) {
76
+ throw getError(error);
77
+ }
78
+ }
79
+ exports.assertIsObject = assertIsObject;
80
+ function assertIsOptionalBigInt(input, error = 'input is not an optional bigint') {
81
+ if (!(0, type_predicate_js_1.isOptionalBigInt)(input)) {
82
+ throw getError(error);
83
+ }
84
+ }
85
+ exports.assertIsOptionalBigInt = assertIsOptionalBigInt;
86
+ function assertIsOptionalBoolean(input, error = 'input is not an optional boolean') {
87
+ if (!(0, type_predicate_js_1.isOptionalBoolean)(input)) {
88
+ throw getError(error);
89
+ }
90
+ }
91
+ exports.assertIsOptionalBoolean = assertIsOptionalBoolean;
92
+ function assertIsOptionalNull(input, error = 'input is not an optional null') {
93
+ if (!(0, type_predicate_js_1.isOptionalNull)(input)) {
94
+ throw getError(error);
95
+ }
96
+ }
97
+ exports.assertIsOptionalNull = assertIsOptionalNull;
98
+ function assertIsOptionalNumber(input, error = 'input is not an optional number') {
99
+ if (!(0, type_predicate_js_1.isOptionalNumber)(input)) {
100
+ throw getError(error);
101
+ }
102
+ }
103
+ exports.assertIsOptionalNumber = assertIsOptionalNumber;
104
+ function assertIsOptionalString(input, error = 'input is not an optional string') {
105
+ if (!(0, type_predicate_js_1.isOptionalString)(input)) {
106
+ throw getError(error);
107
+ }
108
+ }
109
+ exports.assertIsOptionalString = assertIsOptionalString;
110
+ function assertIsOptionalSymbol(input, error = 'input is not an optional symbol') {
111
+ if (!(0, type_predicate_js_1.isOptionalSymbol)(input)) {
112
+ throw getError(error);
113
+ }
114
+ }
115
+ exports.assertIsOptionalSymbol = assertIsOptionalSymbol;
116
+ function assertIsPositiveFiniteNumber(input, error = 'input is not a positive finite number') {
117
+ if (!(0, type_predicate_js_1.isPositiveFiniteNumber)(input)) {
118
+ throw getError(error);
119
+ }
120
+ }
121
+ exports.assertIsPositiveFiniteNumber = assertIsPositiveFiniteNumber;
122
+ function assertIsNumberGTEOne(input, error = 'input is not a number >= 1') {
123
+ if (!(0, type_predicate_js_1.isPositiveFiniteNumber)(input) || input < 1) {
124
+ throw getError(error);
125
+ }
126
+ }
127
+ exports.assertIsNumberGTEOne = assertIsNumberGTEOne;
128
+ function assertIsPositiveInteger(input, error = 'input is not a positive integer') {
129
+ if (!(0, type_predicate_js_1.isPositiveInteger)(input)) {
130
+ throw getError(error);
131
+ }
132
+ }
133
+ exports.assertIsPositiveInteger = assertIsPositiveInteger;
134
+ function assertIsPrimitive(input, error = 'input is not primitive') {
135
+ if (!(0, type_predicate_js_1.isPrimitive)(input)) {
136
+ throw getError(error);
137
+ }
138
+ }
139
+ exports.assertIsPrimitive = assertIsPrimitive;
140
+ function assertIsPromiseFulfilledResult(input, error = 'input is not a promise fulfilled result') {
141
+ if (!(0, type_predicate_js_1.isPromiseFulfilledResult)(input)) {
142
+ throw getError(error);
143
+ }
144
+ }
145
+ exports.assertIsPromiseFulfilledResult = assertIsPromiseFulfilledResult;
146
+ function assertIsPromiseRejectedResult(input, error = 'input is not a promise rejected result') {
147
+ if (!(0, type_predicate_js_1.isPromiseRejectedResult)(input)) {
148
+ throw getError(error);
149
+ }
150
+ }
151
+ exports.assertIsPromiseRejectedResult = assertIsPromiseRejectedResult;
152
+ function assertIsPropertyKey(input, error = 'input is not a property key') {
153
+ if (!(0, type_predicate_js_1.isPropertyKey)(input)) {
154
+ throw getError(error);
155
+ }
156
+ }
157
+ exports.assertIsPropertyKey = assertIsPropertyKey;
158
+ function assertIsString(input, error = 'input is not a string') {
159
+ if (!(0, type_predicate_js_1.isString)(input)) {
160
+ throw getError(error);
161
+ }
162
+ }
163
+ exports.assertIsString = assertIsString;
164
+ function assertIsStringMatching(input, pattern, error = 'input is not a string that matches the pattern') {
165
+ if (!(0, type_predicate_js_1.isStringMatching)(input, pattern)) {
166
+ throw getError(error);
167
+ }
168
+ }
169
+ exports.assertIsStringMatching = assertIsStringMatching;
170
+ function assertIsStringRecord(input, error = 'input is not a string record') {
171
+ if (!(0, type_predicate_js_1.isStringRecord)(input)) {
172
+ throw getError(error);
173
+ }
174
+ }
175
+ exports.assertIsStringRecord = assertIsStringRecord;
176
+ function assertIsStringWithLength(input, error = 'input is not a string with length') {
177
+ if (!(0, type_predicate_js_1.isStringWithLength)(input)) {
178
+ throw getError(error);
179
+ }
180
+ }
181
+ exports.assertIsStringWithLength = assertIsStringWithLength;
182
+ function assertIsSymbol(input, error = 'input is not a symbol') {
183
+ if (!(0, type_predicate_js_1.isSymbol)(input)) {
184
+ throw getError(error);
185
+ }
186
+ }
187
+ exports.assertIsSymbol = assertIsSymbol;
188
+ function assertIsUndefined(input, error = 'input is not undefined') {
189
+ if (!(0, type_predicate_js_1.isUndefined)(input)) {
190
+ throw getError(error);
191
+ }
192
+ }
193
+ exports.assertIsUndefined = assertIsUndefined;
194
+ function assertExhaustive(_, error = 'Failed exhaustive check') {
195
+ throw getError(error);
196
+ }
197
+ exports.assertExhaustive = assertExhaustive;
23
198
  //# sourceMappingURL=type-assertion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":";;;AAAA,2DAA0D;AAG1D,SAAgB,eAAe,CAAC,KAAc;IAC5C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAC5B,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;KAChD;AACH,CAAC;AAJD,0CAIC;AAED,SAAgB,oBAAoB,CAAC,KAAc;IACjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KA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AW,EAAC,KAAK,CAAC,EAAE;QACvB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAPD,8CAOC;AAED,SAAgB,gBAAgB,CAAC,CAAQ,EAAE,QAAwB,yBAAyB;IAC1F,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAFD,4CAEC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maybeUndefined = exports.maybeNull = exports.maybeArray = exports.everyItem = exports.createIsEnumPredicate = void 0;
4
+ const createIsEnumPredicate = (enumObject) => {
5
+ const values = Object.values(enumObject);
6
+ return (input) => {
7
+ return values.includes(input);
8
+ };
9
+ };
10
+ exports.createIsEnumPredicate = createIsEnumPredicate;
11
+ const everyItem = (predicate) => (input) => Array.isArray(input) && input.every(predicate);
12
+ exports.everyItem = everyItem;
13
+ const maybeArray = (predicate) => (input) => Array.isArray(input) ? input.every(predicate) : predicate(input);
14
+ exports.maybeArray = maybeArray;
15
+ const maybeNull = (predicate) => (input) => input === null || predicate(input);
16
+ exports.maybeNull = maybeNull;
17
+ const maybeUndefined = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
18
+ exports.maybeUndefined = maybeUndefined;
19
+ //# sourceMappingURL=type-predicate-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-predicate-factory.js","sourceRoot":"","sources":["../../src/type-predicate-factory.ts"],"names":[],"mappings":";;;AAEO,MAAM,qBAAqB,GAAG,CAA0B,UAAa,EAA+B,EAAE;IAC3G,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAEzC,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC,CAAC;AANW,QAAA,qBAAqB,yBAMhC;AAEK,MAAM,SAAS,GACpB,CAAI,SAA6B,EAAwB,EAAE,CAC3D,CAAC,KAAc,EAAgB,EAAE,CAC/B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAHtC,QAAA,SAAS,aAG6B;AAE5C,MAAM,UAAU,GACrB,CAAI,SAA6B,EAA4B,EAAE,CAC/D,CAAC,KAAc,EAAoB,EAAE,CACnC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAHxD,QAAA,UAAU,cAG8C;AAE9D,MAAM,SAAS,GACpB,CAAI,SAA6B,EAA6B,EAAE,CAChE,CAAC,KAAc,EAAqB,EAAE,CACpC,KAAK,KAAK,IAAI,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAH1B,QAAA,SAAS,aAGiB;AAEhC,MAAM,cAAc,GACzB,CAAI,SAA6B,EAAkC,EAAE,CACrE,CAAC,KAAc,EAA0B,EAAE,CACzC,OAAO,KAAK,KAAK,WAAW,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAHxC,QAAA,cAAc,kBAG0B"}
@@ -1,14 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isObject = exports.isPrimitive = exports.isLengthAware = exports.isPositiveFiniteNumber = exports.isPositiveInteger = exports.isInteger = exports.isFiniteNumber = exports.isIntString = exports.isNumericValueArray = exports.isNumericValue = exports.isNumericString = exports.isPropertyKey = exports.isStringMatching = exports.isOptionalNumber = exports.isOptionalString = void 0;
4
- const isOptionalString = (input) => typeof input === 'string' || typeof input === 'undefined';
5
- exports.isOptionalString = isOptionalString;
6
- const isOptionalNumber = (input) => (typeof input === 'number' && !Number.isNaN(input)) || typeof input === 'undefined';
7
- exports.isOptionalNumber = isOptionalNumber;
3
+ exports.isPromiseRejectedResult = exports.isPromiseFulfilledResult = exports.isStringRecord = exports.isLengthAware = exports.isObject = exports.isPropertyKey = exports.isPositiveFiniteNumber = exports.isPositiveInteger = exports.isInteger = exports.isFiniteNumber = exports.isIntString = exports.isNumericValueArray = exports.isNumericValue = exports.isNumericString = exports.isStringMatching = exports.isStringWithLength = exports.isOptionalNull = exports.isOptionalSymbol = exports.isOptionalBoolean = exports.isOptionalBigInt = exports.isOptionalNumber = exports.isOptionalString = exports.isPrimitive = exports.isNull = exports.isSymbol = exports.isUndefined = exports.isBoolean = exports.isBigInt = exports.isNumber = exports.isString = void 0;
4
+ const type_predicate_factory_js_1 = require("./type-predicate-factory.js");
5
+ // Primitives
6
+ const isString = (input) => typeof input === 'string';
7
+ exports.isString = isString;
8
+ const isNumber = (input) => typeof input === 'number' && !Number.isNaN(input);
9
+ exports.isNumber = isNumber;
10
+ const isBigInt = (input) => typeof input === 'bigint';
11
+ exports.isBigInt = isBigInt;
12
+ const isBoolean = (input) => typeof input === 'boolean';
13
+ exports.isBoolean = isBoolean;
14
+ const isUndefined = (input) => typeof input === 'undefined';
15
+ exports.isUndefined = isUndefined;
16
+ const isSymbol = (input) => typeof input === 'symbol';
17
+ exports.isSymbol = isSymbol;
18
+ const isNull = (input) => input === null;
19
+ exports.isNull = isNull;
20
+ const isPrimitive = (input) => (0, exports.isString)(input) ||
21
+ (0, exports.isNumber)(input) ||
22
+ (0, exports.isBigInt)(input) ||
23
+ (0, exports.isBoolean)(input) ||
24
+ (0, exports.isUndefined)(input) ||
25
+ (0, exports.isSymbol)(input) ||
26
+ (0, exports.isNull)(input);
27
+ exports.isPrimitive = isPrimitive;
28
+ // Optional primitives
29
+ exports.isOptionalString = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isString);
30
+ exports.isOptionalNumber = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isNumber);
31
+ exports.isOptionalBigInt = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isBigInt);
32
+ exports.isOptionalBoolean = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isBoolean);
33
+ exports.isOptionalSymbol = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isSymbol);
34
+ exports.isOptionalNull = (0, type_predicate_factory_js_1.maybeUndefined)(exports.isNull);
35
+ // Primitives with extra checks
36
+ const isStringWithLength = (input) => typeof input === 'string' && input.length > 0;
37
+ exports.isStringWithLength = isStringWithLength;
8
38
  const isStringMatching = (input, pattern) => typeof input === 'string' && pattern.test(input);
9
39
  exports.isStringMatching = isStringMatching;
10
- const isPropertyKey = (input) => typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
11
- exports.isPropertyKey = isPropertyKey;
12
40
  const isNumericString = (input) => (0, exports.isStringMatching)(input, /^[-+]?\d+(\.\d+)?$/);
13
41
  exports.isNumericString = isNumericString;
14
42
  const isNumericValue = (input) => typeof input === 'number' || typeof input === 'bigint' || (0, exports.isNumericString)(input);
@@ -17,7 +45,7 @@ const isNumericValueArray = (input) => Array.isArray(input) && input.every(expor
17
45
  exports.isNumericValueArray = isNumericValueArray;
18
46
  const isIntString = (input) => (0, exports.isStringMatching)(input, /^[-+]?\d+$/);
19
47
  exports.isIntString = isIntString;
20
- const isFiniteNumber = (input) => typeof input === 'number' && Number.isFinite(input);
48
+ const isFiniteNumber = (input) => Number.isFinite(input);
21
49
  exports.isFiniteNumber = isFiniteNumber;
22
50
  const isInteger = (input) => Number.isInteger(input);
23
51
  exports.isInteger = isInteger;
@@ -25,18 +53,23 @@ const isPositiveInteger = (input) => (0, exports.isInteger)(input) && input >= 0
25
53
  exports.isPositiveInteger = isPositiveInteger;
26
54
  const isPositiveFiniteNumber = (input) => (0, exports.isFiniteNumber)(input) && input >= 0;
27
55
  exports.isPositiveFiniteNumber = isPositiveFiniteNumber;
28
- const isLengthAware = (input) =>
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- typeof input === 'object' && input !== null && 'length' in input && typeof input.length === 'number';
31
- exports.isLengthAware = isLengthAware;
32
- const isPrimitive = (input) => typeof input === 'string' ||
33
- typeof input === 'number' ||
34
- typeof input === 'bigint' ||
35
- typeof input === 'boolean' ||
36
- typeof input === 'undefined' ||
37
- typeof input === 'symbol' ||
38
- input === null;
39
- exports.isPrimitive = isPrimitive;
56
+ // Common types
57
+ const isPropertyKey = (input) => typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
58
+ exports.isPropertyKey = isPropertyKey;
40
59
  const isObject = (input) => input !== null && typeof input === 'object' && !Array.isArray(input);
41
60
  exports.isObject = isObject;
61
+ const isLengthAware = (input) => input !== null && typeof input === 'object' && 'length' in input && typeof input.length === 'number';
62
+ exports.isLengthAware = isLengthAware;
63
+ const isStringRecord = (input) => {
64
+ return (0, exports.isObject)(input) && Object.entries(input).every(entry => entry.every(exports.isString));
65
+ };
66
+ exports.isStringRecord = isStringRecord;
67
+ const isPromiseFulfilledResult = (input) => {
68
+ return (0, exports.isObject)(input) && input.status === 'fulfilled';
69
+ };
70
+ exports.isPromiseFulfilledResult = isPromiseFulfilledResult;
71
+ const isPromiseRejectedResult = (input) => {
72
+ return (0, exports.isObject)(input) && input.status === 'rejected' && 'reason' in input;
73
+ };
74
+ exports.isPromiseRejectedResult = isPromiseRejectedResult;
42
75
  //# sourceMappingURL=type-predicate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-predicate.js","sourceRoot":"","sources":["../../src/type-predicate.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAA+B,EAAE,CAC9E,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,WAAW,CAAC;AAD/C,QAAA,gBAAgB,oBAC+B;AAErD,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAA+B,EAAE,CAC9E,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,OAAO,KAAK,KAAK,WAAW,CAAC;AADzE,QAAA,gBAAgB,oBACyD;AAE/E,M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I,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,gBAAQ,CAAC,CAAC,CAAC;AACxF,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEK,MAAM,wBAAwB,GAAG,CAAI,KAAc,EAAsC,EAAE;IAChG,OAAO,IAAA,gBAAQ,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC;AACzD,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC;AAEK,MAAM,uBAAuB,GAAG,CAAC,KAAc,EAAkC,EAAE;IACxF,OAAO,IAAA,gBAAQ,EAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,QAAQ,IAAI,KAAK,CAAC;AAC7E,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC"}
@@ -1,17 +1,163 @@
1
- import { isNumericValueArray } from './type-predicate.js';
2
- export function assertIsInteger(input) {
3
- if (!Number.isInteger(input)) {
4
- throw new TypeError('input is not an integer');
1
+ import { isBigInt, isBoolean, isFiniteNumber, isInteger, isIntString, isLengthAware, isNull, isNumber, isNumericString, isNumericValue, isNumericValueArray, isObject, isOptionalBigInt, isOptionalBoolean, isOptionalNull, isOptionalNumber, isOptionalString, isOptionalSymbol, isPositiveFiniteNumber, isPositiveInteger, isPrimitive, isPromiseFulfilledResult, isPromiseRejectedResult, isPropertyKey, isString, isStringMatching, isStringRecord, isStringWithLength, isSymbol, isUndefined, } from './type-predicate.js';
2
+ function getError(error) {
3
+ return error instanceof Error ? error : new TypeError(error);
4
+ }
5
+ export function assertIsBigInt(input, error = 'input is not a bigint') {
6
+ if (!isBigInt(input)) {
7
+ throw getError(error);
8
+ }
9
+ }
10
+ export function assertIsBoolean(input, error = 'input is not a boolean') {
11
+ if (!isBoolean(input)) {
12
+ throw getError(error);
13
+ }
14
+ }
15
+ export function assertIsFiniteNumber(input, error = 'input is not a finite number') {
16
+ if (!isFiniteNumber(input)) {
17
+ throw getError(error);
18
+ }
19
+ }
20
+ export function assertIsInteger(input, error = 'input is not an integer') {
21
+ if (!isInteger(input)) {
22
+ throw getError(error);
23
+ }
24
+ }
25
+ export function assertIsIntString(input, error = 'input is not an integer string') {
26
+ if (!isIntString(input)) {
27
+ throw getError(error);
28
+ }
29
+ }
30
+ export function assertIsLengthAware(input, error = 'input is not length aware') {
31
+ if (!isLengthAware(input)) {
32
+ throw getError(error);
33
+ }
34
+ }
35
+ export function assertIsNull(input, error = 'input is not null') {
36
+ if (!isNull(input)) {
37
+ throw getError(error);
38
+ }
39
+ }
40
+ export function assertIsNumber(input, error = 'input is not a number') {
41
+ if (!isNumber(input)) {
42
+ throw getError(error);
5
43
  }
6
44
  }
7
- export function assertIsFiniteNumber(input) {
8
- if (!Number.isFinite(input)) {
9
- throw new TypeError('input is not a finite number');
45
+ export function assertIsNumericString(input, error = 'input is not a numeric string') {
46
+ if (!isNumericString(input)) {
47
+ throw getError(error);
10
48
  }
11
49
  }
12
- export function assertIsNumericValueArray(input) {
50
+ export function assertIsNumericValue(input, error = 'input is not a numerical value') {
51
+ if (!isNumericValue(input)) {
52
+ throw getError(error);
53
+ }
54
+ }
55
+ export function assertIsNumericValueArray(input, error = 'input is not a numerical value array') {
13
56
  if (!isNumericValueArray(input)) {
14
- throw new TypeError('all items must be a NumericValue');
57
+ throw getError(error);
58
+ }
59
+ }
60
+ export function assertIsObject(input, error = 'input is not an object') {
61
+ if (!isObject(input)) {
62
+ throw getError(error);
63
+ }
64
+ }
65
+ export function assertIsOptionalBigInt(input, error = 'input is not an optional bigint') {
66
+ if (!isOptionalBigInt(input)) {
67
+ throw getError(error);
68
+ }
69
+ }
70
+ export function assertIsOptionalBoolean(input, error = 'input is not an optional boolean') {
71
+ if (!isOptionalBoolean(input)) {
72
+ throw getError(error);
73
+ }
74
+ }
75
+ export function assertIsOptionalNull(input, error = 'input is not an optional null') {
76
+ if (!isOptionalNull(input)) {
77
+ throw getError(error);
78
+ }
79
+ }
80
+ export function assertIsOptionalNumber(input, error = 'input is not an optional number') {
81
+ if (!isOptionalNumber(input)) {
82
+ throw getError(error);
83
+ }
84
+ }
85
+ export function assertIsOptionalString(input, error = 'input is not an optional string') {
86
+ if (!isOptionalString(input)) {
87
+ throw getError(error);
15
88
  }
16
89
  }
90
+ export function assertIsOptionalSymbol(input, error = 'input is not an optional symbol') {
91
+ if (!isOptionalSymbol(input)) {
92
+ throw getError(error);
93
+ }
94
+ }
95
+ export function assertIsPositiveFiniteNumber(input, error = 'input is not a positive finite number') {
96
+ if (!isPositiveFiniteNumber(input)) {
97
+ throw getError(error);
98
+ }
99
+ }
100
+ export function assertIsNumberGTEOne(input, error = 'input is not a number >= 1') {
101
+ if (!isPositiveFiniteNumber(input) || input < 1) {
102
+ throw getError(error);
103
+ }
104
+ }
105
+ export function assertIsPositiveInteger(input, error = 'input is not a positive integer') {
106
+ if (!isPositiveInteger(input)) {
107
+ throw getError(error);
108
+ }
109
+ }
110
+ export function assertIsPrimitive(input, error = 'input is not primitive') {
111
+ if (!isPrimitive(input)) {
112
+ throw getError(error);
113
+ }
114
+ }
115
+ export function assertIsPromiseFulfilledResult(input, error = 'input is not a promise fulfilled result') {
116
+ if (!isPromiseFulfilledResult(input)) {
117
+ throw getError(error);
118
+ }
119
+ }
120
+ export function assertIsPromiseRejectedResult(input, error = 'input is not a promise rejected result') {
121
+ if (!isPromiseRejectedResult(input)) {
122
+ throw getError(error);
123
+ }
124
+ }
125
+ export function assertIsPropertyKey(input, error = 'input is not a property key') {
126
+ if (!isPropertyKey(input)) {
127
+ throw getError(error);
128
+ }
129
+ }
130
+ export function assertIsString(input, error = 'input is not a string') {
131
+ if (!isString(input)) {
132
+ throw getError(error);
133
+ }
134
+ }
135
+ export function assertIsStringMatching(input, pattern, error = 'input is not a string that matches the pattern') {
136
+ if (!isStringMatching(input, pattern)) {
137
+ throw getError(error);
138
+ }
139
+ }
140
+ export function assertIsStringRecord(input, error = 'input is not a string record') {
141
+ if (!isStringRecord(input)) {
142
+ throw getError(error);
143
+ }
144
+ }
145
+ export function assertIsStringWithLength(input, error = 'input is not a string with length') {
146
+ if (!isStringWithLength(input)) {
147
+ throw getError(error);
148
+ }
149
+ }
150
+ export function assertIsSymbol(input, error = 'input is not a symbol') {
151
+ if (!isSymbol(input)) {
152
+ throw getError(error);
153
+ }
154
+ }
155
+ export function assertIsUndefined(input, error = 'input is not undefined') {
156
+ if (!isUndefined(input)) {
157
+ throw getError(error);
158
+ }
159
+ }
160
+ export function assertExhaustive(_, error = 'Failed exhaustive check') {
161
+ throw getError(error);
162
+ }
17
163
  //# sourceMappingURL=type-assertion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;QAC5B,MAAM,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;KAChD;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC3B,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;KACrD;AACH,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,KAAc;IACtD,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE;QAC/B,MAAM,IAAI,SAAS,CAAC,kCAAkC,CAAC,CAAC;KACzD;AACH,CAAC"}
1
+ {"version":3,"file":"type-assertion.js","sourceRoot":"","sources":["../../src/type-assertion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,cAAc,EACd,SAAS,EACT,WAAW,EACX,aAAa,EACb,MAA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,EACd,OAAe,EACf,QAAwB,gDAAgD;IAExE,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE;QACrC,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,KAAc,EACd,QAAwB,8BAA8B;IAEtD,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;QAC1B,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,KAAc,EACd,QAAwB,mCAAmC;IAE3D,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;QAC9B,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,KAAc,EACd,QAAwB,uBAAuB;IAE/C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACpB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,KAAc,EACd,QAAwB,wBAAwB;IAEhD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE;QACvB,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;KACvB;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAQ,EAAE,QAAwB,yBAAyB;IAC1F,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
@@ -0,0 +1,11 @@
1
+ export const createIsEnumPredicate = (enumObject) => {
2
+ const values = Object.values(enumObject);
3
+ return (input) => {
4
+ return values.includes(input);
5
+ };
6
+ };
7
+ export const everyItem = (predicate) => (input) => Array.isArray(input) && input.every(predicate);
8
+ export const maybeArray = (predicate) => (input) => Array.isArray(input) ? input.every(predicate) : predicate(input);
9
+ export const maybeNull = (predicate) => (input) => input === null || predicate(input);
10
+ export const maybeUndefined = (predicate) => (input) => typeof input === 'undefined' || predicate(input);
11
+ //# sourceMappingURL=type-predicate-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-predicate-factory.js","sourceRoot":"","sources":["../../src/type-predicate-factory.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAA0B,UAAa,EAA+B,EAAE;IAC3G,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAEzC,OAAO,CAAC,KAAc,EAAuB,EAAE;QAC7C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GACpB,CAAI,SAA6B,EAAwB,EAAE,CAC3D,CAAC,KAAc,EAAgB,EAAE,CAC/B,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,UAAU,GACrB,CAAI,SAA6B,EAA4B,EAAE,CAC/D,CAAC,KAAc,EAAoB,EAAE,CACnC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,SAAS,GACpB,CAAI,SAA6B,EAA6B,EAAE,CAChE,CAAC,KAAc,EAAqB,EAAE,CACpC,KAAK,KAAK,IAAI,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,cAAc,GACzB,CAAI,SAA6B,EAAkC,EAAE,CACrE,CAAC,KAAc,EAA0B,EAAE,CACzC,OAAO,KAAK,KAAK,WAAW,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC"}
@@ -1,24 +1,48 @@
1
- export const isOptionalString = (input) => typeof input === 'string' || typeof input === 'undefined';
2
- export const isOptionalNumber = (input) => (typeof input === 'number' && !Number.isNaN(input)) || typeof input === 'undefined';
1
+ import { maybeUndefined } from './type-predicate-factory.js';
2
+ // Primitives
3
+ export const isString = (input) => typeof input === 'string';
4
+ export const isNumber = (input) => typeof input === 'number' && !Number.isNaN(input);
5
+ export const isBigInt = (input) => typeof input === 'bigint';
6
+ export const isBoolean = (input) => typeof input === 'boolean';
7
+ export const isUndefined = (input) => typeof input === 'undefined';
8
+ export const isSymbol = (input) => typeof input === 'symbol';
9
+ export const isNull = (input) => input === null;
10
+ export const isPrimitive = (input) => isString(input) ||
11
+ isNumber(input) ||
12
+ isBigInt(input) ||
13
+ isBoolean(input) ||
14
+ isUndefined(input) ||
15
+ isSymbol(input) ||
16
+ isNull(input);
17
+ // Optional primitives
18
+ export const isOptionalString = maybeUndefined(isString);
19
+ export const isOptionalNumber = maybeUndefined(isNumber);
20
+ export const isOptionalBigInt = maybeUndefined(isBigInt);
21
+ export const isOptionalBoolean = maybeUndefined(isBoolean);
22
+ export const isOptionalSymbol = maybeUndefined(isSymbol);
23
+ export const isOptionalNull = maybeUndefined(isNull);
24
+ // Primitives with extra checks
25
+ export const isStringWithLength = (input) => typeof input === 'string' && input.length > 0;
3
26
  export const isStringMatching = (input, pattern) => typeof input === 'string' && pattern.test(input);
4
- export const isPropertyKey = (input) => typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
5
27
  export const isNumericString = (input) => isStringMatching(input, /^[-+]?\d+(\.\d+)?$/);
6
28
  export const isNumericValue = (input) => typeof input === 'number' || typeof input === 'bigint' || isNumericString(input);
7
29
  export const isNumericValueArray = (input) => Array.isArray(input) && input.every(isNumericValue);
8
30
  export const isIntString = (input) => isStringMatching(input, /^[-+]?\d+$/);
9
- export const isFiniteNumber = (input) => typeof input === 'number' && Number.isFinite(input);
31
+ export const isFiniteNumber = (input) => Number.isFinite(input);
10
32
  export const isInteger = (input) => Number.isInteger(input);
11
33
  export const isPositiveInteger = (input) => isInteger(input) && input >= 0;
12
34
  export const isPositiveFiniteNumber = (input) => isFiniteNumber(input) && input >= 0;
13
- export const isLengthAware = (input) =>
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- typeof input === 'object' && input !== null && 'length' in input && typeof input.length === 'number';
16
- export const isPrimitive = (input) => typeof input === 'string' ||
17
- typeof input === 'number' ||
18
- typeof input === 'bigint' ||
19
- typeof input === 'boolean' ||
20
- typeof input === 'undefined' ||
21
- typeof input === 'symbol' ||
22
- input === null;
35
+ // Common types
36
+ export const isPropertyKey = (input) => typeof input === 'string' || typeof input === 'number' || typeof input === 'symbol';
23
37
  export const isObject = (input) => input !== null && typeof input === 'object' && !Array.isArray(input);
38
+ export const isLengthAware = (input) => input !== null && typeof input === 'object' && 'length' in input && typeof input.length === 'number';
39
+ export const isStringRecord = (input) => {
40
+ return isObject(input) && Object.entries(input).every(entry => entry.every(isString));
41
+ };
42
+ export const isPromiseFulfilledResult = (input) => {
43
+ return isObject(input) && input.status === 'fulfilled';
44
+ };
45
+ export const isPromiseRejectedResult = (input) => {
46
+ return isObject(input) && input.status === 'rejected' && 'reason' in input;
47
+ };
24
48
  //# sourceMappingURL=type-predicate.js.map