@sanity/validation 2.33.4-shopify.8 → 2.34.1-canary.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/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/util/requestIdleCallback.d.ts +3 -0
- package/dist/dts/util/requestIdleCallback.d.ts.map +1 -0
- package/dist/dts/validateDocument.d.ts +3 -1
- package/dist/dts/validateDocument.d.ts.map +1 -1
- package/lib/Rule.js +23 -100
- package/lib/ValidationError.js +0 -9
- package/lib/getClient.js +0 -3
- package/lib/index.js +9 -7
- package/lib/inferFromSchema.js +0 -4
- package/lib/inferFromSchemaType.js +8 -20
- package/lib/util/convertToValidationMarker.js +8 -17
- package/lib/util/deepEquals.js +1 -18
- package/lib/util/escapeRegex.js +1 -4
- package/lib/util/normalizeValidationRules.js +11 -29
- package/lib/util/pathToString.js +0 -6
- package/lib/util/requestIdleCallback.js +30 -0
- package/lib/util/typeString.js +2 -5
- package/lib/validateDocument.js +140 -168
- package/lib/validators/arrayValidator.js +0 -27
- package/lib/validators/booleanValidator.js +0 -8
- package/lib/validators/dateValidator.js +8 -28
- package/lib/validators/genericValidator.js +2 -27
- package/lib/validators/numberValidator.js +0 -15
- package/lib/validators/objectValidator.js +1 -26
- package/lib/validators/slugValidator.js +5 -36
- package/lib/validators/stringValidator.js +3 -31
- package/package.json +6 -5
- package/src/index.ts +2 -0
- package/src/util/requestIdleCallback.ts +29 -0
- package/src/validateDocument.test.ts +0 -77
- package/src/validateDocument.ts +97 -60
|
@@ -4,29 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _normalizeValidationRules = _interopRequireDefault(require("./util/normalizeValidationRules"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
13
|
-
|
|
14
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
|
|
16
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
17
|
-
|
|
18
12
|
function traverse(typeDef, visited) {
|
|
19
13
|
if (visited.has(typeDef)) {
|
|
20
14
|
return;
|
|
21
15
|
}
|
|
22
|
-
|
|
23
16
|
visited.add(typeDef);
|
|
24
17
|
typeDef.validation = (0, _normalizeValidationRules.default)(typeDef);
|
|
25
|
-
|
|
26
18
|
if ('fields' in typeDef) {
|
|
27
19
|
var _iterator = _createForOfIteratorHelper(typeDef.fields),
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
_step;
|
|
30
21
|
try {
|
|
31
22
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
32
23
|
var field = _step.value;
|
|
@@ -38,11 +29,9 @@ function traverse(typeDef, visited) {
|
|
|
38
29
|
_iterator.f();
|
|
39
30
|
}
|
|
40
31
|
}
|
|
41
|
-
|
|
42
32
|
if ('of' in typeDef) {
|
|
43
33
|
var _iterator2 = _createForOfIteratorHelper(typeDef.of),
|
|
44
|
-
|
|
45
|
-
|
|
34
|
+
_step2;
|
|
46
35
|
try {
|
|
47
36
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
48
37
|
var candidate = _step2.value;
|
|
@@ -53,16 +42,15 @@ function traverse(typeDef, visited) {
|
|
|
53
42
|
} finally {
|
|
54
43
|
_iterator2.f();
|
|
55
44
|
}
|
|
56
|
-
}
|
|
57
|
-
// @ts-expect-error TODO (eventually): `annotations` does not exist on the SchemaType yet
|
|
58
|
-
|
|
45
|
+
}
|
|
59
46
|
|
|
47
|
+
// eslint-disable-next-line no-warning-comments
|
|
48
|
+
// @ts-expect-error TODO (eventually): `annotations` does not exist on the SchemaType yet
|
|
60
49
|
if (typeDef.annotations) {
|
|
61
50
|
// eslint-disable-next-line no-warning-comments
|
|
62
51
|
// @ts-expect-error TODO (eventually): `annotations` does not exist on the SchemaType yet
|
|
63
52
|
var _iterator3 = _createForOfIteratorHelper(typeDef.annotations),
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
_step3;
|
|
66
54
|
try {
|
|
67
55
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
68
56
|
var annotation = _step3.value;
|
|
@@ -74,13 +62,13 @@ function traverse(typeDef, visited) {
|
|
|
74
62
|
_iterator3.f();
|
|
75
63
|
}
|
|
76
64
|
}
|
|
77
|
-
}
|
|
65
|
+
}
|
|
78
66
|
|
|
67
|
+
// NOTE: this overload is for TS API compatibility with a previous implementation
|
|
79
68
|
|
|
80
69
|
function inferFromSchemaType(typeDef) {
|
|
81
70
|
traverse(typeDef, new Set());
|
|
82
71
|
return typeDef;
|
|
83
72
|
}
|
|
84
|
-
|
|
85
73
|
var _default = inferFromSchemaType;
|
|
86
74
|
exports.default = _default;
|
|
@@ -5,45 +5,36 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = convertToValidationMarker;
|
|
7
7
|
exports.isNonNullable = isNonNullable;
|
|
8
|
-
|
|
9
8
|
var _ValidationError = _interopRequireDefault(require("../ValidationError"));
|
|
10
|
-
|
|
11
9
|
var _pathToString = _interopRequireDefault(require("../util/pathToString"));
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
11
|
function isNonNullable(t) {
|
|
16
12
|
return t !== null || t !== undefined;
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
function convertToValidationMarker(validatorResult, level, context) {
|
|
20
15
|
var _validatorResult$path;
|
|
21
|
-
|
|
22
16
|
if (validatorResult === true) return [];
|
|
23
|
-
|
|
24
17
|
if (Array.isArray(validatorResult)) {
|
|
25
18
|
return validatorResult.flatMap(child => convertToValidationMarker(child, level, context)).filter(isNonNullable);
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
if (typeof validatorResult === 'string') {
|
|
29
21
|
return convertToValidationMarker(new _ValidationError.default(validatorResult), level, context);
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
if (!(validatorResult instanceof _ValidationError.default)) {
|
|
33
24
|
// in order to accept the `ValidationErrorLike`, it at least needs to have
|
|
34
25
|
// a `message` in the object
|
|
35
26
|
if (typeof (validatorResult === null || validatorResult === void 0 ? void 0 : validatorResult.message) !== 'string') {
|
|
36
27
|
throw new Error("".concat((0, _pathToString.default)(context.path), ": Validator must return 'true' if valid or an error message as a string on errors"));
|
|
37
|
-
}
|
|
38
|
-
// `ValidationErrorClass`. in this case, we want to convert it to a class
|
|
39
|
-
|
|
28
|
+
}
|
|
40
29
|
|
|
30
|
+
// this is the occurs when an object is returned that wasn't created with the
|
|
31
|
+
// `ValidationErrorClass`. in this case, we want to convert it to a class
|
|
41
32
|
return convertToValidationMarker(new _ValidationError.default(validatorResult.message, validatorResult), level, context);
|
|
42
33
|
}
|
|
34
|
+
var results = [];
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
// the validator result does not include any item-level relative paths,
|
|
45
37
|
// then just return the top-level path with the validation result
|
|
46
|
-
|
|
47
38
|
if (!((_validatorResult$path = validatorResult.paths) !== null && _validatorResult$path !== void 0 && _validatorResult$path.length)) {
|
|
48
39
|
return [{
|
|
49
40
|
type: 'validation',
|
|
@@ -51,11 +42,11 @@ function convertToValidationMarker(validatorResult, level, context) {
|
|
|
51
42
|
item: validatorResult,
|
|
52
43
|
path: context.path || []
|
|
53
44
|
}];
|
|
54
|
-
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// if the validator result did include item-level relative paths, then for
|
|
55
48
|
// each item-level relative path, create a validation marker that concatenates
|
|
56
49
|
// the relative path with the path from the validation context
|
|
57
|
-
|
|
58
|
-
|
|
59
50
|
return results.concat(validatorResult.paths.map(path => ({
|
|
60
51
|
type: 'validation',
|
|
61
52
|
path: (context.path || []).concat(path),
|
package/lib/util/deepEquals.js
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = deepEquals;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Modified version of fast-deep-equal (https://github.com/epoberezkin/fast-deep-equal)
|
|
10
9
|
* MIT-licensed, copyright (c) 2017 Evgeny Poberezkin
|
|
11
10
|
**/
|
|
11
|
+
|
|
12
12
|
// NOTE: when converting to typescript, some of the checks were inlined (vs
|
|
13
13
|
// having them in a variable) because the type predicate type narrowing only
|
|
14
14
|
// works when type predicate is called inline in the condition that starts the
|
|
@@ -18,70 +18,53 @@ function deepEquals(a, b) {
|
|
|
18
18
|
if (a === b) {
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
if (Array.isArray(a) && Array.isArray(b)) {
|
|
23
22
|
if (a.length != b.length) return false;
|
|
24
|
-
|
|
25
23
|
for (var i = 0; i < a.length; i++) {
|
|
26
24
|
if (!deepEquals(a[i], b[i])) {
|
|
27
25
|
return false;
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
return true;
|
|
32
29
|
}
|
|
33
|
-
|
|
34
30
|
if (Array.isArray(a) != Array.isArray(b)) {
|
|
35
31
|
return false;
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
39
34
|
var keys = Object.keys(a);
|
|
40
|
-
|
|
41
35
|
if (keys.length !== Object.keys(b).length) {
|
|
42
36
|
return false;
|
|
43
37
|
}
|
|
44
|
-
|
|
45
38
|
if (a instanceof Date && b instanceof Date) {
|
|
46
39
|
return a.getTime() === b.getTime();
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
if (a instanceof Date != b instanceof Date) {
|
|
50
42
|
return false;
|
|
51
43
|
}
|
|
52
|
-
|
|
53
44
|
if (a instanceof RegExp && b instanceof RegExp) {
|
|
54
45
|
return a.toString() == b.toString();
|
|
55
46
|
}
|
|
56
|
-
|
|
57
47
|
if (a instanceof RegExp != b instanceof RegExp) {
|
|
58
48
|
return false;
|
|
59
49
|
}
|
|
60
|
-
|
|
61
50
|
for (var _i = 0; _i < keys.length; _i++) {
|
|
62
51
|
if (keys[_i] === '_key') {
|
|
63
52
|
continue;
|
|
64
53
|
}
|
|
65
|
-
|
|
66
54
|
if (!Object.prototype.hasOwnProperty.call(b, keys[_i])) {
|
|
67
55
|
return false;
|
|
68
56
|
}
|
|
69
57
|
}
|
|
70
|
-
|
|
71
58
|
for (var _i2 = 0; _i2 < keys.length; _i2++) {
|
|
72
59
|
var key = keys[_i2];
|
|
73
|
-
|
|
74
60
|
if (key === '_key') {
|
|
75
61
|
continue;
|
|
76
62
|
}
|
|
77
|
-
|
|
78
63
|
if (!deepEquals(a[key], b[key])) {
|
|
79
64
|
return false;
|
|
80
65
|
}
|
|
81
66
|
}
|
|
82
|
-
|
|
83
67
|
return true;
|
|
84
68
|
}
|
|
85
|
-
|
|
86
69
|
return false;
|
|
87
70
|
}
|
package/lib/util/escapeRegex.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
/* eslint-disable no-useless-escape */
|
|
9
|
-
var _default = string => {
|
|
7
|
+
/* eslint-disable no-useless-escape */var _default = string => {
|
|
10
8
|
// Escape ^$.*+-?=!:|\/()[]{},
|
|
11
9
|
return string.replace(/[\^\$\.\*\+\-\?\=\!\:\|\\\/\(\)\[\]\{\}\,]/g, '\\$&');
|
|
12
10
|
};
|
|
13
|
-
|
|
14
11
|
exports.default = _default;
|
|
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = normalizeValidationRules;
|
|
7
|
-
|
|
8
7
|
var _Rule = _interopRequireDefault(require("../Rule"));
|
|
9
|
-
|
|
10
8
|
var _slugValidator = require("../validators/slugValidator");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
11
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
12
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
19
|
-
|
|
20
13
|
var ruleConstraintTypes = {
|
|
21
14
|
array: true,
|
|
22
15
|
boolean: true,
|
|
@@ -25,9 +18,7 @@ var ruleConstraintTypes = {
|
|
|
25
18
|
object: true,
|
|
26
19
|
string: true
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
var isRuleConstraint = typeString => typeString in ruleConstraintTypes;
|
|
30
|
-
|
|
31
22
|
function getTypeChain(type, visited) {
|
|
32
23
|
if (!type) return [];
|
|
33
24
|
if (visited.has(type)) return [];
|
|
@@ -35,24 +26,23 @@ function getTypeChain(type, visited) {
|
|
|
35
26
|
var next = type.type ? getTypeChain(type.type, visited) : [];
|
|
36
27
|
return [...next, type];
|
|
37
28
|
}
|
|
38
|
-
|
|
39
29
|
function baseRuleReducer(inputRule, type) {
|
|
40
30
|
var baseRule = inputRule;
|
|
41
|
-
|
|
42
31
|
if (isRuleConstraint(type.jsonType)) {
|
|
43
32
|
baseRule = baseRule.type(type.jsonType);
|
|
44
33
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
(type === null || type === void 0 ? void 0 : type.options) &&
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
var typeOptionsList =
|
|
35
|
+
// if type.options is truthy
|
|
36
|
+
(type === null || type === void 0 ? void 0 : type.options) &&
|
|
37
|
+
// and type.options is an object (non-null from the previous)
|
|
38
|
+
typeof type.options === 'object' &&
|
|
39
|
+
// and if `list` is in options
|
|
40
|
+
'list' in type.options &&
|
|
41
|
+
// then finally access the list
|
|
50
42
|
type.options.list;
|
|
51
|
-
|
|
52
43
|
if (Array.isArray(typeOptionsList)) {
|
|
53
44
|
baseRule = baseRule.valid(typeOptionsList.map(option => extractValueFromListOption(option, type)));
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
if (type.name === 'datetime') return baseRule.type('Date');
|
|
57
47
|
if (type.name === 'date') return baseRule.type('Date');
|
|
58
48
|
if (type.name === 'url') return baseRule.uri();
|
|
@@ -61,7 +51,6 @@ function baseRuleReducer(inputRule, type) {
|
|
|
61
51
|
if (type.name === 'email') return baseRule.email();
|
|
62
52
|
return baseRule;
|
|
63
53
|
}
|
|
64
|
-
|
|
65
54
|
function hasValueField(typeDef) {
|
|
66
55
|
if (!typeDef) return false;
|
|
67
56
|
if (!('fields' in typeDef) && typeDef.type) return hasValueField(typeDef.type);
|
|
@@ -69,7 +58,6 @@ function hasValueField(typeDef) {
|
|
|
69
58
|
if (!Array.isArray(typeDef.fields)) return false;
|
|
70
59
|
return typeDef.fields.some(field => field.name === 'value');
|
|
71
60
|
}
|
|
72
|
-
|
|
73
61
|
function extractValueFromListOption(option, typeDef) {
|
|
74
62
|
// If you define a `list` option with object items, where the item has a `value` field,
|
|
75
63
|
// we don't want to treat that as the value but rather the surrounding object
|
|
@@ -77,38 +65,32 @@ function extractValueFromListOption(option, typeDef) {
|
|
|
77
65
|
if (typeDef.jsonType === 'object' && hasValueField(typeDef)) return option;
|
|
78
66
|
return option.value === undefined ? option : option.value;
|
|
79
67
|
}
|
|
68
|
+
|
|
80
69
|
/**
|
|
81
70
|
* Takes in `SchemaValidationValue` and returns an array of `Rule` instances.
|
|
82
71
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
72
|
function normalizeValidationRules(typeDef) {
|
|
86
73
|
if (!typeDef) {
|
|
87
74
|
return [];
|
|
88
75
|
}
|
|
89
|
-
|
|
90
76
|
var validation = typeDef.validation;
|
|
91
|
-
|
|
92
77
|
if (Array.isArray(validation)) {
|
|
93
78
|
return validation.flatMap(i => normalizeValidationRules(_objectSpread(_objectSpread({}, typeDef), {}, {
|
|
94
79
|
validation: i
|
|
95
80
|
})));
|
|
96
81
|
}
|
|
97
|
-
|
|
98
82
|
if (validation instanceof _Rule.default) {
|
|
99
83
|
return [validation];
|
|
100
84
|
}
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
var baseRule =
|
|
86
|
+
// using an object + Object.values to de-dupe the type chain by type name
|
|
103
87
|
Object.values(getTypeChain(typeDef, new Set()).reduce((acc, type) => {
|
|
104
88
|
acc[type.name] = type;
|
|
105
89
|
return acc;
|
|
106
90
|
}, {})).reduce(baseRuleReducer, new _Rule.default(typeDef));
|
|
107
|
-
|
|
108
91
|
if (!validation) {
|
|
109
92
|
return [baseRule];
|
|
110
93
|
}
|
|
111
|
-
|
|
112
94
|
return normalizeValidationRules(_objectSpread(_objectSpread({}, typeDef), {}, {
|
|
113
95
|
validation: validation(baseRule)
|
|
114
96
|
}));
|
package/lib/util/pathToString.js
CHANGED
|
@@ -4,27 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = pathToString;
|
|
7
|
-
|
|
8
7
|
var _types = require("@sanity/types");
|
|
9
|
-
|
|
10
8
|
function pathToString() {
|
|
11
9
|
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
12
10
|
return path.reduce((target, segment, i) => {
|
|
13
11
|
var segmentType = typeof segment;
|
|
14
|
-
|
|
15
12
|
if (segmentType === 'number') {
|
|
16
13
|
return "".concat(target, "[").concat(segment, "]");
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
if (segmentType === 'string') {
|
|
20
16
|
var separator = i === 0 ? '' : '.';
|
|
21
17
|
return "".concat(target).concat(separator).concat(segment);
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
if ((0, _types.isKeyedObject)(segment)) {
|
|
25
20
|
return "".concat(target, "[_key==\"").concat(segment._key, "\"]");
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
throw new Error("Unsupported path segment \"".concat(segment, "\""));
|
|
29
23
|
}, '');
|
|
30
24
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.requestIdleCallback = exports.cancelIdleCallback = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Simple requestIdleCallback polyfill
|
|
9
|
+
* Can be removed when all browsers support requestIdleCallback: https://caniuse.com/requestidlecallback
|
|
10
|
+
* @param callback
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
var requestIdleCallbackShim = function requestIdleCallbackShim(callback, options) {
|
|
14
|
+
var start = Date.now();
|
|
15
|
+
return window.setTimeout(() => {
|
|
16
|
+
callback({
|
|
17
|
+
didTimeout: false,
|
|
18
|
+
timeRemaining() {
|
|
19
|
+
return Math.max(0, Date.now() - start);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}, 0);
|
|
23
|
+
};
|
|
24
|
+
var cancelIdleCallbackShim = function cancelIdleCallbackShim(handle) {
|
|
25
|
+
return window.clearTimeout(handle);
|
|
26
|
+
};
|
|
27
|
+
var requestIdleCallback = window.requestIdleCallback || requestIdleCallbackShim;
|
|
28
|
+
exports.requestIdleCallback = requestIdleCallback;
|
|
29
|
+
var cancelIdleCallback = window.cancelIdleCallback || cancelIdleCallbackShim;
|
|
30
|
+
exports.cancelIdleCallback = cancelIdleCallback;
|
package/lib/util/typeString.js
CHANGED
|
@@ -8,21 +8,18 @@ exports.default = typeString;
|
|
|
8
8
|
// https://github.com/stephenhandley/type-of-is/blob/7138a7e79f5af7c286bf8123f60843a91aaebf38/index.js
|
|
9
9
|
var _toString = {}.toString;
|
|
10
10
|
var builtIns = [Object, Function, Array, String, Boolean, Number, Date, RegExp, Error];
|
|
11
|
-
|
|
12
11
|
function isBuiltIn(_constructor) {
|
|
13
12
|
for (var i = 0; i < builtIns.length; i++) {
|
|
14
13
|
if (builtIns[i] === _constructor) return true;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
return false;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
function typeString(obj) {
|
|
21
18
|
// [object Blah] -> Blah
|
|
22
19
|
var stringType = _toString.call(obj).slice(8, -1);
|
|
20
|
+
if (obj === null || obj === undefined) return stringType.toLowerCase();
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
26
23
|
var constructorType = obj.constructor;
|
|
27
24
|
if (constructorType && !isBuiltIn(constructorType)) return constructorType.name;
|
|
28
25
|
return stringType;
|