@searchspring/snap-toolbox 0.47.0 → 0.49.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/cjs/charsParams/charsParams.d.ts +1 -1
- package/dist/cjs/charsParams/charsParams.d.ts.map +1 -1
- package/dist/cjs/charsParams/charsParams.js +7 -1
- package/dist/cjs/until/until.d.ts +10 -0
- package/dist/cjs/until/until.d.ts.map +1 -0
- package/dist/cjs/until/until.js +123 -0
- package/dist/esm/charsParams/charsParams.d.ts +1 -1
- package/dist/esm/charsParams/charsParams.d.ts.map +1 -1
- package/dist/esm/charsParams/charsParams.js +7 -1
- package/dist/esm/until/until.d.ts +10 -0
- package/dist/esm/until/until.d.ts.map +1 -0
- package/dist/esm/until/until.js +53 -0
- package/package.json +2 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare type ParameterObject = Record<string, boolean | string | string[] | number | number[]>;
|
|
1
|
+
export declare type ParameterObject = Record<string, boolean | string | string[] | number | number[] | unknown>;
|
|
2
2
|
export declare function charsParams(params: ParameterObject): number;
|
|
3
3
|
//# sourceMappingURL=charsParams.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"charsParams.d.ts","sourceRoot":"","sources":["../../../src/charsParams/charsParams.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"charsParams.d.ts","sourceRoot":"","sources":["../../../src/charsParams/charsParams.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;AAExG,wBAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAwB3D"}
|
|
@@ -14,9 +14,15 @@ function charsParams(params) {
|
|
|
14
14
|
return length + keyLength + 1 + ('' + val).length;
|
|
15
15
|
}, 0));
|
|
16
16
|
}
|
|
17
|
-
else {
|
|
17
|
+
else if (typeof value == 'object') {
|
|
18
|
+
//recursive check
|
|
19
|
+
return count + keyLength + 1 + charsParams(value);
|
|
20
|
+
}
|
|
21
|
+
else if (typeof value == 'string' || typeof value == 'number') {
|
|
18
22
|
return count + keyLength + 1 + ('' + value).length;
|
|
19
23
|
}
|
|
24
|
+
else
|
|
25
|
+
return count + keyLength;
|
|
20
26
|
}, 1);
|
|
21
27
|
return count;
|
|
22
28
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare type UntilOptions = {
|
|
2
|
+
checkMax: number;
|
|
3
|
+
checkCount: number;
|
|
4
|
+
checkTime: number;
|
|
5
|
+
exponential: number;
|
|
6
|
+
defer: boolean;
|
|
7
|
+
executeFunction: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const until: (thing: unknown, customOptions?: Partial<UntilOptions> | undefined) => Promise<unknown>;
|
|
10
|
+
//# sourceMappingURL=until.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../../src/until/until.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;CACzB,CAAC;AAWF,eAAO,MAAM,KAAK,UAAiB,OAAO,wDAA0C,QAAQ,OAAO,CA8ClG,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.until = void 0;
|
|
51
|
+
var defaultUntilOptions = {
|
|
52
|
+
checkMax: 25,
|
|
53
|
+
checkCount: 0,
|
|
54
|
+
checkTime: 60,
|
|
55
|
+
exponential: 1.1,
|
|
56
|
+
defer: false,
|
|
57
|
+
executeFunction: true,
|
|
58
|
+
};
|
|
59
|
+
var until = function (thing, customOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
+
var options;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
options = __assign(__assign({}, defaultUntilOptions), (customOptions || {}));
|
|
63
|
+
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
+
var checkForThing, thingCheck, waiting_1;
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
switch (_a.label) {
|
|
67
|
+
case 0:
|
|
68
|
+
checkForThing = function (thing) { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
switch (typeof thing) {
|
|
71
|
+
case 'function': {
|
|
72
|
+
if (options.executeFunction) {
|
|
73
|
+
return [2 /*return*/, thing()];
|
|
74
|
+
}
|
|
75
|
+
return [2 /*return*/, thing];
|
|
76
|
+
}
|
|
77
|
+
default: {
|
|
78
|
+
if (thing) {
|
|
79
|
+
return [2 /*return*/, thing];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
});
|
|
85
|
+
}); };
|
|
86
|
+
return [4 /*yield*/, checkForThing(thing)];
|
|
87
|
+
case 1:
|
|
88
|
+
thingCheck = _a.sent();
|
|
89
|
+
if (thingCheck && !options.defer) {
|
|
90
|
+
resolve(thingCheck);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
waiting_1 = function () {
|
|
94
|
+
window === null || window === void 0 ? void 0 : window.setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
95
|
+
var thingCheck;
|
|
96
|
+
return __generator(this, function (_a) {
|
|
97
|
+
switch (_a.label) {
|
|
98
|
+
case 0: return [4 /*yield*/, checkForThing(thing)];
|
|
99
|
+
case 1:
|
|
100
|
+
thingCheck = _a.sent();
|
|
101
|
+
if (thingCheck) {
|
|
102
|
+
return [2 /*return*/, resolve(thingCheck)];
|
|
103
|
+
}
|
|
104
|
+
options.checkCount++;
|
|
105
|
+
options.checkTime *= options.exponential;
|
|
106
|
+
if (options.checkCount < options.checkMax) {
|
|
107
|
+
return [2 /*return*/, waiting_1()];
|
|
108
|
+
}
|
|
109
|
+
// timeout reached
|
|
110
|
+
return [2 /*return*/, reject()];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}); }, options.checkTime);
|
|
114
|
+
};
|
|
115
|
+
waiting_1();
|
|
116
|
+
}
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}); })];
|
|
121
|
+
});
|
|
122
|
+
}); };
|
|
123
|
+
exports.until = until;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare type ParameterObject = Record<string, boolean | string | string[] | number | number[]>;
|
|
1
|
+
export declare type ParameterObject = Record<string, boolean | string | string[] | number | number[] | unknown>;
|
|
2
2
|
export declare function charsParams(params: ParameterObject): number;
|
|
3
3
|
//# sourceMappingURL=charsParams.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"charsParams.d.ts","sourceRoot":"","sources":["../../../src/charsParams/charsParams.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"charsParams.d.ts","sourceRoot":"","sources":["../../../src/charsParams/charsParams.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;AAExG,wBAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAwB3D"}
|
|
@@ -11,9 +11,15 @@ export function charsParams(params) {
|
|
|
11
11
|
return length + keyLength + 1 + ('' + val).length;
|
|
12
12
|
}, 0));
|
|
13
13
|
}
|
|
14
|
-
else {
|
|
14
|
+
else if (typeof value == 'object') {
|
|
15
|
+
//recursive check
|
|
16
|
+
return count + keyLength + 1 + charsParams(value);
|
|
17
|
+
}
|
|
18
|
+
else if (typeof value == 'string' || typeof value == 'number') {
|
|
15
19
|
return count + keyLength + 1 + ('' + value).length;
|
|
16
20
|
}
|
|
21
|
+
else
|
|
22
|
+
return count + keyLength;
|
|
17
23
|
}, 1);
|
|
18
24
|
return count;
|
|
19
25
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare type UntilOptions = {
|
|
2
|
+
checkMax: number;
|
|
3
|
+
checkCount: number;
|
|
4
|
+
checkTime: number;
|
|
5
|
+
exponential: number;
|
|
6
|
+
defer: boolean;
|
|
7
|
+
executeFunction: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare const until: (thing: unknown, customOptions?: Partial<UntilOptions> | undefined) => Promise<unknown>;
|
|
10
|
+
//# sourceMappingURL=until.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"until.d.ts","sourceRoot":"","sources":["../../../src/until/until.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;IACf,eAAe,EAAE,OAAO,CAAC;CACzB,CAAC;AAWF,eAAO,MAAM,KAAK,UAAiB,OAAO,wDAA0C,QAAQ,OAAO,CA8ClG,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const defaultUntilOptions = {
|
|
2
|
+
checkMax: 25,
|
|
3
|
+
checkCount: 0,
|
|
4
|
+
checkTime: 60,
|
|
5
|
+
exponential: 1.1,
|
|
6
|
+
defer: false,
|
|
7
|
+
executeFunction: true,
|
|
8
|
+
};
|
|
9
|
+
export const until = async (thing, customOptions) => {
|
|
10
|
+
const options = {
|
|
11
|
+
...defaultUntilOptions,
|
|
12
|
+
...(customOptions || {}),
|
|
13
|
+
};
|
|
14
|
+
return new Promise(async (resolve, reject) => {
|
|
15
|
+
const checkForThing = async (thing) => {
|
|
16
|
+
switch (typeof thing) {
|
|
17
|
+
case 'function': {
|
|
18
|
+
if (options.executeFunction) {
|
|
19
|
+
return thing();
|
|
20
|
+
}
|
|
21
|
+
return thing;
|
|
22
|
+
}
|
|
23
|
+
default: {
|
|
24
|
+
if (thing) {
|
|
25
|
+
return thing;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const thingCheck = await checkForThing(thing);
|
|
31
|
+
if (thingCheck && !options.defer) {
|
|
32
|
+
resolve(thingCheck);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const waiting = () => {
|
|
36
|
+
window?.setTimeout(async () => {
|
|
37
|
+
const thingCheck = await checkForThing(thing);
|
|
38
|
+
if (thingCheck) {
|
|
39
|
+
return resolve(thingCheck);
|
|
40
|
+
}
|
|
41
|
+
options.checkCount++;
|
|
42
|
+
options.checkTime *= options.exponential;
|
|
43
|
+
if (options.checkCount < options.checkMax) {
|
|
44
|
+
return waiting();
|
|
45
|
+
}
|
|
46
|
+
// timeout reached
|
|
47
|
+
return reject();
|
|
48
|
+
}, options.checkTime);
|
|
49
|
+
};
|
|
50
|
+
waiting();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@searchspring/snap-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.0",
|
|
4
4
|
"description": "Snap Toolbox",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"files": [
|
|
24
24
|
"dist/**/*"
|
|
25
25
|
],
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "29db25460668f3c53e07942c62de4d9c82c051a1"
|
|
27
27
|
}
|