@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.
Files changed (66) hide show
  1. package/dist/error/index.d.ts +17 -17
  2. package/dist/error/index.js +17 -17
  3. package/dist/error/invalid-array.error.js +5 -1
  4. package/dist/error/invalid-boolean.error.js +5 -1
  5. package/dist/error/invalid-date.error.js +1 -1
  6. package/dist/error/invalid-delimited.error.js +5 -1
  7. package/dist/error/invalid-enum-map.error.js +5 -1
  8. package/dist/error/invalid-enum-value.error.js +5 -1
  9. package/dist/error/invalid-integer.error.js +5 -1
  10. package/dist/error/invalid-list.error.js +1 -1
  11. package/dist/error/invalid-literal-items.error.js +5 -1
  12. package/dist/error/invalid-literal-value.error.js +5 -1
  13. package/dist/error/invalid-map.error.js +1 -1
  14. package/dist/error/invalid-number.error.js +5 -1
  15. package/dist/error/invalid-object.error.js +5 -1
  16. package/dist/error/invalid-real-value.error.js +5 -1
  17. package/dist/error/invalid-set.error.js +1 -1
  18. package/dist/error/invalid-string.error.js +5 -1
  19. package/dist/error/invalid-text.error.js +1 -1
  20. package/dist/index.d.ts +6 -6
  21. package/dist/index.foretell.js +24 -24
  22. package/dist/index.js +6 -6
  23. package/dist/index.loader.js +2 -2
  24. package/dist/is/index.d.ts +25 -25
  25. package/dist/is/index.js +25 -25
  26. package/dist/is/is-boolean-like.js +2 -2
  27. package/dist/is/is-false-like.js +1 -1
  28. package/dist/is/is-instance-of.js +1 -1
  29. package/dist/is/is-not-empty.js +1 -1
  30. package/dist/is/is-sys-class.js +1 -1
  31. package/dist/is/is-sys-function.js +1 -1
  32. package/dist/is/is-true-like.js +1 -1
  33. package/dist/is/is-type-of.d.ts +1 -1
  34. package/dist/is/is-valid-number.js +1 -1
  35. package/dist/literal/basic-type.js +11 -2
  36. package/dist/literal/defined-type.d.ts +1 -1
  37. package/dist/literal/defined-type.js +2 -2
  38. package/dist/literal/extended-type.js +22 -4
  39. package/dist/literal/false-weak.d.ts +1 -1
  40. package/dist/literal/false-weak.js +2 -2
  41. package/dist/literal/index.d.ts +7 -7
  42. package/dist/literal/index.js +7 -7
  43. package/dist/literal/sys-class.d.ts +1 -1
  44. package/dist/literal/sys-class.js +65 -15
  45. package/dist/literal/sys-function.d.ts +1 -1
  46. package/dist/literal/sys-function.js +20 -4
  47. package/dist/literal/true-weak.d.ts +1 -1
  48. package/dist/literal/true-weak.js +2 -2
  49. package/dist/to/index.d.ts +15 -15
  50. package/dist/to/index.js +15 -15
  51. package/dist/to/to-array-value.js +46 -42
  52. package/dist/to/to-boolean-value.js +13 -13
  53. package/dist/to/to-date-value.js +22 -20
  54. package/dist/to/to-delimited-value.js +15 -13
  55. package/dist/to/to-enum-value.js +22 -21
  56. package/dist/to/to-integer-value.js +14 -13
  57. package/dist/to/to-list-value.js +9 -8
  58. package/dist/to/to-literal-value.js +23 -22
  59. package/dist/to/to-map-value.js +44 -41
  60. package/dist/to/to-number-value.js +12 -12
  61. package/dist/to/to-object-value.js +26 -24
  62. package/dist/to/to-set-value.js +8 -8
  63. package/dist/to/to-string-value.js +14 -13
  64. package/dist/to/to-text-value.js +18 -16
  65. package/dist/to/util.js +18 -15
  66. 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
- let o = optCheck(opt);
13
+ const o = optCheck(opt);
14
14
  if (isEmpty(value)) {
15
- return _toEmpty(value, o, InvalidStringError, 'string');
15
+ return _toEmpty(value, o, InvalidStringError, "string");
16
16
  }
17
+ let num;
17
18
  switch (typeof value) {
18
- case 'string':
19
+ case "string":
19
20
  return value;
20
- case 'number':
21
- const num = _realNumber(value, o);
22
- return (num !== undefined) ? num.toString(10) : undefined;
23
- case 'bigint':
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 'boolean':
26
- return value ? 'true' : 'false';
27
- case 'object':
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 'function':
36
- return toStringValue(_toRun(value, o, 'function'), o);
36
+ case "function":
37
+ return toStringValue(_toRun(value, o, "function"), o);
37
38
  }
38
- return _toElse(value, o, InvalidStringError, 'string');
39
+ return _toElse(value, o, InvalidStringError, "string");
39
40
  }
@@ -10,25 +10,27 @@ import { InvalidTextError } from "../error/index.js";
10
10
  * @return {string}
11
11
  * */
12
12
  export function toTextValue(value, opt) {
13
- let o = optCheck(opt);
13
+ const o = optCheck(opt);
14
14
  if (isEmpty(value)) {
15
- return _toEmpty(value, o, InvalidTextError, 'string');
15
+ return _toEmpty(value, o, InvalidTextError, "string");
16
16
  }
17
+ let str;
18
+ let num;
17
19
  switch (typeof value) {
18
- case 'string':
19
- const str = value.trim();
20
- if (str === '') {
21
- return _toEmpty(value, { ...o, textCase: 'empty' }, InvalidTextError, 'string');
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 'number':
25
- const num = _realNumber(value, o);
26
- return (num !== undefined) ? num.toString(10) : undefined;
27
- case 'bigint':
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 'boolean':
30
- return value ? 'true' : 'false';
31
- case 'object':
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 'function':
40
- return toTextValue(_toRun(value, o, 'function'), o);
41
+ case "function":
42
+ return toTextValue(_toRun(value, o, "function"), o);
41
43
  }
42
- return _toElse(value, o, InvalidTextError, 'string');
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: 'unexpected', callback });
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: 'empty',
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: 'invalid',
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, 'issue', 'nan');
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, 'issue', 'finite');
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, 'issue', 'not:safe');
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 === 'string') {
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 (e) {
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 === 'string') {
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 (e) {
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 === 'string') {
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 (e) {
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.6",
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
- "test": "npx jest --config=jest.json --clearCache && npx jest --config=jest.json --verbose",
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
- "@babel/preset-typescript": "^7.27.0",
42
- "@types/express": "^5.0.6",
43
- "@types/geoip-lite": "^1.4.4",
44
- "@types/jest": "^29.5.14",
45
- "@types/node": "^22.14.0",
46
- "@typescript-eslint/eslint-plugin": "^8.29.0",
47
- "@typescript-eslint/parser": "^8.29.0",
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-jest": "^29.3.1",
56
- "ts-node": "^10.8.1",
57
- "typescript": "^5.7.3"
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.18"
57
+ "@leyyo/common": "^1.3.20"
61
58
  }
62
59
  }