@keeex/utils 7.0.2 → 7.1.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/lib/json.d.ts +6 -2
- package/lib/json.js +14 -1
- package/lib/promise.d.ts +4 -1
- package/lib/promise.js +8 -2
- package/lib/types/utils.d.ts +2 -0
- package/lib/types/utils.js +4 -3
- package/package.json +1 -1
- package/web/json.d.ts +6 -2
- package/web/json.js +12 -1
- package/web/promise.d.ts +4 -1
- package/web/promise.js +8 -2
- package/web/types/utils.d.ts +2 -0
- package/web/types/utils.js +3 -1
package/lib/json.d.ts
CHANGED
|
@@ -13,25 +13,28 @@
|
|
|
13
13
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
-
import
|
|
16
|
+
import * as types from "./types/types.js";
|
|
17
17
|
/**
|
|
18
18
|
* All the primitive types supported in a JSON file.
|
|
19
19
|
*
|
|
20
20
|
* @public
|
|
21
21
|
*/
|
|
22
22
|
export type JSONPrimitiveType = null | string | number | boolean;
|
|
23
|
+
export declare const isJsonPrimitiveType: (obj: unknown) => obj is JSONPrimitiveType;
|
|
23
24
|
/**
|
|
24
25
|
* All possible value type in a JSON file.
|
|
25
26
|
*
|
|
26
27
|
* @public
|
|
27
28
|
*/
|
|
28
29
|
export type JSONValueType = JSONPrimitiveType | JSONArray | JSONObject;
|
|
30
|
+
export declare const isJsonValueType: types.TypePredicate<JSONValueType>;
|
|
29
31
|
/**
|
|
30
32
|
* All supported arrays in a JSON files.
|
|
31
33
|
*
|
|
32
34
|
* @public
|
|
33
35
|
*/
|
|
34
36
|
export type JSONArray = Array<JSONValueType>;
|
|
37
|
+
export declare const isJsonArray: types.TypePredicate<JSONValueType[]>;
|
|
35
38
|
/**
|
|
36
39
|
* All supported objects in a JSON files.
|
|
37
40
|
*
|
|
@@ -40,12 +43,13 @@ export type JSONArray = Array<JSONValueType>;
|
|
|
40
43
|
export interface JSONObject {
|
|
41
44
|
[key: string]: JSONValueType;
|
|
42
45
|
}
|
|
46
|
+
export declare const isJsonObject: types.TypePredicate<Record<string, JSONValueType>>;
|
|
43
47
|
/**
|
|
44
48
|
* JSON.parse() with typed return.
|
|
45
49
|
*
|
|
46
50
|
* @public
|
|
47
51
|
*/
|
|
48
|
-
export declare const jsonParse: <T>(value: unknown, predicate?: TypePredicate<T>) => T;
|
|
52
|
+
export declare const jsonParse: <T>(value: unknown, predicate?: types.TypePredicate<T>) => T;
|
|
49
53
|
/**
|
|
50
54
|
* Do a JSON stringify operation with optional canonization of properties' order.
|
|
51
55
|
*
|
package/lib/json.js
CHANGED
|
@@ -13,6 +13,19 @@
|
|
|
13
13
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
+
import { makeArrayOfTypePredicate } from "./types/array.js";
|
|
17
|
+
import { makeKeyValueOfTypePredicate } from "./types/record.js";
|
|
18
|
+
import * as types from "./types/types.js";
|
|
19
|
+
export const isJsonPrimitiveType = (obj) => obj === null || typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean";
|
|
20
|
+
export const isJsonValueType = types.makeOrPredicate([
|
|
21
|
+
isJsonPrimitiveType,
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
23
|
+
(obj) => isJsonArray(obj),
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
25
|
+
(obj) => isJsonObject(obj),
|
|
26
|
+
]);
|
|
27
|
+
export const isJsonArray = makeArrayOfTypePredicate(isJsonValueType);
|
|
28
|
+
export const isJsonObject = makeKeyValueOfTypePredicate(isJsonValueType);
|
|
16
29
|
const JSON_DEFAULT_INDENT = 2;
|
|
17
30
|
/**
|
|
18
31
|
* JSON.parse() with typed return.
|
|
@@ -87,7 +100,7 @@ export const jsonStringify = (source, order = false, prettyIndent = false) => {
|
|
|
87
100
|
if (Array.isArray(source))
|
|
88
101
|
return processArray(source, prettyIndent);
|
|
89
102
|
const sourceType = typeof source;
|
|
90
|
-
if (["string", "number", "boolean"].includes(sourceType) || source === null) {
|
|
103
|
+
if (["string", "number", "boolean", "undefined"].includes(sourceType) || source === null) {
|
|
91
104
|
return JSON.stringify(source);
|
|
92
105
|
}
|
|
93
106
|
if (sourceType !== "object")
|
package/lib/promise.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
+
import { Awaitable } from "./types/types.js";
|
|
16
17
|
/**
|
|
17
18
|
* Create a promise that resolves after a given delay.
|
|
18
19
|
*
|
|
@@ -34,9 +35,11 @@ export type PromiseFunc<T> = () => Promise<T | void>;
|
|
|
34
35
|
* @public
|
|
35
36
|
*/
|
|
36
37
|
export declare const firstTruthy: <T>(promiseFuncs: Array<PromiseFunc<T>>) => Promise<T>;
|
|
38
|
+
type AwaitableFn<T> = () => Awaitable<T>;
|
|
37
39
|
/**
|
|
38
40
|
* Drop a promise and silence any exception.
|
|
39
41
|
*
|
|
40
42
|
* This is to be used *only* on dropped promises to explicitly silence any warning.
|
|
41
43
|
*/
|
|
42
|
-
export declare const dropPromise: <T>(promise:
|
|
44
|
+
export declare const dropPromise: <T>(promise: Awaitable<T> | AwaitableFn<T>) => void;
|
|
45
|
+
export {};
|
package/lib/promise.js
CHANGED
|
@@ -73,6 +73,12 @@ export const firstTruthy = async (promiseFuncs) => {
|
|
|
73
73
|
* This is to be used *only* on dropped promises to explicitly silence any warning.
|
|
74
74
|
*/
|
|
75
75
|
export const dropPromise = (promise) => {
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
if (typeof promise === "function") {
|
|
77
|
+
dropPromise(promise());
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (promise instanceof Promise) {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, promise/prefer-await-to-then
|
|
82
|
+
promise.catch(() => { });
|
|
83
|
+
}
|
|
78
84
|
};
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -14,5 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
16
|
import ms from "ms";
|
|
17
|
+
/** Check that the argument match the string portion of `ms()` */
|
|
18
|
+
export declare const isMsStringValue: import("./types.js").TypePredicate<ms.StringValue>;
|
|
17
19
|
/** Check that a value is suitable for input for `ms()` */
|
|
18
20
|
export declare const isMsInput: import("./types.js").TypePredicate<number | ms.StringValue>;
|
package/lib/types/utils.js
CHANGED
|
@@ -58,10 +58,11 @@ const msUnitAnyCase = Array.from(new Set([
|
|
|
58
58
|
const isMsStrInput = makeTemplatePredicate("${number}");
|
|
59
59
|
const isMsStrUnitPredicate = makeTemplatePredicate("${number}${msUnitAnyCase}", { msUnitAnyCase });
|
|
60
60
|
const isMsSpaceUnitPredicate = makeTemplatePredicate("${number} ${msUnitAnyCase}", { msUnitAnyCase });
|
|
61
|
-
/** Check that
|
|
62
|
-
export const
|
|
63
|
-
isNumber,
|
|
61
|
+
/** Check that the argument match the string portion of `ms()` */
|
|
62
|
+
export const isMsStringValue = makeOrPredicate([
|
|
64
63
|
isMsStrInput,
|
|
65
64
|
isMsStrUnitPredicate,
|
|
66
65
|
isMsSpaceUnitPredicate,
|
|
67
66
|
]);
|
|
67
|
+
/** Check that a value is suitable for input for `ms()` */
|
|
68
|
+
export const isMsInput = makeOrPredicate([isNumber, isMsStringValue]);
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@keeex/utils","version":"7.0
|
|
1
|
+
{"name":"@keeex/utils","version":"7.1.0","description":"Various utility functions for pure JavaScript","scripts":{},"author":"KeeeX SAS","contributors":[{"name":"Gabriel Paul \"Cley Faye\" Risterucci","email":"gabriel@keeex.net"}],"homepage":"https://keeex.me/oss","keywords":["utility"],"type":"module","license":"MIT","dependencies":{"@keeex/bubble_babble":"^3.0.1","@keeex/log":"^1.3.0","base64-arraybuffer":"^1.0.2","cron-parser":"^5.1.1","ms":"^2.1.3","text-encoding-shim":"^1.0.5"},"exports":{"./units.js":{"node":"./lib/units.js","browser":"./web/units.js","default":"./lib/units.js"},"./uint8array.js":{"node":"./lib/uint8array.js","browser":"./web/uint8array.js","default":"./lib/uint8array.js"},"./string.js":{"node":"./lib/string.js","browser":"./web/string.js","default":"./lib/string.js"},"./starttime.js":{"node":"./lib/starttime.js","browser":"./web/starttime.js","default":"./lib/starttime.js"},"./promise.js":{"node":"./lib/promise.js","browser":"./web/promise.js","default":"./lib/promise.js"},"./path.js":{"node":"./lib/path.js","browser":"./web/path.js","default":"./lib/path.js"},"./number.js":{"node":"./lib/number.js","browser":"./web/number.js","default":"./lib/number.js"},"./json.js":{"node":"./lib/json.js","browser":"./web/json.js","default":"./lib/json.js"},"./idx.js":{"node":"./lib/idx.js","browser":"./web/idx.js","default":"./lib/idx.js"},"./hex.js":{"node":"./lib/hex.js","browser":"./web/hex.js","default":"./lib/hex.js"},"./global.js":{"node":"./lib/global.js","browser":"./web/global.js","default":"./lib/global.js"},"./error.js":{"node":"./lib/error.js","browser":"./web/error.js","default":"./lib/error.js"},"./dict.js":{"node":"./lib/dict.js","browser":"./web/dict.js","default":"./lib/dict.js"},"./cron.js":{"node":"./lib/cron.js","browser":"./web/cron.js","default":"./lib/cron.js"},"./consts.js":{"node":"./lib/consts.js","browser":"./web/consts.js","default":"./lib/consts.js"},"./bytebuffer.js":{"node":"./lib/bytebuffer.js","browser":"./web/bytebuffer.js","default":"./lib/bytebuffer.js"},"./benchmark.js":{"node":"./lib/benchmark.js","browser":"./web/benchmark.js","default":"./lib/benchmark.js"},"./base64.js":{"node":"./lib/base64.js","browser":"./web/base64.js","default":"./lib/base64.js"},"./base58.js":{"node":"./lib/base58.js","browser":"./web/base58.js","default":"./lib/base58.js"},"./arraybuffer.js":{"node":"./lib/arraybuffer.js","browser":"./web/arraybuffer.js","default":"./lib/arraybuffer.js"},"./array.js":{"node":"./lib/array.js","browser":"./web/array.js","default":"./lib/array.js"},"./marshalling/unmarshaller.js":{"node":"./lib/marshalling/unmarshaller.js","browser":"./web/marshalling/unmarshaller.js","default":"./lib/marshalling/unmarshaller.js"},"./marshalling/marshaller.js":{"node":"./lib/marshalling/marshaller.js","browser":"./web/marshalling/marshaller.js","default":"./lib/marshalling/marshaller.js"},"./types/utils.js":{"node":"./lib/types/utils.js","browser":"./web/types/utils.js","default":"./lib/types/utils.js"},"./types/types.js":{"node":"./lib/types/types.js","browser":"./web/types/types.js","default":"./lib/types/types.js"},"./types/record.js":{"node":"./lib/types/record.js","browser":"./web/types/record.js","default":"./lib/types/record.js"},"./types/primitive.js":{"node":"./lib/types/primitive.js","browser":"./web/types/primitive.js","default":"./lib/types/primitive.js"},"./types/predicateerror.js":{"node":"./lib/types/predicateerror.js","browser":"./web/types/predicateerror.js","default":"./lib/types/predicateerror.js"},"./types/enum.js":{"node":"./lib/types/enum.js","browser":"./web/types/enum.js","default":"./lib/types/enum.js"},"./types/array.js":{"node":"./lib/types/array.js","browser":"./web/types/array.js","default":"./lib/types/array.js"},"./async/timecache.js":{"node":"./lib/async/timecache.js","browser":"./web/async/timecache.js","default":"./lib/async/timecache.js"},"./async/queues.js":{"node":"./lib/async/queues.js","browser":"./web/async/queues.js","default":"./lib/async/queues.js"},"./async/keycache.js":{"node":"./lib/async/keycache.js","browser":"./web/async/keycache.js","default":"./lib/async/keycache.js"},"./async/deferredpromise.js":{"node":"./lib/async/deferredpromise.js","browser":"./web/async/deferredpromise.js","default":"./lib/async/deferredpromise.js"},"./async/asynctrigger.js":{"node":"./lib/async/asynctrigger.js","browser":"./web/async/asynctrigger.js","default":"./lib/async/asynctrigger.js"}},"files":["/lib","/web"]}
|
package/web/json.d.ts
CHANGED
|
@@ -13,25 +13,28 @@
|
|
|
13
13
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
-
import
|
|
16
|
+
import * as types from "./types/types.js";
|
|
17
17
|
/**
|
|
18
18
|
* All the primitive types supported in a JSON file.
|
|
19
19
|
*
|
|
20
20
|
* @public
|
|
21
21
|
*/
|
|
22
22
|
export type JSONPrimitiveType = null | string | number | boolean;
|
|
23
|
+
export declare const isJsonPrimitiveType: (obj: unknown) => obj is JSONPrimitiveType;
|
|
23
24
|
/**
|
|
24
25
|
* All possible value type in a JSON file.
|
|
25
26
|
*
|
|
26
27
|
* @public
|
|
27
28
|
*/
|
|
28
29
|
export type JSONValueType = JSONPrimitiveType | JSONArray | JSONObject;
|
|
30
|
+
export declare const isJsonValueType: types.TypePredicate<JSONValueType>;
|
|
29
31
|
/**
|
|
30
32
|
* All supported arrays in a JSON files.
|
|
31
33
|
*
|
|
32
34
|
* @public
|
|
33
35
|
*/
|
|
34
36
|
export type JSONArray = Array<JSONValueType>;
|
|
37
|
+
export declare const isJsonArray: types.TypePredicate<JSONValueType[]>;
|
|
35
38
|
/**
|
|
36
39
|
* All supported objects in a JSON files.
|
|
37
40
|
*
|
|
@@ -40,12 +43,13 @@ export type JSONArray = Array<JSONValueType>;
|
|
|
40
43
|
export interface JSONObject {
|
|
41
44
|
[key: string]: JSONValueType;
|
|
42
45
|
}
|
|
46
|
+
export declare const isJsonObject: types.TypePredicate<Record<string, JSONValueType>>;
|
|
43
47
|
/**
|
|
44
48
|
* JSON.parse() with typed return.
|
|
45
49
|
*
|
|
46
50
|
* @public
|
|
47
51
|
*/
|
|
48
|
-
export declare const jsonParse: <T>(value: unknown, predicate?: TypePredicate<T>) => T;
|
|
52
|
+
export declare const jsonParse: <T>(value: unknown, predicate?: types.TypePredicate<T>) => T;
|
|
49
53
|
/**
|
|
50
54
|
* Do a JSON stringify operation with optional canonization of properties' order.
|
|
51
55
|
*
|
package/web/json.js
CHANGED
|
@@ -13,6 +13,17 @@
|
|
|
13
13
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
+
import { makeArrayOfTypePredicate } from "./types/array.js";
|
|
17
|
+
import { makeKeyValueOfTypePredicate } from "./types/record.js";
|
|
18
|
+
import * as types from "./types/types.js";
|
|
19
|
+
export const isJsonPrimitiveType = obj => obj === null || typeof obj === "string" || typeof obj === "number" || typeof obj === "boolean";
|
|
20
|
+
export const isJsonValueType = types.makeOrPredicate([isJsonPrimitiveType,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
22
|
+
obj => isJsonArray(obj),
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
24
|
+
obj => isJsonObject(obj)]);
|
|
25
|
+
export const isJsonArray = makeArrayOfTypePredicate(isJsonValueType);
|
|
26
|
+
export const isJsonObject = makeKeyValueOfTypePredicate(isJsonValueType);
|
|
16
27
|
const JSON_DEFAULT_INDENT = 2;
|
|
17
28
|
/**
|
|
18
29
|
* JSON.parse() with typed return.
|
|
@@ -77,7 +88,7 @@ export const jsonStringify = (source, order = false, prettyIndent = false) => {
|
|
|
77
88
|
}
|
|
78
89
|
if (Array.isArray(source)) return processArray(source, prettyIndent);
|
|
79
90
|
const sourceType = typeof source;
|
|
80
|
-
if (["string", "number", "boolean"].includes(sourceType) || source === null) {
|
|
91
|
+
if (["string", "number", "boolean", "undefined"].includes(sourceType) || source === null) {
|
|
81
92
|
return JSON.stringify(source);
|
|
82
93
|
}
|
|
83
94
|
if (sourceType !== "object") throw new Error("Invalid object input");
|
package/web/promise.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
+
import { Awaitable } from "./types/types.js";
|
|
16
17
|
/**
|
|
17
18
|
* Create a promise that resolves after a given delay.
|
|
18
19
|
*
|
|
@@ -34,9 +35,11 @@ export type PromiseFunc<T> = () => Promise<T | void>;
|
|
|
34
35
|
* @public
|
|
35
36
|
*/
|
|
36
37
|
export declare const firstTruthy: <T>(promiseFuncs: Array<PromiseFunc<T>>) => Promise<T>;
|
|
38
|
+
type AwaitableFn<T> = () => Awaitable<T>;
|
|
37
39
|
/**
|
|
38
40
|
* Drop a promise and silence any exception.
|
|
39
41
|
*
|
|
40
42
|
* This is to be used *only* on dropped promises to explicitly silence any warning.
|
|
41
43
|
*/
|
|
42
|
-
export declare const dropPromise: <T>(promise:
|
|
44
|
+
export declare const dropPromise: <T>(promise: Awaitable<T> | AwaitableFn<T>) => void;
|
|
45
|
+
export {};
|
package/web/promise.js
CHANGED
|
@@ -69,6 +69,12 @@ export const firstTruthy = async promiseFuncs => {
|
|
|
69
69
|
* This is to be used *only* on dropped promises to explicitly silence any warning.
|
|
70
70
|
*/
|
|
71
71
|
export const dropPromise = promise => {
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
if (typeof promise === "function") {
|
|
73
|
+
dropPromise(promise());
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (promise instanceof Promise) {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function, promise/prefer-await-to-then
|
|
78
|
+
promise.catch(() => {});
|
|
79
|
+
}
|
|
74
80
|
};
|
package/web/types/utils.d.ts
CHANGED
|
@@ -14,5 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
16
|
import ms from "ms";
|
|
17
|
+
/** Check that the argument match the string portion of `ms()` */
|
|
18
|
+
export declare const isMsStringValue: import("./types.js").TypePredicate<ms.StringValue>;
|
|
17
19
|
/** Check that a value is suitable for input for `ms()` */
|
|
18
20
|
export declare const isMsInput: import("./types.js").TypePredicate<number | ms.StringValue>;
|
package/web/types/utils.js
CHANGED
|
@@ -26,5 +26,7 @@ const isMsStrUnitPredicate = makeTemplatePredicate("${number}${msUnitAnyCase}",
|
|
|
26
26
|
const isMsSpaceUnitPredicate = makeTemplatePredicate("${number} ${msUnitAnyCase}", {
|
|
27
27
|
msUnitAnyCase
|
|
28
28
|
});
|
|
29
|
+
/** Check that the argument match the string portion of `ms()` */
|
|
30
|
+
export const isMsStringValue = makeOrPredicate([isMsStrInput, isMsStrUnitPredicate, isMsSpaceUnitPredicate]);
|
|
29
31
|
/** Check that a value is suitable for input for `ms()` */
|
|
30
|
-
export const isMsInput = makeOrPredicate([isNumber,
|
|
32
|
+
export const isMsInput = makeOrPredicate([isNumber, isMsStringValue]);
|