@leyyo/type 1.3.6 → 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/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
|
@@ -10,21 +10,22 @@ import { InvalidStringError } from "../error/index.js";
|
|
|
10
10
|
* @return {string}
|
|
11
11
|
* */
|
|
12
12
|
export function toStringValue(value, opt) {
|
|
13
|
-
|
|
13
|
+
const o = optCheck(opt);
|
|
14
14
|
if (isEmpty(value)) {
|
|
15
|
-
return _toEmpty(value, o, InvalidStringError,
|
|
15
|
+
return _toEmpty(value, o, InvalidStringError, "string");
|
|
16
16
|
}
|
|
17
|
+
let num;
|
|
17
18
|
switch (typeof value) {
|
|
18
|
-
case
|
|
19
|
+
case "string":
|
|
19
20
|
return value;
|
|
20
|
-
case
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
case
|
|
21
|
+
case "number":
|
|
22
|
+
num = _realNumber(value, o);
|
|
23
|
+
return num !== undefined ? num.toString(10) : undefined;
|
|
24
|
+
case "bigint":
|
|
24
25
|
return value.toString();
|
|
25
|
-
case
|
|
26
|
-
return value ?
|
|
27
|
-
case
|
|
26
|
+
case "boolean":
|
|
27
|
+
return value ? "true" : "false";
|
|
28
|
+
case "object":
|
|
28
29
|
if (Array.isArray(value) && value.length === 1) {
|
|
29
30
|
return toStringValue(value[0], o);
|
|
30
31
|
}
|
|
@@ -32,8 +33,8 @@ export function toStringValue(value, opt) {
|
|
|
32
33
|
return toStringValue(value.id, o);
|
|
33
34
|
}
|
|
34
35
|
break;
|
|
35
|
-
case
|
|
36
|
-
return toStringValue(_toRun(value, o,
|
|
36
|
+
case "function":
|
|
37
|
+
return toStringValue(_toRun(value, o, "function"), o);
|
|
37
38
|
}
|
|
38
|
-
return _toElse(value, o, InvalidStringError,
|
|
39
|
+
return _toElse(value, o, InvalidStringError, "string");
|
|
39
40
|
}
|
package/dist/to/to-text-value.js
CHANGED
|
@@ -10,25 +10,27 @@ import { InvalidTextError } from "../error/index.js";
|
|
|
10
10
|
* @return {string}
|
|
11
11
|
* */
|
|
12
12
|
export function toTextValue(value, opt) {
|
|
13
|
-
|
|
13
|
+
const o = optCheck(opt);
|
|
14
14
|
if (isEmpty(value)) {
|
|
15
|
-
return _toEmpty(value, o, InvalidTextError,
|
|
15
|
+
return _toEmpty(value, o, InvalidTextError, "string");
|
|
16
16
|
}
|
|
17
|
+
let str;
|
|
18
|
+
let num;
|
|
17
19
|
switch (typeof value) {
|
|
18
|
-
case
|
|
19
|
-
|
|
20
|
-
if (str
|
|
21
|
-
return _toEmpty(value, { ...o, textCase:
|
|
20
|
+
case "string":
|
|
21
|
+
str = value.trim();
|
|
22
|
+
if (!str) {
|
|
23
|
+
return _toEmpty(value, { ...o, textCase: "empty" }, InvalidTextError, "string");
|
|
22
24
|
}
|
|
23
25
|
return str;
|
|
24
|
-
case
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
case
|
|
26
|
+
case "number":
|
|
27
|
+
num = _realNumber(value, o);
|
|
28
|
+
return num !== undefined ? num.toString(10) : undefined;
|
|
29
|
+
case "bigint":
|
|
28
30
|
return value.toString();
|
|
29
|
-
case
|
|
30
|
-
return value ?
|
|
31
|
-
case
|
|
31
|
+
case "boolean":
|
|
32
|
+
return value ? "true" : "false";
|
|
33
|
+
case "object":
|
|
32
34
|
if (Array.isArray(value) && value.length === 1) {
|
|
33
35
|
return toTextValue(value[0], o);
|
|
34
36
|
}
|
|
@@ -36,8 +38,8 @@ export function toTextValue(value, opt) {
|
|
|
36
38
|
return toTextValue(value.id, o);
|
|
37
39
|
}
|
|
38
40
|
break;
|
|
39
|
-
case
|
|
40
|
-
return toTextValue(_toRun(value, o,
|
|
41
|
+
case "function":
|
|
42
|
+
return toTextValue(_toRun(value, o, "function"), o);
|
|
41
43
|
}
|
|
42
|
-
return _toElse(value, o, InvalidTextError,
|
|
44
|
+
return _toElse(value, o, InvalidTextError, "string");
|
|
43
45
|
}
|
package/dist/to/util.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { errorCommon, extendedType, optAdd, optAppend } from "@leyyo/common";
|
|
1
|
+
import { errorCommon, extendedType, optAdd, optAppend, } from "@leyyo/common";
|
|
2
2
|
import { InvalidRealValueError } from "../error/index.js";
|
|
3
3
|
export function _toRun(fn, opt, callback) {
|
|
4
4
|
try {
|
|
@@ -6,7 +6,7 @@ export function _toRun(fn, opt, callback) {
|
|
|
6
6
|
}
|
|
7
7
|
catch (e) {
|
|
8
8
|
const err = errorCommon.cast(e, opt);
|
|
9
|
-
err.params = optAppend(err.params, { issue:
|
|
9
|
+
err.params = optAppend(err.params, { issue: "unexpected", callback });
|
|
10
10
|
if (!opt.silent) {
|
|
11
11
|
throw err;
|
|
12
12
|
}
|
|
@@ -17,9 +17,9 @@ export function _toRun(fn, opt, callback) {
|
|
|
17
17
|
export function _toEmpty(value, opt, clazz, expected) {
|
|
18
18
|
if (!opt.nullable && !opt.silent) {
|
|
19
19
|
opt = optAppend(opt, {
|
|
20
|
-
issue:
|
|
20
|
+
issue: "empty",
|
|
21
21
|
expected,
|
|
22
|
-
type: extendedType(value)
|
|
22
|
+
type: extendedType(value),
|
|
23
23
|
});
|
|
24
24
|
throw new clazz(expected, opt);
|
|
25
25
|
}
|
|
@@ -28,10 +28,10 @@ export function _toEmpty(value, opt, clazz, expected) {
|
|
|
28
28
|
export function _toElse(value, opt, clazz, ...expected) {
|
|
29
29
|
if (!opt.silent) {
|
|
30
30
|
opt = optAppend(opt, {
|
|
31
|
-
issue:
|
|
31
|
+
issue: "invalid",
|
|
32
32
|
expected: new Set(expected),
|
|
33
33
|
value,
|
|
34
|
-
type: typeof value
|
|
34
|
+
type: typeof value,
|
|
35
35
|
});
|
|
36
36
|
throw new clazz(expected, opt);
|
|
37
37
|
}
|
|
@@ -39,14 +39,14 @@ export function _toElse(value, opt, clazz, ...expected) {
|
|
|
39
39
|
}
|
|
40
40
|
export function _realNumber(value, opt) {
|
|
41
41
|
if (isNaN(value)) {
|
|
42
|
-
opt = optAdd(opt,
|
|
42
|
+
opt = optAdd(opt, "issue", "nan");
|
|
43
43
|
if (!opt.silent) {
|
|
44
44
|
throw new InvalidRealValueError(`Value should be real value, but it's NaN`, opt);
|
|
45
45
|
}
|
|
46
46
|
return undefined;
|
|
47
47
|
}
|
|
48
48
|
if (!isFinite(value)) {
|
|
49
|
-
opt = optAdd(opt,
|
|
49
|
+
opt = optAdd(opt, "issue", "finite");
|
|
50
50
|
if (!opt.silent) {
|
|
51
51
|
throw new InvalidRealValueError(`Value should be real value, but it's finite`, opt);
|
|
52
52
|
}
|
|
@@ -56,7 +56,7 @@ export function _realNumber(value, opt) {
|
|
|
56
56
|
}
|
|
57
57
|
export function _safeInteger(value, opt) {
|
|
58
58
|
if (!Number.isSafeInteger(value)) {
|
|
59
|
-
opt = optAdd(opt,
|
|
59
|
+
opt = optAdd(opt, "issue", "not:safe");
|
|
60
60
|
if (!opt.silent) {
|
|
61
61
|
throw new InvalidRealValueError(`Value should be real value, but it's not safe integer`, opt);
|
|
62
62
|
}
|
|
@@ -73,7 +73,7 @@ export function _inEnumMap(value, map) {
|
|
|
73
73
|
if (Object.keys(map).includes(value)) {
|
|
74
74
|
return map[value];
|
|
75
75
|
}
|
|
76
|
-
if (typeof value ===
|
|
76
|
+
if (typeof value === "string") {
|
|
77
77
|
// regular, in lower-case
|
|
78
78
|
let str = value.toLowerCase();
|
|
79
79
|
let v = _inEnumMap(str, map);
|
|
@@ -90,7 +90,8 @@ export function _inEnumMap(value, map) {
|
|
|
90
90
|
try {
|
|
91
91
|
return _inEnumMap(parseInt(value, 10), map);
|
|
92
92
|
}
|
|
93
|
-
catch (
|
|
93
|
+
catch (_e) {
|
|
94
|
+
// nothing
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
return undefined;
|
|
@@ -102,7 +103,7 @@ export function _inEnumAlteration(value, alt) {
|
|
|
102
103
|
if (Object.keys(alt).includes(value)) {
|
|
103
104
|
return alt[value];
|
|
104
105
|
}
|
|
105
|
-
if (typeof value ===
|
|
106
|
+
if (typeof value === "string") {
|
|
106
107
|
// regular, in lower-case
|
|
107
108
|
let str = value.toLowerCase();
|
|
108
109
|
let v = _inEnumAlteration(str, alt);
|
|
@@ -119,7 +120,8 @@ export function _inEnumAlteration(value, alt) {
|
|
|
119
120
|
try {
|
|
120
121
|
return _inEnumAlteration(parseInt(value, 10), alt);
|
|
121
122
|
}
|
|
122
|
-
catch (
|
|
123
|
+
catch (_e) {
|
|
124
|
+
// nothing
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
return undefined;
|
|
@@ -131,7 +133,7 @@ export function _inEnumLiteral(value, arr) {
|
|
|
131
133
|
if (arr.includes(value)) {
|
|
132
134
|
return value;
|
|
133
135
|
}
|
|
134
|
-
if (typeof value ===
|
|
136
|
+
if (typeof value === "string") {
|
|
135
137
|
// regular, in lower-case
|
|
136
138
|
let str = value.toLowerCase();
|
|
137
139
|
let v = _inEnumLiteral(str, arr);
|
|
@@ -148,7 +150,8 @@ export function _inEnumLiteral(value, arr) {
|
|
|
148
150
|
try {
|
|
149
151
|
return _inEnumLiteral(parseInt(value, 10), arr);
|
|
150
152
|
}
|
|
151
|
-
catch (
|
|
153
|
+
catch (_e) {
|
|
154
|
+
// nothing
|
|
152
155
|
}
|
|
153
156
|
}
|
|
154
157
|
return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leyyo/type",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"description": "Leyyo type library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"type",
|
|
@@ -25,38 +25,35 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"clear": "rimraf dist",
|
|
27
27
|
"lint": "eslint src/**/*.ts",
|
|
28
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
29
|
+
"format": "prettier --check \"{src,test}/**/*.{ts,tsx,js}\"",
|
|
30
|
+
"format:force": "prettier --write \"{src,test}/**/*.{ts,tsx,js}\"",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"test:watch": "vitest",
|
|
33
|
+
"test:coverage": "vitest run --coverage",
|
|
28
34
|
"asset": "node -r ts-node/register commands/assets.js",
|
|
29
|
-
"foretell": "node -r ts-node/register commands/build-lazy.js",
|
|
30
35
|
"build": "npm run clear && tsc && npm run asset",
|
|
31
|
-
"
|
|
32
|
-
"test:watch": "jest --watch --config=jest.json",
|
|
33
|
-
"test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",
|
|
34
|
-
"~publish": "npm run build && npm publish -access=public"
|
|
36
|
+
"publish:public": "npm run lint && npm run format:force && npm run test && npm run build && npm publish --access=public"
|
|
35
37
|
},
|
|
36
38
|
"files": [
|
|
37
39
|
"dist/*"
|
|
38
40
|
],
|
|
39
41
|
"license": "ISC",
|
|
40
42
|
"devDependencies": {
|
|
41
|
-
|
|
42
|
-
"@types/
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"eslint": "^9.23.0",
|
|
49
|
-
"eslint-config-prettier": "^10.1.1",
|
|
50
|
-
"eslint-plugin-jsdoc": "^50.6.9",
|
|
51
|
-
"eslint-plugin-node": "^11.1.0",
|
|
52
|
-
"jest": "^29.7.0",
|
|
53
|
-
"prettier": "^3.5.3",
|
|
43
|
+
"@eslint/js": "^9.0.0",
|
|
44
|
+
"@types/node": "^24.2.1",
|
|
45
|
+
"@vitest/coverage-istanbul": "^4.0.18",
|
|
46
|
+
"eslint": "^9.0.0",
|
|
47
|
+
"eslint-config-prettier": "^10.1.8",
|
|
48
|
+
"eslint-plugin-n": "^17.24.0",
|
|
49
|
+
"prettier": "^3.8.1",
|
|
54
50
|
"rimraf": "^6.0.1",
|
|
55
|
-
"ts-
|
|
56
|
-
"
|
|
57
|
-
"typescript": "^
|
|
51
|
+
"ts-node": "^10.9.2",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"typescript-eslint": "^8.0.0",
|
|
54
|
+
"vitest": "^4.0.18"
|
|
58
55
|
},
|
|
59
56
|
"dependencies": {
|
|
60
|
-
"@leyyo/common": "^1.3.
|
|
57
|
+
"@leyyo/common": "^1.3.20"
|
|
61
58
|
}
|
|
62
59
|
}
|