@salesforce/ts-types 2.0.9 → 2.0.11
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/LICENSE.txt +1 -1
- package/lib/errors.js +1 -0
- package/lib/experimental/index.js +3 -4
- package/lib/narrowing/as.js +11 -12
- package/lib/narrowing/assert.js +14 -15
- package/lib/narrowing/coerce.js +3 -4
- package/lib/narrowing/ensure.js +13 -14
- package/lib/narrowing/get.js +13 -14
- package/lib/narrowing/has.js +13 -14
- package/lib/narrowing/internal.js +1 -2
- package/lib/narrowing/is.js +15 -16
- package/lib/narrowing/object.js +6 -7
- package/lib/narrowing/to.js +3 -4
- package/lib/types/collection.d.ts +4 -6
- package/lib/types/json.d.ts +1 -2
- package/package.json +18 -31
package/LICENSE.txt
CHANGED
package/lib/errors.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.JsonCloneError = exports.UnexpectedValueTypeError = exports.AssertionFai
|
|
|
12
12
|
* For a complete `NamedError` solution, see [@salesforce/kit]{@link https://preview.npmjs.com/package/@salesforce/kit}.
|
|
13
13
|
*/
|
|
14
14
|
class NamedError extends Error {
|
|
15
|
+
name;
|
|
15
16
|
constructor(name, message) {
|
|
16
17
|
super(message);
|
|
17
18
|
this.name = name;
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.is = is;
|
|
10
|
+
exports.as = as;
|
|
11
|
+
exports.hasNull = hasNull;
|
|
10
12
|
/**
|
|
11
13
|
* A staging area for either introducing or removing type and functions, incrementally.
|
|
12
14
|
*/
|
|
@@ -25,7 +27,6 @@ function is(obj, shape) {
|
|
|
25
27
|
.every(({ key, type, optional }) => (optional && !(key in obj)) ||
|
|
26
28
|
((0, narrowing_1.isString)(type) ? typeof (0, narrowing_1.get)(obj, key) === type : (0, narrowing_1.get)(obj, key) instanceof type)));
|
|
27
29
|
}
|
|
28
|
-
exports.is = is;
|
|
29
30
|
/**
|
|
30
31
|
* @ignore
|
|
31
32
|
*/
|
|
@@ -36,12 +37,10 @@ exports.is = is;
|
|
|
36
37
|
function as(obj, shape) {
|
|
37
38
|
return is(obj, shape) ? obj : undefined;
|
|
38
39
|
}
|
|
39
|
-
exports.as = as;
|
|
40
40
|
/**
|
|
41
41
|
* @ignore
|
|
42
42
|
*/
|
|
43
43
|
function hasNull(value, key) {
|
|
44
44
|
return (0, narrowing_1.has)(value, key) && value[key] == null;
|
|
45
45
|
}
|
|
46
|
-
exports.hasNull = hasNull;
|
|
47
46
|
//# sourceMappingURL=index.js.map
|
package/lib/narrowing/as.js
CHANGED
|
@@ -6,61 +6,60 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.asString = asString;
|
|
10
|
+
exports.asNumber = asNumber;
|
|
11
|
+
exports.asBoolean = asBoolean;
|
|
12
|
+
exports.asObject = asObject;
|
|
13
|
+
exports.asPlainObject = asPlainObject;
|
|
14
|
+
exports.asDictionary = asDictionary;
|
|
15
|
+
exports.asInstance = asInstance;
|
|
16
|
+
exports.asArray = asArray;
|
|
17
|
+
exports.asFunction = asFunction;
|
|
18
|
+
exports.asJsonMap = asJsonMap;
|
|
19
|
+
exports.asJsonArray = asJsonArray;
|
|
10
20
|
const is_1 = require("./is");
|
|
11
21
|
// underlying function
|
|
12
22
|
function asString(value, defaultValue) {
|
|
13
23
|
return (0, is_1.isString)(value) ? value : defaultValue;
|
|
14
24
|
}
|
|
15
|
-
exports.asString = asString;
|
|
16
25
|
// underlying function
|
|
17
26
|
function asNumber(value, defaultValue) {
|
|
18
27
|
return (0, is_1.isNumber)(value) ? value : defaultValue;
|
|
19
28
|
}
|
|
20
|
-
exports.asNumber = asNumber;
|
|
21
29
|
// underlying function
|
|
22
30
|
function asBoolean(value, defaultValue) {
|
|
23
31
|
return (0, is_1.isBoolean)(value) ? value : defaultValue;
|
|
24
32
|
}
|
|
25
|
-
exports.asBoolean = asBoolean;
|
|
26
33
|
// underlying function
|
|
27
34
|
function asObject(value, defaultValue) {
|
|
28
35
|
return (0, is_1.isObject)(value) ? value : defaultValue;
|
|
29
36
|
}
|
|
30
|
-
exports.asObject = asObject;
|
|
31
37
|
// underlying function
|
|
32
38
|
function asPlainObject(value, defaultValue) {
|
|
33
39
|
return (0, is_1.isPlainObject)(value) ? value : defaultValue;
|
|
34
40
|
}
|
|
35
|
-
exports.asPlainObject = asPlainObject;
|
|
36
41
|
// underlying function
|
|
37
42
|
function asDictionary(value, defaultValue) {
|
|
38
43
|
return (0, is_1.isDictionary)(value) ? value : defaultValue;
|
|
39
44
|
}
|
|
40
|
-
exports.asDictionary = asDictionary;
|
|
41
45
|
// underlying function
|
|
42
46
|
function asInstance(value, ctor, defaultValue) {
|
|
43
47
|
return (0, is_1.isInstance)(value, ctor) ? value : defaultValue;
|
|
44
48
|
}
|
|
45
|
-
exports.asInstance = asInstance;
|
|
46
49
|
// underlying function
|
|
47
50
|
function asArray(value, defaultValue) {
|
|
48
51
|
return (0, is_1.isArray)(value) ? value : defaultValue;
|
|
49
52
|
}
|
|
50
|
-
exports.asArray = asArray;
|
|
51
53
|
// underlying function
|
|
52
54
|
function asFunction(value, defaultValue) {
|
|
53
55
|
return (0, is_1.isFunction)(value) ? value : defaultValue;
|
|
54
56
|
}
|
|
55
|
-
exports.asFunction = asFunction;
|
|
56
57
|
// underlying function
|
|
57
58
|
function asJsonMap(value, defaultValue) {
|
|
58
59
|
return (0, is_1.isJsonMap)(value) ? value : defaultValue;
|
|
59
60
|
}
|
|
60
|
-
exports.asJsonMap = asJsonMap;
|
|
61
61
|
// underlying function
|
|
62
62
|
function asJsonArray(value, defaultValue) {
|
|
63
63
|
return (0, is_1.isJsonArray)(value) ? value : defaultValue;
|
|
64
64
|
}
|
|
65
|
-
exports.asJsonArray = asJsonArray;
|
|
66
65
|
//# sourceMappingURL=as.js.map
|
package/lib/narrowing/assert.js
CHANGED
|
@@ -6,7 +6,20 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.assert = assert;
|
|
10
|
+
exports.assertNonNull = assertNonNull;
|
|
11
|
+
exports.assertString = assertString;
|
|
12
|
+
exports.assertNumber = assertNumber;
|
|
13
|
+
exports.assertBoolean = assertBoolean;
|
|
14
|
+
exports.assertObject = assertObject;
|
|
15
|
+
exports.assertPlainObject = assertPlainObject;
|
|
16
|
+
exports.assertDictionary = assertDictionary;
|
|
17
|
+
exports.assertInstance = assertInstance;
|
|
18
|
+
exports.assertArray = assertArray;
|
|
19
|
+
exports.assertFunction = assertFunction;
|
|
20
|
+
exports.assertAnyJson = assertAnyJson;
|
|
21
|
+
exports.assertJsonMap = assertJsonMap;
|
|
22
|
+
exports.assertJsonArray = assertJsonArray;
|
|
10
23
|
const errors_1 = require("../errors");
|
|
11
24
|
const as_1 = require("./as");
|
|
12
25
|
const to_1 = require("./to");
|
|
@@ -22,7 +35,6 @@ function assert(condition, message) {
|
|
|
22
35
|
throw new errors_1.AssertionFailedError(message ?? 'Assertion condition was false');
|
|
23
36
|
}
|
|
24
37
|
}
|
|
25
|
-
exports.assert = assert;
|
|
26
38
|
/**
|
|
27
39
|
* Narrows a type `Nullable<T>` to a `T` or raises an error.
|
|
28
40
|
*
|
|
@@ -41,7 +53,6 @@ exports.assert = assert;
|
|
|
41
53
|
function assertNonNull(value, message) {
|
|
42
54
|
assert(value != null, message ?? 'Value is not defined');
|
|
43
55
|
}
|
|
44
|
-
exports.assertNonNull = assertNonNull;
|
|
45
56
|
/**
|
|
46
57
|
* Narrows an `unknown` value to a `string` if it is type-compatible, or raises an error otherwise.
|
|
47
58
|
*
|
|
@@ -52,7 +63,6 @@ exports.assertNonNull = assertNonNull;
|
|
|
52
63
|
function assertString(value, message) {
|
|
53
64
|
assertNonNull((0, as_1.asString)(value), message ?? 'Value is not a string');
|
|
54
65
|
}
|
|
55
|
-
exports.assertString = assertString;
|
|
56
66
|
/**
|
|
57
67
|
* Narrows an `unknown` value to a `number` if it is type-compatible, or raises an error otherwise.
|
|
58
68
|
*
|
|
@@ -63,7 +73,6 @@ exports.assertString = assertString;
|
|
|
63
73
|
function assertNumber(value, message) {
|
|
64
74
|
assertNonNull((0, as_1.asNumber)(value), message ?? 'Value is not a number');
|
|
65
75
|
}
|
|
66
|
-
exports.assertNumber = assertNumber;
|
|
67
76
|
/**
|
|
68
77
|
* Narrows an `unknown` value to a `boolean` if it is type-compatible, or raises an error otherwise.
|
|
69
78
|
*
|
|
@@ -74,7 +83,6 @@ exports.assertNumber = assertNumber;
|
|
|
74
83
|
function assertBoolean(value, message) {
|
|
75
84
|
assertNonNull((0, as_1.asBoolean)(value), message ?? 'Value is not a boolean');
|
|
76
85
|
}
|
|
77
|
-
exports.assertBoolean = assertBoolean;
|
|
78
86
|
/**
|
|
79
87
|
* Narrows an `unknown` value to an `object` if it is type-compatible, or raises an error otherwise.
|
|
80
88
|
*
|
|
@@ -85,7 +93,6 @@ exports.assertBoolean = assertBoolean;
|
|
|
85
93
|
function assertObject(value, message) {
|
|
86
94
|
assertNonNull((0, as_1.asObject)(value), message ?? 'Value is not an object');
|
|
87
95
|
}
|
|
88
|
-
exports.assertObject = assertObject;
|
|
89
96
|
/**
|
|
90
97
|
* Narrows an `unknown` value to an `object` if it is type-compatible and tests positively with {@link isPlainObject},
|
|
91
98
|
* or raises an error otherwise.
|
|
@@ -97,7 +104,6 @@ exports.assertObject = assertObject;
|
|
|
97
104
|
function assertPlainObject(value, message) {
|
|
98
105
|
assertNonNull((0, as_1.asPlainObject)(value), message ?? 'Value is not a plain object');
|
|
99
106
|
}
|
|
100
|
-
exports.assertPlainObject = assertPlainObject;
|
|
101
107
|
/**
|
|
102
108
|
* Narrows an `unknown` value to a `Dictionary<T>` if it is type-compatible and tests positively
|
|
103
109
|
* with {@link isDictionary}, or raises an error otherwise.
|
|
@@ -109,7 +115,6 @@ exports.assertPlainObject = assertPlainObject;
|
|
|
109
115
|
function assertDictionary(value, message) {
|
|
110
116
|
assertNonNull((0, as_1.asDictionary)(value), message ?? 'Value is not a dictionary object');
|
|
111
117
|
}
|
|
112
|
-
exports.assertDictionary = assertDictionary;
|
|
113
118
|
/**
|
|
114
119
|
* Narrows an `unknown` value to instance of constructor type `T` if it is type-compatible, or raises an error
|
|
115
120
|
* otherwise.
|
|
@@ -121,7 +126,6 @@ exports.assertDictionary = assertDictionary;
|
|
|
121
126
|
function assertInstance(value, ctor, message) {
|
|
122
127
|
assertNonNull((0, as_1.asInstance)(value, ctor), message ?? `Value is not an instance of ${ctor.name}`);
|
|
123
128
|
}
|
|
124
|
-
exports.assertInstance = assertInstance;
|
|
125
129
|
/**
|
|
126
130
|
* Narrows an `unknown` value to an `Array` if it is type-compatible, or raises an error otherwise.
|
|
127
131
|
*
|
|
@@ -132,7 +136,6 @@ exports.assertInstance = assertInstance;
|
|
|
132
136
|
function assertArray(value, message) {
|
|
133
137
|
assertNonNull((0, as_1.asArray)(value), message ?? 'Value is not an array');
|
|
134
138
|
}
|
|
135
|
-
exports.assertArray = assertArray;
|
|
136
139
|
/**
|
|
137
140
|
* Narrows an `unknown` value to an `AnyFunction` if it is type-compatible, or raises an error otherwise.
|
|
138
141
|
*
|
|
@@ -143,7 +146,6 @@ exports.assertArray = assertArray;
|
|
|
143
146
|
function assertFunction(value, message) {
|
|
144
147
|
assertNonNull((0, as_1.asFunction)(value), message ?? 'Value is not a function');
|
|
145
148
|
}
|
|
146
|
-
exports.assertFunction = assertFunction;
|
|
147
149
|
/**
|
|
148
150
|
* Narrows an `unknown` value to an `AnyJson` if it is type-compatible, or returns `undefined` otherwise.
|
|
149
151
|
*
|
|
@@ -156,7 +158,6 @@ exports.assertFunction = assertFunction;
|
|
|
156
158
|
function assertAnyJson(value, message) {
|
|
157
159
|
assertNonNull((0, to_1.toAnyJson)(value), message ?? 'Value is not a JSON-compatible value type');
|
|
158
160
|
}
|
|
159
|
-
exports.assertAnyJson = assertAnyJson;
|
|
160
161
|
/**
|
|
161
162
|
* Narrows an `AnyJson` value to a `JsonMap` if it is type-compatible, or raises an error otherwise.
|
|
162
163
|
*
|
|
@@ -167,7 +168,6 @@ exports.assertAnyJson = assertAnyJson;
|
|
|
167
168
|
function assertJsonMap(value, message) {
|
|
168
169
|
assertNonNull((0, as_1.asJsonMap)(value), message ?? 'Value is not a JsonMap');
|
|
169
170
|
}
|
|
170
|
-
exports.assertJsonMap = assertJsonMap;
|
|
171
171
|
/**
|
|
172
172
|
* Narrows an `AnyJson` value to a `JsonArray` if it is type-compatible, or raises an error otherwise.
|
|
173
173
|
*
|
|
@@ -178,5 +178,4 @@ exports.assertJsonMap = assertJsonMap;
|
|
|
178
178
|
function assertJsonArray(value, message) {
|
|
179
179
|
assertNonNull((0, as_1.asJsonArray)(value), message ?? 'Value is not a JsonArray');
|
|
180
180
|
}
|
|
181
|
-
exports.assertJsonArray = assertJsonArray;
|
|
182
181
|
//# sourceMappingURL=assert.js.map
|
package/lib/narrowing/coerce.js
CHANGED
|
@@ -6,22 +6,21 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.coerceAnyJson = coerceAnyJson;
|
|
10
|
+
exports.coerceJsonMap = coerceJsonMap;
|
|
11
|
+
exports.coerceJsonArray = coerceJsonArray;
|
|
10
12
|
const as_1 = require("./as");
|
|
11
13
|
const is_1 = require("./is");
|
|
12
14
|
// underlying function
|
|
13
15
|
function coerceAnyJson(value, defaultValue) {
|
|
14
16
|
return (0, is_1.isAnyJson)(value) ? value : defaultValue;
|
|
15
17
|
}
|
|
16
|
-
exports.coerceAnyJson = coerceAnyJson;
|
|
17
18
|
// underlying function
|
|
18
19
|
function coerceJsonMap(value, defaultValue) {
|
|
19
20
|
return (0, as_1.asJsonMap)(coerceAnyJson(value)) ?? defaultValue;
|
|
20
21
|
}
|
|
21
|
-
exports.coerceJsonMap = coerceJsonMap;
|
|
22
22
|
// underlying method
|
|
23
23
|
function coerceJsonArray(value, defaultValue) {
|
|
24
24
|
return (0, as_1.asJsonArray)(coerceAnyJson(value)) ?? defaultValue;
|
|
25
25
|
}
|
|
26
|
-
exports.coerceJsonArray = coerceJsonArray;
|
|
27
26
|
//# sourceMappingURL=coerce.js.map
|
package/lib/narrowing/ensure.js
CHANGED
|
@@ -6,7 +6,19 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.ensure = ensure;
|
|
10
|
+
exports.ensureString = ensureString;
|
|
11
|
+
exports.ensureNumber = ensureNumber;
|
|
12
|
+
exports.ensureBoolean = ensureBoolean;
|
|
13
|
+
exports.ensureObject = ensureObject;
|
|
14
|
+
exports.ensurePlainObject = ensurePlainObject;
|
|
15
|
+
exports.ensureDictionary = ensureDictionary;
|
|
16
|
+
exports.ensureInstance = ensureInstance;
|
|
17
|
+
exports.ensureArray = ensureArray;
|
|
18
|
+
exports.ensureFunction = ensureFunction;
|
|
19
|
+
exports.ensureAnyJson = ensureAnyJson;
|
|
20
|
+
exports.ensureJsonMap = ensureJsonMap;
|
|
21
|
+
exports.ensureJsonArray = ensureJsonArray;
|
|
10
22
|
const errors_1 = require("../errors");
|
|
11
23
|
const as_1 = require("./as");
|
|
12
24
|
const to_1 = require("./to");
|
|
@@ -31,7 +43,6 @@ function ensure(value, message) {
|
|
|
31
43
|
}
|
|
32
44
|
return value;
|
|
33
45
|
}
|
|
34
|
-
exports.ensure = ensure;
|
|
35
46
|
/**
|
|
36
47
|
* Narrows an `unknown` value to a `string` if it is type-compatible, or raises an error otherwise.
|
|
37
48
|
*
|
|
@@ -42,7 +53,6 @@ exports.ensure = ensure;
|
|
|
42
53
|
function ensureString(value, message) {
|
|
43
54
|
return ensure((0, as_1.asString)(value), message ?? 'Value is not a string');
|
|
44
55
|
}
|
|
45
|
-
exports.ensureString = ensureString;
|
|
46
56
|
/**
|
|
47
57
|
* Narrows an `unknown` value to a `number` if it is type-compatible, or raises an error otherwise.
|
|
48
58
|
*
|
|
@@ -53,7 +63,6 @@ exports.ensureString = ensureString;
|
|
|
53
63
|
function ensureNumber(value, message) {
|
|
54
64
|
return ensure((0, as_1.asNumber)(value), message ?? 'Value is not a number');
|
|
55
65
|
}
|
|
56
|
-
exports.ensureNumber = ensureNumber;
|
|
57
66
|
/**
|
|
58
67
|
* Narrows an `unknown` value to a `boolean` if it is type-compatible, or raises an error otherwise.
|
|
59
68
|
*
|
|
@@ -64,7 +73,6 @@ exports.ensureNumber = ensureNumber;
|
|
|
64
73
|
function ensureBoolean(value, message) {
|
|
65
74
|
return ensure((0, as_1.asBoolean)(value), message ?? 'Value is not a boolean');
|
|
66
75
|
}
|
|
67
|
-
exports.ensureBoolean = ensureBoolean;
|
|
68
76
|
/**
|
|
69
77
|
* Narrows an `unknown` value to an `object` if it is type-compatible, or raises an error otherwise.
|
|
70
78
|
*
|
|
@@ -75,7 +83,6 @@ exports.ensureBoolean = ensureBoolean;
|
|
|
75
83
|
function ensureObject(value, message) {
|
|
76
84
|
return ensure((0, as_1.asObject)(value), message ?? 'Value is not an object');
|
|
77
85
|
}
|
|
78
|
-
exports.ensureObject = ensureObject;
|
|
79
86
|
/**
|
|
80
87
|
* Narrows an `unknown` value to an `object` if it is type-compatible and tests positively with {@link isPlainObject},
|
|
81
88
|
* or raises an error otherwise.
|
|
@@ -87,7 +94,6 @@ exports.ensureObject = ensureObject;
|
|
|
87
94
|
function ensurePlainObject(value, message) {
|
|
88
95
|
return ensure((0, as_1.asPlainObject)(value), message ?? 'Value is not a plain object');
|
|
89
96
|
}
|
|
90
|
-
exports.ensurePlainObject = ensurePlainObject;
|
|
91
97
|
/**
|
|
92
98
|
* Narrows an `unknown` value to a `Dictionary<T>` if it is type-compatible and tests positively
|
|
93
99
|
* with {@link isDictionary}, or raises an error otherwise.
|
|
@@ -99,7 +105,6 @@ exports.ensurePlainObject = ensurePlainObject;
|
|
|
99
105
|
function ensureDictionary(value, message) {
|
|
100
106
|
return ensure((0, as_1.asDictionary)(value), message ?? 'Value is not a dictionary object');
|
|
101
107
|
}
|
|
102
|
-
exports.ensureDictionary = ensureDictionary;
|
|
103
108
|
/**
|
|
104
109
|
* Narrows an `unknown` value to instance of constructor type `T` if it is type-compatible, or raises an error
|
|
105
110
|
* otherwise.
|
|
@@ -111,7 +116,6 @@ exports.ensureDictionary = ensureDictionary;
|
|
|
111
116
|
function ensureInstance(value, ctor, message) {
|
|
112
117
|
return ensure((0, as_1.asInstance)(value, ctor), message ?? `Value is not an instance of ${ctor.name}`);
|
|
113
118
|
}
|
|
114
|
-
exports.ensureInstance = ensureInstance;
|
|
115
119
|
/**
|
|
116
120
|
* Narrows an `unknown` value to an `Array` if it is type-compatible, or raises an error otherwise.
|
|
117
121
|
*
|
|
@@ -122,7 +126,6 @@ exports.ensureInstance = ensureInstance;
|
|
|
122
126
|
function ensureArray(value, message) {
|
|
123
127
|
return ensure((0, as_1.asArray)(value), message ?? 'Value is not an array');
|
|
124
128
|
}
|
|
125
|
-
exports.ensureArray = ensureArray;
|
|
126
129
|
/**
|
|
127
130
|
* Narrows an `unknown` value to an `AnyFunction` if it is type-compatible, or raises an error otherwise.
|
|
128
131
|
*
|
|
@@ -133,7 +136,6 @@ exports.ensureArray = ensureArray;
|
|
|
133
136
|
function ensureFunction(value, message) {
|
|
134
137
|
return ensure((0, as_1.asFunction)(value), message ?? 'Value is not a function');
|
|
135
138
|
}
|
|
136
|
-
exports.ensureFunction = ensureFunction;
|
|
137
139
|
/**
|
|
138
140
|
* Narrows an `unknown` value to an `AnyJson` if it is type-compatible, or returns `undefined` otherwise.
|
|
139
141
|
*
|
|
@@ -146,7 +148,6 @@ exports.ensureFunction = ensureFunction;
|
|
|
146
148
|
function ensureAnyJson(value, message) {
|
|
147
149
|
return ensure((0, to_1.toAnyJson)(value), message ?? 'Value is not a JSON-compatible value type');
|
|
148
150
|
}
|
|
149
|
-
exports.ensureAnyJson = ensureAnyJson;
|
|
150
151
|
/**
|
|
151
152
|
* Narrows an `AnyJson` value to a `JsonMap` if it is type-compatible, or raises an error otherwise.
|
|
152
153
|
*
|
|
@@ -157,7 +158,6 @@ exports.ensureAnyJson = ensureAnyJson;
|
|
|
157
158
|
function ensureJsonMap(value, message) {
|
|
158
159
|
return ensure((0, as_1.asJsonMap)(value), message ?? 'Value is not a JsonMap');
|
|
159
160
|
}
|
|
160
|
-
exports.ensureJsonMap = ensureJsonMap;
|
|
161
161
|
/**
|
|
162
162
|
* Narrows an `AnyJson` value to a `JsonArray` if it is type-compatible, or raises an error otherwise.
|
|
163
163
|
*
|
|
@@ -168,5 +168,4 @@ exports.ensureJsonMap = ensureJsonMap;
|
|
|
168
168
|
function ensureJsonArray(value, message) {
|
|
169
169
|
return ensure((0, as_1.asJsonArray)(value), message ?? 'Value is not a JsonArray');
|
|
170
170
|
}
|
|
171
|
-
exports.ensureJsonArray = ensureJsonArray;
|
|
172
171
|
//# sourceMappingURL=ensure.js.map
|
package/lib/narrowing/get.js
CHANGED
|
@@ -6,7 +6,19 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.get = get;
|
|
10
|
+
exports.getString = getString;
|
|
11
|
+
exports.getNumber = getNumber;
|
|
12
|
+
exports.getBoolean = getBoolean;
|
|
13
|
+
exports.getObject = getObject;
|
|
14
|
+
exports.getPlainObject = getPlainObject;
|
|
15
|
+
exports.getDictionary = getDictionary;
|
|
16
|
+
exports.getInstance = getInstance;
|
|
17
|
+
exports.getArray = getArray;
|
|
18
|
+
exports.getFunction = getFunction;
|
|
19
|
+
exports.getAnyJson = getAnyJson;
|
|
20
|
+
exports.getJsonMap = getJsonMap;
|
|
21
|
+
exports.getJsonArray = getJsonArray;
|
|
10
22
|
const as_1 = require("./as");
|
|
11
23
|
const coerce_1 = require("./coerce");
|
|
12
24
|
const has_1 = require("./has");
|
|
@@ -43,65 +55,52 @@ function get(from, path, defaultValue) {
|
|
|
43
55
|
.filter((p) => !!p)
|
|
44
56
|
.reduce((r, p) => ((0, has_1.has)(r, p) ? r[p] : undefined), from), defaultValue);
|
|
45
57
|
}
|
|
46
|
-
exports.get = get;
|
|
47
58
|
// underlying function
|
|
48
59
|
function getString(from, path, defaultValue) {
|
|
49
60
|
return (0, internal_1.valueOrDefault)((0, as_1.asString)(get(from, path)), defaultValue);
|
|
50
61
|
}
|
|
51
|
-
exports.getString = getString;
|
|
52
62
|
// underlying function
|
|
53
63
|
function getNumber(from, path, defaultValue) {
|
|
54
64
|
return (0, internal_1.valueOrDefault)((0, as_1.asNumber)(get(from, path)), defaultValue);
|
|
55
65
|
}
|
|
56
|
-
exports.getNumber = getNumber;
|
|
57
66
|
// underlying function
|
|
58
67
|
function getBoolean(from, path, defaultValue) {
|
|
59
68
|
return (0, internal_1.valueOrDefault)((0, as_1.asBoolean)(get(from, path)), defaultValue);
|
|
60
69
|
}
|
|
61
|
-
exports.getBoolean = getBoolean;
|
|
62
70
|
// underlying function
|
|
63
71
|
function getObject(from, path, defaultValue) {
|
|
64
72
|
return (0, internal_1.valueOrDefault)((0, as_1.asObject)(get(from, path)), defaultValue);
|
|
65
73
|
}
|
|
66
|
-
exports.getObject = getObject;
|
|
67
74
|
// underlying function
|
|
68
75
|
function getPlainObject(from, path, defaultValue) {
|
|
69
76
|
return (0, internal_1.valueOrDefault)((0, as_1.asPlainObject)(get(from, path)), defaultValue);
|
|
70
77
|
}
|
|
71
|
-
exports.getPlainObject = getPlainObject;
|
|
72
78
|
// underlying function
|
|
73
79
|
function getDictionary(from, path, defaultValue) {
|
|
74
80
|
return (0, internal_1.valueOrDefault)((0, as_1.asDictionary)(get(from, path)), defaultValue);
|
|
75
81
|
}
|
|
76
|
-
exports.getDictionary = getDictionary;
|
|
77
82
|
// underlying function
|
|
78
83
|
function getInstance(from, path, ctor, defaultValue) {
|
|
79
84
|
return (0, internal_1.valueOrDefault)((0, as_1.asInstance)(get(from, path), ctor), defaultValue);
|
|
80
85
|
}
|
|
81
|
-
exports.getInstance = getInstance;
|
|
82
86
|
// underlying function
|
|
83
87
|
function getArray(from, path, defaultValue) {
|
|
84
88
|
return (0, internal_1.valueOrDefault)((0, as_1.asArray)(get(from, path)), defaultValue);
|
|
85
89
|
}
|
|
86
|
-
exports.getArray = getArray;
|
|
87
90
|
// underlying function
|
|
88
91
|
function getFunction(from, path, defaultValue) {
|
|
89
92
|
return (0, internal_1.valueOrDefault)((0, as_1.asFunction)(get(from, path)), defaultValue);
|
|
90
93
|
}
|
|
91
|
-
exports.getFunction = getFunction;
|
|
92
94
|
// underlying function
|
|
93
95
|
function getAnyJson(from, path, defaultValue) {
|
|
94
96
|
return (0, internal_1.valueOrDefault)((0, coerce_1.coerceAnyJson)(get(from, path)), defaultValue);
|
|
95
97
|
}
|
|
96
|
-
exports.getAnyJson = getAnyJson;
|
|
97
98
|
// underlying function
|
|
98
99
|
function getJsonMap(from, path, defaultValue) {
|
|
99
100
|
return (0, internal_1.valueOrDefault)((0, as_1.asJsonMap)(getAnyJson(from, path)), defaultValue);
|
|
100
101
|
}
|
|
101
|
-
exports.getJsonMap = getJsonMap;
|
|
102
102
|
// underlying function
|
|
103
103
|
function getJsonArray(from, path, defaultValue) {
|
|
104
104
|
return (0, internal_1.valueOrDefault)((0, as_1.asJsonArray)(getAnyJson(from, path)), defaultValue);
|
|
105
105
|
}
|
|
106
|
-
exports.getJsonArray = getJsonArray;
|
|
107
106
|
//# sourceMappingURL=get.js.map
|
package/lib/narrowing/has.js
CHANGED
|
@@ -6,7 +6,19 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.has = has;
|
|
10
|
+
exports.hasString = hasString;
|
|
11
|
+
exports.hasNumber = hasNumber;
|
|
12
|
+
exports.hasBoolean = hasBoolean;
|
|
13
|
+
exports.hasObject = hasObject;
|
|
14
|
+
exports.hasPlainObject = hasPlainObject;
|
|
15
|
+
exports.hasDictionary = hasDictionary;
|
|
16
|
+
exports.hasInstance = hasInstance;
|
|
17
|
+
exports.hasArray = hasArray;
|
|
18
|
+
exports.hasFunction = hasFunction;
|
|
19
|
+
exports.hasAnyJson = hasAnyJson;
|
|
20
|
+
exports.hasJsonMap = hasJsonMap;
|
|
21
|
+
exports.hasJsonArray = hasJsonArray;
|
|
10
22
|
const is_1 = require("./is");
|
|
11
23
|
/**
|
|
12
24
|
* Tests whether a value of type `T` contains one or more property `keys`. If so, the type of the tested value is
|
|
@@ -32,7 +44,6 @@ const is_1 = require("./is");
|
|
|
32
44
|
function has(value, keys) {
|
|
33
45
|
return (0, is_1.isObject)(value) && ((0, is_1.isArray)(keys) ? keys.every((k) => k in value) : keys in value);
|
|
34
46
|
}
|
|
35
|
-
exports.has = has;
|
|
36
47
|
/**
|
|
37
48
|
* Tests whether a value of type `T` contains a property `key` of type `string`. If so, the type of the tested value is
|
|
38
49
|
* narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the
|
|
@@ -54,7 +65,6 @@ exports.has = has;
|
|
|
54
65
|
function hasString(value, key) {
|
|
55
66
|
return has(value, key) && (0, is_1.isString)(value[key]);
|
|
56
67
|
}
|
|
57
|
-
exports.hasString = hasString;
|
|
58
68
|
/**
|
|
59
69
|
* Tests whether a value of type `T` contains a property `key` of type `number`. If so, the type of the tested value is
|
|
60
70
|
* narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the
|
|
@@ -76,7 +86,6 @@ exports.hasString = hasString;
|
|
|
76
86
|
function hasNumber(value, key) {
|
|
77
87
|
return has(value, key) && (0, is_1.isNumber)(value[key]);
|
|
78
88
|
}
|
|
79
|
-
exports.hasNumber = hasNumber;
|
|
80
89
|
/**
|
|
81
90
|
* Tests whether a value of type `T` contains a property `key` of type `boolean`. If so, the type of the tested value is
|
|
82
91
|
* narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the
|
|
@@ -98,7 +107,6 @@ exports.hasNumber = hasNumber;
|
|
|
98
107
|
function hasBoolean(value, key) {
|
|
99
108
|
return has(value, key) && (0, is_1.isBoolean)(value[key]);
|
|
100
109
|
}
|
|
101
|
-
exports.hasBoolean = hasBoolean;
|
|
102
110
|
/**
|
|
103
111
|
* Tests whether a value of type `T` contains a property `key` of type `object`. If so, the type of the tested value is
|
|
104
112
|
* narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if the
|
|
@@ -122,7 +130,6 @@ exports.hasBoolean = hasBoolean;
|
|
|
122
130
|
function hasObject(value, key) {
|
|
123
131
|
return has(value, key) && (0, is_1.isObject)(value[key]);
|
|
124
132
|
}
|
|
125
|
-
exports.hasObject = hasObject;
|
|
126
133
|
/**
|
|
127
134
|
* Tests whether a value of type `T` contains a property `key` whose type tests positively when tested with
|
|
128
135
|
* {@link isPlainObject}. If so, the type of the tested value is narrowed to reflect the existence of that key for
|
|
@@ -147,7 +154,6 @@ exports.hasObject = hasObject;
|
|
|
147
154
|
function hasPlainObject(value, key) {
|
|
148
155
|
return has(value, key) && (0, is_1.isPlainObject)(value[key]);
|
|
149
156
|
}
|
|
150
|
-
exports.hasPlainObject = hasPlainObject;
|
|
151
157
|
/**
|
|
152
158
|
* Tests whether a value of type `T` contains a property `key` whose type tests positively when tested with
|
|
153
159
|
* {@link isDictionary}. If so, the type of the tested value is narrowed to reflect the existence of that key for
|
|
@@ -172,7 +178,6 @@ exports.hasPlainObject = hasPlainObject;
|
|
|
172
178
|
function hasDictionary(value, key) {
|
|
173
179
|
return has(value, key) && (0, is_1.isDictionary)(value[key]);
|
|
174
180
|
}
|
|
175
|
-
exports.hasDictionary = hasDictionary;
|
|
176
181
|
/**
|
|
177
182
|
* Tests whether a value of type `T` contains a property `key` whose type tests positively when tested with
|
|
178
183
|
* {@link isInstance} when compared with the given constructor type `C`. If so, the type of the tested value is
|
|
@@ -198,7 +203,6 @@ exports.hasDictionary = hasDictionary;
|
|
|
198
203
|
function hasInstance(value, key, ctor) {
|
|
199
204
|
return has(value, key) && value[key] instanceof ctor;
|
|
200
205
|
}
|
|
201
|
-
exports.hasInstance = hasInstance;
|
|
202
206
|
/**
|
|
203
207
|
* Tests whether a value of type `T` contains a property `key` of type {@link AnyArray}. If so, the type of the tested
|
|
204
208
|
* value is narrowed to reflect the existence of that key for convenient access in the same scope. Returns `false` if
|
|
@@ -220,7 +224,6 @@ exports.hasInstance = hasInstance;
|
|
|
220
224
|
function hasArray(value, key) {
|
|
221
225
|
return has(value, key) && (0, is_1.isArray)(value[key]);
|
|
222
226
|
}
|
|
223
|
-
exports.hasArray = hasArray;
|
|
224
227
|
/**
|
|
225
228
|
* Tests whether a value of type `T` contains a property `key` of type {@link AnyFunction}. If so, the type of the
|
|
226
229
|
* tested value is narrowed to reflect the existence of that key for convenient access in the same scope. Returns
|
|
@@ -241,7 +244,6 @@ exports.hasArray = hasArray;
|
|
|
241
244
|
function hasFunction(value, key) {
|
|
242
245
|
return has(value, key) && (0, is_1.isFunction)(value[key]);
|
|
243
246
|
}
|
|
244
|
-
exports.hasFunction = hasFunction;
|
|
245
247
|
/**
|
|
246
248
|
* Tests whether a value of type `T` contains a property `key` of type {@link AnyJson}, _using a shallow test for
|
|
247
249
|
* `AnyJson` compatibility_ (see {@link isAnyJson} for more information). If so, the type of the
|
|
@@ -262,7 +264,6 @@ exports.hasFunction = hasFunction;
|
|
|
262
264
|
function hasAnyJson(value, key) {
|
|
263
265
|
return has(value, key) && (0, is_1.isAnyJson)(value[key]);
|
|
264
266
|
}
|
|
265
|
-
exports.hasAnyJson = hasAnyJson;
|
|
266
267
|
/**
|
|
267
268
|
* Tests whether a value of type `T extends AnyJson` contains a property `key` of type {@link JsonMap}. If so, the type
|
|
268
269
|
* of the tested value is narrowed to reflect the existence of that key for convenient access in the same scope. Returns
|
|
@@ -282,7 +283,6 @@ exports.hasAnyJson = hasAnyJson;
|
|
|
282
283
|
function hasJsonMap(value, key) {
|
|
283
284
|
return hasAnyJson(value, key) && (0, is_1.isJsonMap)(value[key]);
|
|
284
285
|
}
|
|
285
|
-
exports.hasJsonMap = hasJsonMap;
|
|
286
286
|
/**
|
|
287
287
|
* Tests whether a value of type `T extends AnyJson` contains a property `key` of type {@link JsonArray}. If so, the
|
|
288
288
|
* type of the tested value is narrowed to reflect the existence of that key for convenient access in the same scope.
|
|
@@ -302,5 +302,4 @@ exports.hasJsonMap = hasJsonMap;
|
|
|
302
302
|
function hasJsonArray(value, key) {
|
|
303
303
|
return hasAnyJson(value, key) && (0, is_1.isJsonArray)(value[key]);
|
|
304
304
|
}
|
|
305
|
-
exports.hasJsonArray = hasJsonArray;
|
|
306
305
|
//# sourceMappingURL=has.js.map
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.valueOrDefault =
|
|
9
|
+
exports.valueOrDefault = valueOrDefault;
|
|
10
10
|
/**
|
|
11
11
|
* Returns the given `value` if not either `undefined` or `null`, or the given `defaultValue` otherwise if defined.
|
|
12
12
|
* Returns `null` if the value is `null` and `defaultValue` is `undefined`.
|
|
@@ -18,5 +18,4 @@ exports.valueOrDefault = void 0;
|
|
|
18
18
|
function valueOrDefault(value, defaultValue) {
|
|
19
19
|
return value != null || defaultValue === undefined ? value : defaultValue;
|
|
20
20
|
}
|
|
21
|
-
exports.valueOrDefault = valueOrDefault;
|
|
22
21
|
//# sourceMappingURL=internal.js.map
|
package/lib/narrowing/is.js
CHANGED
|
@@ -6,7 +6,21 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.isString = isString;
|
|
10
|
+
exports.isNumber = isNumber;
|
|
11
|
+
exports.isBoolean = isBoolean;
|
|
12
|
+
exports.isObject = isObject;
|
|
13
|
+
exports.isFunction = isFunction;
|
|
14
|
+
exports.isPlainObject = isPlainObject;
|
|
15
|
+
exports.isDictionary = isDictionary;
|
|
16
|
+
exports.isInstance = isInstance;
|
|
17
|
+
exports.isClassAssignableTo = isClassAssignableTo;
|
|
18
|
+
exports.isArray = isArray;
|
|
19
|
+
exports.isArrayLike = isArrayLike;
|
|
20
|
+
exports.isAnyJson = isAnyJson;
|
|
21
|
+
exports.isJsonMap = isJsonMap;
|
|
22
|
+
exports.isJsonArray = isJsonArray;
|
|
23
|
+
exports.isKeyOf = isKeyOf;
|
|
10
24
|
/**
|
|
11
25
|
* Tests whether an `unknown` value is a `string`.
|
|
12
26
|
*
|
|
@@ -15,7 +29,6 @@ exports.isKeyOf = exports.isJsonArray = exports.isJsonMap = exports.isAnyJson =
|
|
|
15
29
|
function isString(value) {
|
|
16
30
|
return typeof value === 'string';
|
|
17
31
|
}
|
|
18
|
-
exports.isString = isString;
|
|
19
32
|
/**
|
|
20
33
|
* Tests whether an `unknown` value is a `number`.
|
|
21
34
|
*
|
|
@@ -24,7 +37,6 @@ exports.isString = isString;
|
|
|
24
37
|
function isNumber(value) {
|
|
25
38
|
return typeof value === 'number';
|
|
26
39
|
}
|
|
27
|
-
exports.isNumber = isNumber;
|
|
28
40
|
/**
|
|
29
41
|
* Tests whether an `unknown` value is a `boolean`.
|
|
30
42
|
*
|
|
@@ -33,7 +45,6 @@ exports.isNumber = isNumber;
|
|
|
33
45
|
function isBoolean(value) {
|
|
34
46
|
return typeof value === 'boolean';
|
|
35
47
|
}
|
|
36
|
-
exports.isBoolean = isBoolean;
|
|
37
48
|
/**
|
|
38
49
|
* Tests whether an `unknown` value is an `Object` subtype (e.g., arrays, functions, objects, regexes,
|
|
39
50
|
* new Number(0), new String(''), and new Boolean(true)). Tests that wish to distinguish objects that
|
|
@@ -53,7 +64,6 @@ exports.isBoolean = isBoolean;
|
|
|
53
64
|
function isObject(value) {
|
|
54
65
|
return value != null && (typeof value === 'object' || typeof value === 'function');
|
|
55
66
|
}
|
|
56
|
-
exports.isObject = isObject;
|
|
57
67
|
/**
|
|
58
68
|
* Tests whether an `unknown` value is a `function`.
|
|
59
69
|
*
|
|
@@ -62,7 +72,6 @@ exports.isObject = isObject;
|
|
|
62
72
|
function isFunction(value) {
|
|
63
73
|
return typeof value === 'function';
|
|
64
74
|
}
|
|
65
|
-
exports.isFunction = isFunction;
|
|
66
75
|
/**
|
|
67
76
|
* Tests whether or not an `unknown` value is a plain JavaScript object. That is, if it is an object created
|
|
68
77
|
* by the Object constructor or one with a null `prototype`.
|
|
@@ -91,7 +100,6 @@ function isPlainObject(value) {
|
|
|
91
100
|
return false;
|
|
92
101
|
return true;
|
|
93
102
|
}
|
|
94
|
-
exports.isPlainObject = isPlainObject;
|
|
95
103
|
/**
|
|
96
104
|
* A shortcut for testing the suitability of a value to be used as a `Dictionary<T>` type. Shorthand for
|
|
97
105
|
* writing `isPlainObject<Dictionary<T>>(value)`. While some non-plain-object types are compatible with
|
|
@@ -110,7 +118,6 @@ exports.isPlainObject = isPlainObject;
|
|
|
110
118
|
function isDictionary(value) {
|
|
111
119
|
return isPlainObject(value);
|
|
112
120
|
}
|
|
113
|
-
exports.isDictionary = isDictionary;
|
|
114
121
|
/**
|
|
115
122
|
* Tests whether an `unknown` value is a `function`.
|
|
116
123
|
*
|
|
@@ -119,7 +126,6 @@ exports.isDictionary = isDictionary;
|
|
|
119
126
|
function isInstance(value, ctor) {
|
|
120
127
|
return value instanceof ctor;
|
|
121
128
|
}
|
|
122
|
-
exports.isInstance = isInstance;
|
|
123
129
|
/**
|
|
124
130
|
* Tests whether an `unknown` value is a class constructor that is either equal to or extends another class
|
|
125
131
|
* constructor.
|
|
@@ -132,7 +138,6 @@ function isClassAssignableTo(value, cls) {
|
|
|
132
138
|
const has = (v, k) => isObject(v) && k in v;
|
|
133
139
|
return value === cls || (has(value, 'prototype') && value.prototype instanceof cls);
|
|
134
140
|
}
|
|
135
|
-
exports.isClassAssignableTo = isClassAssignableTo;
|
|
136
141
|
/**
|
|
137
142
|
* Tests whether an `unknown` value is an `Array`.
|
|
138
143
|
*
|
|
@@ -149,7 +154,6 @@ exports.isClassAssignableTo = isClassAssignableTo;
|
|
|
149
154
|
function isArray(value) {
|
|
150
155
|
return Array.isArray(value);
|
|
151
156
|
}
|
|
152
|
-
exports.isArray = isArray;
|
|
153
157
|
/**
|
|
154
158
|
* Tests whether an `unknown` value conforms to {@link AnyArrayLike}.
|
|
155
159
|
*
|
|
@@ -168,7 +172,6 @@ function isArrayLike(value) {
|
|
|
168
172
|
const hasLength = (v) => isObject(v) && 'length' in v;
|
|
169
173
|
return !isFunction(value) && (isString(value) || hasLength(value));
|
|
170
174
|
}
|
|
171
|
-
exports.isArrayLike = isArrayLike;
|
|
172
175
|
/**
|
|
173
176
|
* Tests whether `unknown` value is a valid JSON type. Note that objects and arrays are only checked using a shallow
|
|
174
177
|
* test. To be sure that a given value is JSON-compatible at runtime, see {@link toAnyJson}.
|
|
@@ -178,7 +181,6 @@ exports.isArrayLike = isArrayLike;
|
|
|
178
181
|
function isAnyJson(value) {
|
|
179
182
|
return (value === null || isString(value) || isNumber(value) || isBoolean(value) || isPlainObject(value) || isArray(value));
|
|
180
183
|
}
|
|
181
|
-
exports.isAnyJson = isAnyJson;
|
|
182
184
|
/**
|
|
183
185
|
* Tests whether an `AnyJson` value is an object.
|
|
184
186
|
*
|
|
@@ -187,7 +189,6 @@ exports.isAnyJson = isAnyJson;
|
|
|
187
189
|
function isJsonMap(value) {
|
|
188
190
|
return isPlainObject(value);
|
|
189
191
|
}
|
|
190
|
-
exports.isJsonMap = isJsonMap;
|
|
191
192
|
/**
|
|
192
193
|
* Tests whether an `AnyJson` value is an array.
|
|
193
194
|
*
|
|
@@ -196,7 +197,6 @@ exports.isJsonMap = isJsonMap;
|
|
|
196
197
|
function isJsonArray(value) {
|
|
197
198
|
return isArray(value);
|
|
198
199
|
}
|
|
199
|
-
exports.isJsonArray = isJsonArray;
|
|
200
200
|
/**
|
|
201
201
|
* Tests whether or not a `key` string is a key of the given object type `T`.
|
|
202
202
|
*
|
|
@@ -206,5 +206,4 @@ exports.isJsonArray = isJsonArray;
|
|
|
206
206
|
function isKeyOf(obj, key) {
|
|
207
207
|
return Object.keys(obj).includes(key);
|
|
208
208
|
}
|
|
209
|
-
exports.isKeyOf = isKeyOf;
|
|
210
209
|
//# sourceMappingURL=is.js.map
|
package/lib/narrowing/object.js
CHANGED
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.keysOf = keysOf;
|
|
10
|
+
exports.entriesOf = entriesOf;
|
|
11
|
+
exports.valuesOf = valuesOf;
|
|
12
|
+
exports.definiteEntriesOf = definiteEntriesOf;
|
|
13
|
+
exports.definiteKeysOf = definiteKeysOf;
|
|
14
|
+
exports.definiteValuesOf = definiteValuesOf;
|
|
10
15
|
/**
|
|
11
16
|
* Returns the keys of an object of type `T`. This is like `Object.keys` except the return type
|
|
12
17
|
* captures the known keys of `T`.
|
|
@@ -38,7 +43,6 @@ exports.definiteValuesOf = exports.definiteKeysOf = exports.definiteEntriesOf =
|
|
|
38
43
|
function keysOf(obj) {
|
|
39
44
|
return Object.keys(obj ?? {});
|
|
40
45
|
}
|
|
41
|
-
exports.keysOf = keysOf;
|
|
42
46
|
/**
|
|
43
47
|
* Returns the entries of an object of type `T`. This is like `Object.entries` except the return type
|
|
44
48
|
* captures the known keys and value types of `T`.
|
|
@@ -70,7 +74,6 @@ exports.keysOf = keysOf;
|
|
|
70
74
|
function entriesOf(obj) {
|
|
71
75
|
return Object.entries(obj ?? {});
|
|
72
76
|
}
|
|
73
|
-
exports.entriesOf = entriesOf;
|
|
74
77
|
/**
|
|
75
78
|
* Returns the values of an object of type `T`. This is like `Object.values` except the return type
|
|
76
79
|
* captures the possible value types of `T`.
|
|
@@ -102,7 +105,6 @@ exports.entriesOf = entriesOf;
|
|
|
102
105
|
function valuesOf(obj) {
|
|
103
106
|
return Object.values(obj ?? {});
|
|
104
107
|
}
|
|
105
|
-
exports.valuesOf = valuesOf;
|
|
106
108
|
/**
|
|
107
109
|
* Returns an array of all entry tuples of type `[K, NonNullable<T[K]>]` in an object `T` whose values are neither
|
|
108
110
|
* `null` nor `undefined`. This can be convenient for enumerating the entries of unknown objects with optional
|
|
@@ -116,7 +118,6 @@ exports.valuesOf = valuesOf;
|
|
|
116
118
|
function definiteEntriesOf(obj) {
|
|
117
119
|
return entriesOf(obj).filter((entry) => entry[1] != null);
|
|
118
120
|
}
|
|
119
|
-
exports.definiteEntriesOf = definiteEntriesOf;
|
|
120
121
|
/**
|
|
121
122
|
* Returns an array of all `string` keys in an object of type `T` whose values are neither `null` nor `undefined`.
|
|
122
123
|
* This can be convenient for enumerating the keys of definitely assigned properties in an object or `Dictionary`.
|
|
@@ -128,7 +129,6 @@ exports.definiteEntriesOf = definiteEntriesOf;
|
|
|
128
129
|
function definiteKeysOf(obj) {
|
|
129
130
|
return definiteEntriesOf(obj).map((entry) => entry[0]);
|
|
130
131
|
}
|
|
131
|
-
exports.definiteKeysOf = definiteKeysOf;
|
|
132
132
|
/**
|
|
133
133
|
* Returns an array of all values of type `T` in an object `T` for values that are neither `null` nor `undefined`.
|
|
134
134
|
* This can be convenient for enumerating the values of unknown objects with optional properties (including
|
|
@@ -139,5 +139,4 @@ exports.definiteKeysOf = definiteKeysOf;
|
|
|
139
139
|
function definiteValuesOf(obj) {
|
|
140
140
|
return definiteEntriesOf(obj).map((entry) => entry[1]);
|
|
141
141
|
}
|
|
142
|
-
exports.definiteValuesOf = definiteValuesOf;
|
|
143
142
|
//# sourceMappingURL=object.js.map
|
package/lib/narrowing/to.js
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.
|
|
9
|
+
exports.toAnyJson = toAnyJson;
|
|
10
|
+
exports.toJsonMap = toJsonMap;
|
|
11
|
+
exports.toJsonArray = toJsonArray;
|
|
10
12
|
const errors_1 = require("../errors");
|
|
11
13
|
const as_1 = require("./as");
|
|
12
14
|
// underlying function
|
|
@@ -18,15 +20,12 @@ function toAnyJson(value, defaultValue) {
|
|
|
18
20
|
throw new errors_1.JsonCloneError(err);
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
exports.toAnyJson = toAnyJson;
|
|
22
23
|
// underlying function
|
|
23
24
|
function toJsonMap(value, defaultValue) {
|
|
24
25
|
return (0, as_1.asJsonMap)(toAnyJson(value)) ?? defaultValue;
|
|
25
26
|
}
|
|
26
|
-
exports.toJsonMap = toJsonMap;
|
|
27
27
|
// underlying method
|
|
28
28
|
function toJsonArray(value, defaultValue) {
|
|
29
29
|
return (0, as_1.asJsonArray)(toAnyJson(value)) ?? defaultValue;
|
|
30
30
|
}
|
|
31
|
-
exports.toJsonArray = toJsonArray;
|
|
32
31
|
//# sourceMappingURL=to.js.map
|
|
@@ -8,17 +8,15 @@ import { Optional } from './union';
|
|
|
8
8
|
* and values, see the following functions: {@link definiteEntriesOf}, {@link definiteKeysOf}, and
|
|
9
9
|
* {@link definiteValuesOf}.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type Dictionary<T = unknown> = {
|
|
12
12
|
[key: string]: Optional<T>;
|
|
13
|
-
}
|
|
13
|
+
};
|
|
14
14
|
/**
|
|
15
15
|
* An alias for an array of `T` elements, where `T` defaults to `unknown`.
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
18
|
-
}
|
|
17
|
+
export type AnyArray<T = unknown> = T[];
|
|
19
18
|
/**
|
|
20
19
|
* Any object with both a numeric index signature with values of type `T` and a numeric `length`
|
|
21
20
|
* property. `T` defaults to `unknown` if unspecified.
|
|
22
21
|
*/
|
|
23
|
-
export
|
|
24
|
-
}
|
|
22
|
+
export type AnyArrayLike<T = unknown> = ArrayLike<T>;
|
package/lib/types/json.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/ts-types",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"description": "Types and related utilities for TypeScript",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": "forcedotcom/ts-types",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"license": "BSD-3-Clause",
|
|
9
9
|
"types": "lib/index.d.ts",
|
|
10
10
|
"engines": {
|
|
11
|
-
"node": ">=
|
|
11
|
+
"node": ">=18.0.0"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"lib/**/*.js",
|
|
@@ -16,46 +16,23 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "wireit",
|
|
19
|
-
"ci-docs": "yarn sf-ci-docs",
|
|
20
19
|
"clean": "sf-clean",
|
|
21
20
|
"clean-all": "sf-clean all",
|
|
22
21
|
"compile": "wireit",
|
|
23
22
|
"docs": "sf-docs",
|
|
24
23
|
"format": "wireit",
|
|
24
|
+
"link-check": "wireit",
|
|
25
25
|
"lint": "wireit",
|
|
26
26
|
"prepack": "sf-prepack",
|
|
27
27
|
"prepare": "sf-install",
|
|
28
28
|
"test": "wireit",
|
|
29
29
|
"test:only": "wireit"
|
|
30
30
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"tslib": "^2.6.2"
|
|
33
|
-
},
|
|
31
|
+
"dependencies": {},
|
|
34
32
|
"devDependencies": {
|
|
35
|
-
"@salesforce/dev-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
39
|
-
"@typescript-eslint/parser": "^5.62.0",
|
|
40
|
-
"chai": "^4.3.10",
|
|
41
|
-
"eslint": "^8.51.0",
|
|
42
|
-
"eslint-config-prettier": "^8.10.0",
|
|
43
|
-
"eslint-config-salesforce": "^2.0.2",
|
|
44
|
-
"eslint-config-salesforce-license": "^0.2.0",
|
|
45
|
-
"eslint-config-salesforce-typescript": "^1.1.2",
|
|
46
|
-
"eslint-plugin-header": "^3.1.1",
|
|
47
|
-
"eslint-plugin-import": "2.28.1",
|
|
48
|
-
"eslint-plugin-jsdoc": "^43.2.0",
|
|
49
|
-
"eslint-plugin-prefer-arrow": "^1.2.1",
|
|
50
|
-
"husky": "^7.0.4",
|
|
51
|
-
"mocha": "^9.1.3",
|
|
52
|
-
"nyc": "^15.1.0",
|
|
53
|
-
"prettier": "^2.8.8",
|
|
54
|
-
"pretty-quick": "^3.1.0",
|
|
55
|
-
"sinon": "10.0.0",
|
|
56
|
-
"ts-node": "^10.0.0",
|
|
57
|
-
"typescript": "^4.9.5",
|
|
58
|
-
"wireit": "^0.14.0"
|
|
33
|
+
"@salesforce/dev-scripts": "^10.2.5",
|
|
34
|
+
"ts-node": "^10.9.2",
|
|
35
|
+
"typescript": "^5.5.4"
|
|
59
36
|
},
|
|
60
37
|
"wireit": {
|
|
61
38
|
"build": {
|
|
@@ -110,7 +87,8 @@
|
|
|
110
87
|
"test": {
|
|
111
88
|
"dependencies": [
|
|
112
89
|
"test:only",
|
|
113
|
-
"test:compile"
|
|
90
|
+
"test:compile",
|
|
91
|
+
"link-check"
|
|
114
92
|
]
|
|
115
93
|
},
|
|
116
94
|
"test:only": {
|
|
@@ -127,6 +105,15 @@
|
|
|
127
105
|
".nycrc"
|
|
128
106
|
],
|
|
129
107
|
"output": []
|
|
108
|
+
},
|
|
109
|
+
"link-check": {
|
|
110
|
+
"command": "node -e \"process.exit(process.env.CI ? 0 : 1)\" || linkinator \"**/*.md\" --skip \"CHANGELOG.md|node_modules|test/|confluence.internal.salesforce.com|my.salesforce.com|%s\" --markdown --retry --directory-listing --verbosity error",
|
|
111
|
+
"files": [
|
|
112
|
+
"./*.md",
|
|
113
|
+
"./!(CHANGELOG).md",
|
|
114
|
+
"messages/**/*.md"
|
|
115
|
+
],
|
|
116
|
+
"output": []
|
|
130
117
|
}
|
|
131
118
|
}
|
|
132
119
|
}
|