@leyyo/type 1.3.5 → 1.3.7
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/error/index.d.ts +17 -17
- package/dist/error/index.js +17 -17
- package/dist/error/invalid-array.error.js +5 -1
- package/dist/error/invalid-boolean.error.js +5 -1
- package/dist/error/invalid-date.error.js +1 -1
- package/dist/error/invalid-delimited.error.js +5 -1
- package/dist/error/invalid-enum-map.error.js +5 -1
- package/dist/error/invalid-enum-value.error.js +5 -1
- package/dist/error/invalid-integer.error.js +5 -1
- package/dist/error/invalid-list.error.js +1 -1
- package/dist/error/invalid-literal-items.error.js +5 -1
- package/dist/error/invalid-literal-value.error.js +5 -1
- package/dist/error/invalid-map.error.js +1 -1
- package/dist/error/invalid-number.error.js +5 -1
- package/dist/error/invalid-object.error.js +5 -1
- package/dist/error/invalid-real-value.error.js +5 -1
- package/dist/error/invalid-set.error.js +1 -1
- package/dist/error/invalid-string.error.js +5 -1
- package/dist/error/invalid-text.error.js +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.foretell.js +24 -24
- package/dist/index.js +6 -6
- package/dist/index.loader.js +2 -2
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +3 -2
- package/dist/is/index.d.ts +25 -25
- package/dist/is/index.js +25 -25
- package/dist/is/is-boolean-like.js +2 -2
- package/dist/is/is-false-like.js +1 -1
- package/dist/is/is-instance-of.js +1 -1
- package/dist/is/is-not-empty.js +1 -1
- package/dist/is/is-sys-class.js +1 -1
- package/dist/is/is-sys-function.js +1 -1
- package/dist/is/is-true-like.js +1 -1
- package/dist/is/is-type-of.d.ts +1 -1
- package/dist/is/is-valid-number.js +1 -1
- package/dist/literal/basic-type.js +11 -2
- package/dist/literal/defined-type.d.ts +1 -1
- package/dist/literal/defined-type.js +2 -2
- package/dist/literal/extended-type.js +22 -4
- package/dist/literal/false-weak.d.ts +1 -1
- package/dist/literal/false-weak.js +2 -2
- package/dist/literal/index.d.ts +7 -7
- package/dist/literal/index.js +7 -7
- package/dist/literal/sys-class.d.ts +1 -1
- package/dist/literal/sys-class.js +65 -15
- package/dist/literal/sys-function.d.ts +1 -1
- package/dist/literal/sys-function.js +20 -4
- package/dist/literal/true-weak.d.ts +1 -1
- package/dist/literal/true-weak.js +2 -2
- package/dist/to/index.d.ts +15 -15
- package/dist/to/index.js +15 -15
- package/dist/to/to-array-value.js +46 -42
- package/dist/to/to-boolean-value.js +13 -13
- package/dist/to/to-date-value.js +22 -20
- package/dist/to/to-delimited-value.js +15 -13
- package/dist/to/to-enum-value.js +22 -21
- package/dist/to/to-integer-value.js +14 -13
- package/dist/to/to-list-value.js +9 -8
- package/dist/to/to-literal-value.js +23 -22
- package/dist/to/to-map-value.js +44 -41
- package/dist/to/to-number-value.js +12 -12
- package/dist/to/to-object-value.js +26 -24
- package/dist/to/to-set-value.js +8 -8
- package/dist/to/to-string-value.js +14 -13
- package/dist/to/to-text-value.js +18 -16
- package/dist/to/util.js +18 -15
- package/package.json +20 -23
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import { literalPool } from "@leyyo/common";
|
|
2
2
|
import { FQN } from "../internal.js";
|
|
3
3
|
const literals = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
"string",
|
|
5
|
+
"object",
|
|
6
|
+
"number",
|
|
7
|
+
"boolean",
|
|
8
|
+
"function",
|
|
9
|
+
"symbol",
|
|
10
|
+
"bigint",
|
|
11
|
+
"undefined",
|
|
12
|
+
"array",
|
|
13
|
+
"null",
|
|
14
|
+
"enum-map",
|
|
15
|
+
"literal-items",
|
|
16
|
+
"class",
|
|
17
|
+
"empty",
|
|
18
|
+
"text",
|
|
19
|
+
"nan",
|
|
20
|
+
"integer",
|
|
21
|
+
"date",
|
|
22
|
+
"map",
|
|
23
|
+
"set",
|
|
24
|
+
"list",
|
|
7
25
|
];
|
|
8
26
|
/**
|
|
9
27
|
* JS Types with custom types
|
|
10
28
|
* */
|
|
11
29
|
export const ExtendedTypeItems = literals;
|
|
12
|
-
literalPool.define(FQN,
|
|
30
|
+
literalPool.define(FQN, "ExtendedType", ExtendedTypeItems, { i18n: true, aliases: [] });
|
|
@@ -2,6 +2,6 @@ declare const literals: readonly ["0", "-1", "false", "f", "no", "n", "off"];
|
|
|
2
2
|
/**
|
|
3
3
|
* Weak False
|
|
4
4
|
* */
|
|
5
|
-
export type FalseWeak = typeof literals[number];
|
|
5
|
+
export type FalseWeak = (typeof literals)[number];
|
|
6
6
|
export declare const FalseWeakItems: ReadonlyArray<FalseWeak>;
|
|
7
7
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { literalPool } from "@leyyo/common";
|
|
2
2
|
import { FQN } from "../internal.js";
|
|
3
|
-
const literals = [
|
|
3
|
+
const literals = ["0", "-1", "false", "f", "no", "n", "off"];
|
|
4
4
|
export const FalseWeakItems = literals;
|
|
5
|
-
literalPool.define(FQN,
|
|
5
|
+
literalPool.define(FQN, "FalseWeak", FalseWeakItems, { i18n: true, aliases: ["FalseLike"] });
|
package/dist/literal/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from "./basic-type.js";
|
|
2
|
+
export * from "./defined-type.js";
|
|
3
|
+
export * from "./extended-type.js";
|
|
4
|
+
export * from "./false-weak.js";
|
|
5
|
+
export * from "./sys-class.js";
|
|
6
|
+
export * from "./sys-function.js";
|
|
7
|
+
export * from "./true-weak.js";
|
package/dist/literal/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from "./basic-type.js";
|
|
2
|
+
export * from "./defined-type.js";
|
|
3
|
+
export * from "./extended-type.js";
|
|
4
|
+
export * from "./false-weak.js";
|
|
5
|
+
export * from "./sys-class.js";
|
|
6
|
+
export * from "./sys-function.js";
|
|
7
|
+
export * from "./true-weak.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare const literals: readonly ["Function", "Object", "Boolean", "Symbol", "Error", "AggregateError", "EvalError", "InternalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "Number", "BigInt", "Math", "Date", "String", "RegExp", "Array", "Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array", "Int32Array", "Uint32Array", "Float32Array", "Float64Array", "BigInt64Array", "BigUint64Array", "Map", "Set", "WeakMap", "WeakSet", "ArrayBuffer", "SharedArrayBuffer", "Atomics", "DataView", "JSON", "Promise", "Generator", "GeneratorFunction", "AsyncFunction", "AsyncGenerator", "AsyncGeneratorFunction", "Reflect", "Proxy", "Intl", "Intl.Collator", "Intl.DateTimeFormat", "Intl.ListFormat", "Intl.NumberFormat", "Intl.PluralRules", "Intl.RelativeTimeFormat", "Intl.Locale", "WebAssembly", "WebAssembly.Module", "WebAssembly.Instance", "WebAssembly.Memory", "WebAssembly.Table", "WebAssembly.CompileError", "WebAssembly.LinkError", "WebAssembly.RuntimeError"];
|
|
2
|
-
export type SysClass = typeof literals[number];
|
|
2
|
+
export type SysClass = (typeof literals)[number];
|
|
3
3
|
export declare const SysClassItems: ReadonlyArray<SysClass>;
|
|
4
4
|
export {};
|
|
@@ -1,20 +1,70 @@
|
|
|
1
1
|
import { literalPool } from "@leyyo/common";
|
|
2
2
|
import { FQN } from "../internal.js";
|
|
3
3
|
const literals = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
"Function",
|
|
5
|
+
"Object",
|
|
6
|
+
"Boolean",
|
|
7
|
+
"Symbol",
|
|
8
|
+
"Error",
|
|
9
|
+
"AggregateError",
|
|
10
|
+
"EvalError",
|
|
11
|
+
"InternalError",
|
|
12
|
+
"RangeError",
|
|
13
|
+
"ReferenceError",
|
|
14
|
+
"SyntaxError",
|
|
15
|
+
"TypeError",
|
|
16
|
+
"URIError",
|
|
17
|
+
`Number`,
|
|
18
|
+
`BigInt`,
|
|
19
|
+
`Math`,
|
|
20
|
+
`Date`,
|
|
21
|
+
"String",
|
|
22
|
+
"RegExp",
|
|
23
|
+
"Array",
|
|
24
|
+
"Int8Array",
|
|
25
|
+
"Uint8Array",
|
|
26
|
+
"Uint8ClampedArray",
|
|
27
|
+
"Int16Array",
|
|
28
|
+
"Uint16Array",
|
|
29
|
+
"Int32Array",
|
|
30
|
+
"Uint32Array",
|
|
31
|
+
"Float32Array",
|
|
32
|
+
"Float64Array",
|
|
33
|
+
"BigInt64Array",
|
|
34
|
+
"BigUint64Array",
|
|
35
|
+
"Map",
|
|
36
|
+
"Set",
|
|
37
|
+
"WeakMap",
|
|
38
|
+
"WeakSet",
|
|
39
|
+
"ArrayBuffer",
|
|
40
|
+
"SharedArrayBuffer",
|
|
41
|
+
"Atomics",
|
|
42
|
+
"DataView",
|
|
43
|
+
"JSON",
|
|
44
|
+
"Promise",
|
|
45
|
+
"Generator",
|
|
46
|
+
"GeneratorFunction",
|
|
47
|
+
"AsyncFunction",
|
|
48
|
+
"AsyncGenerator",
|
|
49
|
+
"AsyncGeneratorFunction",
|
|
50
|
+
"Reflect",
|
|
51
|
+
"Proxy",
|
|
52
|
+
"Intl",
|
|
53
|
+
"Intl.Collator",
|
|
54
|
+
"Intl.DateTimeFormat",
|
|
55
|
+
"Intl.ListFormat",
|
|
56
|
+
"Intl.NumberFormat",
|
|
57
|
+
"Intl.PluralRules",
|
|
58
|
+
"Intl.RelativeTimeFormat",
|
|
59
|
+
"Intl.Locale",
|
|
60
|
+
"WebAssembly",
|
|
61
|
+
"WebAssembly.Module",
|
|
62
|
+
"WebAssembly.Instance",
|
|
63
|
+
"WebAssembly.Memory",
|
|
64
|
+
"WebAssembly.Table",
|
|
65
|
+
"WebAssembly.CompileError",
|
|
66
|
+
"WebAssembly.LinkError",
|
|
67
|
+
"WebAssembly.RuntimeError",
|
|
18
68
|
];
|
|
19
69
|
export const SysClassItems = literals;
|
|
20
|
-
literalPool.define(FQN,
|
|
70
|
+
literalPool.define(FQN, "SysClass", SysClassItems, { i18n: true, aliases: ["SystemClass"] });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
declare const literals: readonly ["constructor", "__defineGetter__", "__defineSetter__", "hasOwnProperty", "__lookupGetter__", "__lookupSetter__", "isPrototypeOf", "propertyIsEnumerable", "toString", "valueOf", "__proto__", "toLocaleString", "toJSON", "__esModule"];
|
|
2
|
-
export type SysFunction = typeof literals[number];
|
|
2
|
+
export type SysFunction = (typeof literals)[number];
|
|
3
3
|
export declare const SysFunctionItems: ReadonlyArray<SysFunction>;
|
|
4
4
|
export {};
|
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { literalPool } from "@leyyo/common";
|
|
2
2
|
import { FQN } from "../internal.js";
|
|
3
|
-
const literals = [
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const literals = [
|
|
4
|
+
"constructor",
|
|
5
|
+
"__defineGetter__",
|
|
6
|
+
"__defineSetter__",
|
|
7
|
+
"hasOwnProperty",
|
|
8
|
+
"__lookupGetter__",
|
|
9
|
+
"__lookupSetter__",
|
|
10
|
+
"isPrototypeOf",
|
|
11
|
+
"propertyIsEnumerable",
|
|
12
|
+
"toString",
|
|
13
|
+
"valueOf",
|
|
14
|
+
"__proto__",
|
|
15
|
+
"toLocaleString",
|
|
16
|
+
"toJSON",
|
|
17
|
+
"__esModule",
|
|
18
|
+
];
|
|
6
19
|
export const SysFunctionItems = literals;
|
|
7
|
-
literalPool.define(FQN,
|
|
20
|
+
literalPool.define(FQN, "SysFunction", SysFunctionItems, {
|
|
21
|
+
i18n: true,
|
|
22
|
+
aliases: ["SystemFunction", "SystemFn", "SysFn"],
|
|
23
|
+
});
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Weak True
|
|
3
3
|
* */
|
|
4
4
|
declare const literals: readonly ["1", "true", "t", "yes", "y", "on"];
|
|
5
|
-
export type TrueWeak = typeof literals[number];
|
|
5
|
+
export type TrueWeak = (typeof literals)[number];
|
|
6
6
|
export declare const TrueWeakItems: ReadonlyArray<TrueWeak>;
|
|
7
7
|
export {};
|
|
@@ -3,6 +3,6 @@ import { FQN } from "../internal.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Weak True
|
|
5
5
|
* */
|
|
6
|
-
const literals = [
|
|
6
|
+
const literals = ["1", "true", "t", "yes", "y", "on"];
|
|
7
7
|
export const TrueWeakItems = literals;
|
|
8
|
-
literalPool.define(FQN,
|
|
8
|
+
literalPool.define(FQN, "TrueWeak", TrueWeakItems, { i18n: true, aliases: ["TrueLike"] });
|
package/dist/to/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./to-array-value.js";
|
|
3
|
+
export * from "./to-boolean-value.js";
|
|
4
|
+
export * from "./to-date-value.js";
|
|
5
|
+
export * from "./to-delimited-value.js";
|
|
6
|
+
export * from "./to-enum-value.js";
|
|
7
|
+
export * from "./to-integer-value.js";
|
|
8
|
+
export * from "./to-list-value.js";
|
|
9
|
+
export * from "./to-literal-value.js";
|
|
10
|
+
export * from "./to-map-value.js";
|
|
11
|
+
export * from "./to-number-value.js";
|
|
12
|
+
export * from "./to-object-value.js";
|
|
13
|
+
export * from "./to-set-value.js";
|
|
14
|
+
export * from "./to-string-value.js";
|
|
15
|
+
export * from "./to-text-value.js";
|
package/dist/to/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./to-array-value.js";
|
|
3
|
+
export * from "./to-boolean-value.js";
|
|
4
|
+
export * from "./to-date-value.js";
|
|
5
|
+
export * from "./to-delimited-value.js";
|
|
6
|
+
export * from "./to-enum-value.js";
|
|
7
|
+
export * from "./to-integer-value.js";
|
|
8
|
+
export * from "./to-list-value.js";
|
|
9
|
+
export * from "./to-literal-value.js";
|
|
10
|
+
export * from "./to-map-value.js";
|
|
11
|
+
export * from "./to-number-value.js";
|
|
12
|
+
export * from "./to-object-value.js";
|
|
13
|
+
export * from "./to-set-value.js";
|
|
14
|
+
export * from "./to-string-value.js";
|
|
15
|
+
export * from "./to-text-value.js";
|
|
@@ -9,56 +9,60 @@ import { InvalidArrayError } from "../error/index.js";
|
|
|
9
9
|
* @return {Array}
|
|
10
10
|
* */
|
|
11
11
|
export function toArrayValue(value, opt) {
|
|
12
|
-
|
|
12
|
+
const options = optCheck(opt);
|
|
13
13
|
if (isEmpty(value)) {
|
|
14
|
-
return _toEmpty(value,
|
|
14
|
+
return _toEmpty(value, options, InvalidArrayError, "array");
|
|
15
15
|
}
|
|
16
|
+
let clonedOptions;
|
|
16
17
|
switch (typeof value) {
|
|
17
18
|
case "string":
|
|
18
19
|
case "boolean":
|
|
19
20
|
case "number":
|
|
20
21
|
case "bigint":
|
|
21
|
-
|
|
22
|
-
delete
|
|
23
|
-
|
|
24
|
-
return toArrayValue([value],
|
|
25
|
-
case
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
clonedOptions = { ...options };
|
|
23
|
+
delete clonedOptions.nullable;
|
|
24
|
+
clonedOptions.nullable = clonedOptions.itemNullable;
|
|
25
|
+
return toArrayValue([value], clonedOptions);
|
|
26
|
+
case "object":
|
|
27
|
+
return _toArrayValue(value, options);
|
|
28
|
+
case "function":
|
|
29
|
+
return toArrayValue(_toRun(value, options, "function"), options);
|
|
30
|
+
}
|
|
31
|
+
return _toElse(value, options, InvalidArrayError, "array");
|
|
32
|
+
}
|
|
33
|
+
function _toArrayValue(value, options) {
|
|
34
|
+
if (value instanceof Set) {
|
|
35
|
+
return toArrayValue(Array.from(value.values()), options);
|
|
36
|
+
}
|
|
37
|
+
else if (value instanceof List) {
|
|
38
|
+
return toArrayValue([...value], options);
|
|
39
|
+
}
|
|
40
|
+
else if (Array.isArray(value)) {
|
|
41
|
+
if (value.length < 1) {
|
|
42
|
+
if (options.zeroLength) {
|
|
43
|
+
return [];
|
|
31
44
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
o2.field = oldField;
|
|
51
|
-
optField(o2, index);
|
|
52
|
-
const itemValue = _toRun(() => o2.itemFn(v, o2), o2, 'item');
|
|
53
|
-
if (!o.ignoreEmptyItems || !isEmpty(itemValue)) {
|
|
54
|
-
value.push(value);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return value;
|
|
45
|
+
return _toEmpty(value, options, InvalidArrayError, "array");
|
|
46
|
+
}
|
|
47
|
+
if (typeof options.itemFn !== "function" || value.length < 1) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
const clonedOptions = { ...options };
|
|
51
|
+
delete clonedOptions.nullable;
|
|
52
|
+
clonedOptions.nullable = clonedOptions.itemNullable;
|
|
53
|
+
const oldField = clonedOptions.field;
|
|
54
|
+
delete clonedOptions.field;
|
|
55
|
+
const clonedArr = [...value];
|
|
56
|
+
value.splice(0, value.length);
|
|
57
|
+
clonedArr.forEach((v, index) => {
|
|
58
|
+
clonedOptions.field = oldField;
|
|
59
|
+
optField(clonedOptions, index);
|
|
60
|
+
const itemValue = _toRun(() => clonedOptions.itemFn(v, clonedOptions), clonedOptions, "item");
|
|
61
|
+
if (!clonedOptions.ignoreEmptyItems || !isEmpty(itemValue)) {
|
|
62
|
+
value.push(value);
|
|
58
63
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return toArrayValue(_toRun(value, o, 'function'), o);
|
|
64
|
+
});
|
|
65
|
+
return value;
|
|
62
66
|
}
|
|
63
|
-
return
|
|
67
|
+
return toArrayValue([value], options);
|
|
64
68
|
}
|
|
@@ -13,14 +13,14 @@ import { InvalidBooleanError } from "../error/index.js";
|
|
|
13
13
|
export function toBooleanValue(value, opt) {
|
|
14
14
|
let o = optCheck(opt);
|
|
15
15
|
if (isEmpty(value)) {
|
|
16
|
-
return _toEmpty(value, o, InvalidBooleanError,
|
|
16
|
+
return _toEmpty(value, o, InvalidBooleanError, "boolean");
|
|
17
17
|
}
|
|
18
18
|
let err;
|
|
19
19
|
switch (typeof value) {
|
|
20
|
-
case
|
|
20
|
+
case "boolean":
|
|
21
21
|
return value;
|
|
22
|
-
case
|
|
23
|
-
case
|
|
22
|
+
case "string":
|
|
23
|
+
case "number":
|
|
24
24
|
if (isTrueLike(value)) {
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
@@ -28,12 +28,12 @@ export function toBooleanValue(value, opt) {
|
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
30
|
o = optAppend(o, {
|
|
31
|
-
issue:
|
|
32
|
-
expected:
|
|
33
|
-
type:
|
|
31
|
+
issue: "invalid",
|
|
32
|
+
expected: "boolean",
|
|
33
|
+
type: "string",
|
|
34
34
|
value,
|
|
35
35
|
});
|
|
36
|
-
err = new InvalidValueError(
|
|
36
|
+
err = new InvalidValueError("Invalid boolean like for text", o);
|
|
37
37
|
if (!o.silent) {
|
|
38
38
|
throw err;
|
|
39
39
|
}
|
|
@@ -41,14 +41,14 @@ export function toBooleanValue(value, opt) {
|
|
|
41
41
|
err.logWarn();
|
|
42
42
|
}
|
|
43
43
|
return undefined;
|
|
44
|
-
case
|
|
44
|
+
case "object":
|
|
45
45
|
if (Array.isArray(value) && value.length === 1) {
|
|
46
|
-
o.prev =
|
|
46
|
+
o.prev = "array";
|
|
47
47
|
return toBooleanValue(value[0], o);
|
|
48
48
|
}
|
|
49
49
|
break;
|
|
50
|
-
case
|
|
51
|
-
return toBooleanValue(_toRun(value, o,
|
|
50
|
+
case "function":
|
|
51
|
+
return toBooleanValue(_toRun(value, o, "function"), o);
|
|
52
52
|
}
|
|
53
|
-
return _toElse(value, o, InvalidBooleanError,
|
|
53
|
+
return _toElse(value, o, InvalidBooleanError, "boolean");
|
|
54
54
|
}
|
package/dist/to/to-date-value.js
CHANGED
|
@@ -10,42 +10,44 @@ import { InvalidDateError } from "../error/index.js";
|
|
|
10
10
|
* @return {Date}
|
|
11
11
|
* */
|
|
12
12
|
export function toDateValue(value, opt) {
|
|
13
|
-
|
|
13
|
+
const o = optCheck(opt);
|
|
14
14
|
if (isEmpty(value)) {
|
|
15
|
-
return _toEmpty(value, o, InvalidDateError,
|
|
15
|
+
return _toEmpty(value, o, InvalidDateError, "date");
|
|
16
16
|
}
|
|
17
|
+
let arr;
|
|
18
|
+
let str;
|
|
17
19
|
switch (typeof value) {
|
|
18
|
-
case
|
|
20
|
+
case "object":
|
|
19
21
|
if (value instanceof Date) {
|
|
20
22
|
return value;
|
|
21
23
|
}
|
|
22
|
-
else if (typeof value[
|
|
23
|
-
return toDateValue(_toRun(value[
|
|
24
|
+
else if (typeof value["toDateValue"] === "function") {
|
|
25
|
+
return toDateValue(_toRun(value["toDateValue"], o, "moment"), o);
|
|
24
26
|
}
|
|
25
27
|
if (Array.isArray(value)) {
|
|
26
|
-
|
|
28
|
+
arr = value;
|
|
27
29
|
if (arr.length === 1) {
|
|
28
|
-
o.prev =
|
|
30
|
+
o.prev = "integer";
|
|
29
31
|
return toDateValue(arr[0], o);
|
|
30
32
|
}
|
|
31
33
|
if (arr.length > 1 && arr.length < 8) {
|
|
32
34
|
const [year, monthIndex, date, hours, minutes, seconds, ms] = arr;
|
|
33
|
-
return _toRun(() => new Date(year, monthIndex, date, hours, minutes, seconds, ms), o,
|
|
35
|
+
return _toRun(() => new Date(year, monthIndex, date, hours, minutes, seconds, ms), o, "array");
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
break;
|
|
37
|
-
case
|
|
38
|
-
|
|
39
|
-
if (str
|
|
40
|
-
return _toEmpty(value, o, InvalidDateError,
|
|
39
|
+
case "string":
|
|
40
|
+
str = value.trim();
|
|
41
|
+
if (!str) {
|
|
42
|
+
return _toEmpty(value, o, InvalidDateError, "date");
|
|
41
43
|
}
|
|
42
|
-
return toDateValue(_toRun(() => new Date(str), o,
|
|
43
|
-
case
|
|
44
|
-
return toDateValue(_toRun(() => new Date(value.toString(10)), o,
|
|
45
|
-
case
|
|
46
|
-
return toDateValue(_toRun(() => new Date(value), o,
|
|
47
|
-
case
|
|
48
|
-
return toDateValue(_toRun(value, o,
|
|
44
|
+
return toDateValue(_toRun(() => new Date(str), o, "string"), o);
|
|
45
|
+
case "bigint":
|
|
46
|
+
return toDateValue(_toRun(() => new Date(value.toString(10)), o, "bigint"), o);
|
|
47
|
+
case "number":
|
|
48
|
+
return toDateValue(_toRun(() => new Date(value), o, "number"), o);
|
|
49
|
+
case "function":
|
|
50
|
+
return toDateValue(_toRun(value, o, "function"), o);
|
|
49
51
|
}
|
|
50
|
-
return _toElse(value, o, InvalidDateError,
|
|
52
|
+
return _toElse(value, o, InvalidDateError, "date", "string", "integer");
|
|
51
53
|
}
|
|
@@ -11,29 +11,31 @@ import { InvalidDelimitedError } from "../error/index.js";
|
|
|
11
11
|
* @return {Array}
|
|
12
12
|
* */
|
|
13
13
|
export function toDelimitedValue(value, opt) {
|
|
14
|
-
|
|
14
|
+
const o = optCheck(opt);
|
|
15
15
|
if (isEmpty(value)) {
|
|
16
|
-
return _toEmpty(value, o, InvalidDelimitedError,
|
|
16
|
+
return _toEmpty(value, o, InvalidDelimitedError, "string");
|
|
17
17
|
}
|
|
18
|
+
let str;
|
|
19
|
+
let arr;
|
|
18
20
|
switch (typeof value) {
|
|
19
21
|
case "string":
|
|
20
|
-
|
|
21
|
-
if (str
|
|
22
|
-
return _toEmpty(value, o, InvalidDelimitedError,
|
|
22
|
+
str = value.trim();
|
|
23
|
+
if (!str) {
|
|
24
|
+
return _toEmpty(value, o, InvalidDelimitedError, "string");
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
.split(
|
|
26
|
-
.map(v => v.trim())
|
|
27
|
-
.filter(
|
|
26
|
+
arr = str
|
|
27
|
+
.split(",")
|
|
28
|
+
.map((v) => v.trim())
|
|
29
|
+
.filter(Boolean);
|
|
28
30
|
return toArrayValue(arr, o);
|
|
29
31
|
case "boolean":
|
|
30
32
|
case "number":
|
|
31
33
|
case "bigint":
|
|
32
34
|
return toArrayValue([value], o);
|
|
33
|
-
case
|
|
35
|
+
case "object":
|
|
34
36
|
return toArrayValue(value, o);
|
|
35
|
-
case
|
|
36
|
-
return toDelimitedValue(_toRun(value, o,
|
|
37
|
+
case "function":
|
|
38
|
+
return toDelimitedValue(_toRun(value, o, "function"), o);
|
|
37
39
|
}
|
|
38
|
-
return _toElse(value, o, InvalidDelimitedError,
|
|
40
|
+
return _toElse(value, o, InvalidDelimitedError, "string");
|
|
39
41
|
}
|