@duplojs/utils 1.6.2 → 1.6.3

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 (121) hide show
  1. package/dist/array/types/createTuple.d.ts +1 -1
  2. package/dist/clean/constraint/base.cjs +7 -0
  3. package/dist/clean/constraint/base.d.ts +26 -6
  4. package/dist/clean/constraint/base.mjs +7 -0
  5. package/dist/clean/constraint/cast.cjs +18 -0
  6. package/dist/clean/constraint/cast.d.ts +29 -0
  7. package/dist/clean/constraint/cast.mjs +16 -0
  8. package/dist/clean/constraint/defaultConstraint/number.cjs +2 -10
  9. package/dist/clean/constraint/defaultConstraint/number.d.ts +12 -37
  10. package/dist/clean/constraint/defaultConstraint/number.mjs +3 -10
  11. package/dist/clean/constraint/defaultConstraint/string.d.ts +9 -5
  12. package/dist/clean/constraint/index.d.ts +1 -0
  13. package/dist/clean/constraint/set.cjs +7 -1
  14. package/dist/clean/constraint/set.d.ts +25 -5
  15. package/dist/clean/constraint/set.mjs +7 -1
  16. package/dist/clean/entity/index.cjs +14 -4
  17. package/dist/clean/entity/index.d.ts +11 -1
  18. package/dist/clean/entity/index.mjs +15 -6
  19. package/dist/clean/index.cjs +5 -1
  20. package/dist/clean/index.d.ts +1 -0
  21. package/dist/clean/index.mjs +4 -2
  22. package/dist/clean/newType.cjs +6 -1
  23. package/dist/clean/newType.d.ts +20 -5
  24. package/dist/clean/newType.mjs +6 -1
  25. package/dist/clean/primitive/operations/equal.cjs +3 -0
  26. package/dist/clean/primitive/operations/equal.d.ts +2 -2
  27. package/dist/clean/primitive/operations/equal.mjs +3 -0
  28. package/dist/clean/toMapDataParser.cjs +52 -0
  29. package/dist/clean/toMapDataParser.d.ts +53 -0
  30. package/dist/clean/toMapDataParser.mjs +50 -0
  31. package/dist/common/index.d.ts +1 -0
  32. package/dist/common/printer.cjs +73 -0
  33. package/dist/common/printer.d.ts +139 -0
  34. package/dist/common/printer.mjs +73 -0
  35. package/dist/common/types/and.d.ts +1 -2
  36. package/dist/common/types/or.d.ts +1 -2
  37. package/dist/dataParser/base.cjs +12 -35
  38. package/dist/dataParser/base.d.ts +6 -9
  39. package/dist/dataParser/base.mjs +8 -30
  40. package/dist/dataParser/error.cjs +39 -21
  41. package/dist/dataParser/error.d.ts +19 -19
  42. package/dist/dataParser/error.mjs +37 -18
  43. package/dist/dataParser/extended/index.cjs +3 -4
  44. package/dist/dataParser/extended/index.mjs +1 -1
  45. package/dist/dataParser/identifier.d.ts +6 -6
  46. package/dist/dataParser/index.cjs +3 -6
  47. package/dist/dataParser/index.mjs +2 -2
  48. package/dist/dataParser/parsers/array/checkers/max.cjs +3 -6
  49. package/dist/dataParser/parsers/array/checkers/max.mjs +4 -7
  50. package/dist/dataParser/parsers/array/checkers/min.cjs +3 -6
  51. package/dist/dataParser/parsers/array/checkers/min.mjs +4 -7
  52. package/dist/dataParser/parsers/array/index.cjs +8 -8
  53. package/dist/dataParser/parsers/array/index.mjs +4 -4
  54. package/dist/dataParser/parsers/bigint/checkers/max.cjs +2 -2
  55. package/dist/dataParser/parsers/bigint/checkers/max.mjs +3 -3
  56. package/dist/dataParser/parsers/bigint/checkers/min.cjs +2 -2
  57. package/dist/dataParser/parsers/bigint/checkers/min.mjs +3 -3
  58. package/dist/dataParser/parsers/bigint/index.cjs +2 -2
  59. package/dist/dataParser/parsers/bigint/index.mjs +3 -3
  60. package/dist/dataParser/parsers/boolean.cjs +3 -3
  61. package/dist/dataParser/parsers/boolean.mjs +4 -4
  62. package/dist/dataParser/parsers/date.cjs +4 -4
  63. package/dist/dataParser/parsers/date.mjs +5 -5
  64. package/dist/dataParser/parsers/empty.cjs +2 -2
  65. package/dist/dataParser/parsers/empty.mjs +3 -3
  66. package/dist/dataParser/parsers/literal.cjs +2 -2
  67. package/dist/dataParser/parsers/literal.mjs +3 -3
  68. package/dist/dataParser/parsers/nil.cjs +2 -2
  69. package/dist/dataParser/parsers/nil.mjs +3 -3
  70. package/dist/dataParser/parsers/number/checkers/int.cjs +2 -2
  71. package/dist/dataParser/parsers/number/checkers/int.mjs +3 -3
  72. package/dist/dataParser/parsers/number/checkers/max.cjs +3 -1
  73. package/dist/dataParser/parsers/number/checkers/max.mjs +4 -2
  74. package/dist/dataParser/parsers/number/checkers/min.cjs +3 -1
  75. package/dist/dataParser/parsers/number/checkers/min.mjs +4 -2
  76. package/dist/dataParser/parsers/number/index.cjs +2 -2
  77. package/dist/dataParser/parsers/number/index.mjs +3 -3
  78. package/dist/dataParser/parsers/object/index.cjs +8 -8
  79. package/dist/dataParser/parsers/object/index.mjs +4 -4
  80. package/dist/dataParser/parsers/pipe.cjs +25 -10
  81. package/dist/dataParser/parsers/pipe.mjs +22 -7
  82. package/dist/dataParser/parsers/record/index.cjs +18 -16
  83. package/dist/dataParser/parsers/record/index.mjs +8 -6
  84. package/dist/dataParser/parsers/recover.cjs +7 -6
  85. package/dist/dataParser/parsers/recover.mjs +2 -1
  86. package/dist/dataParser/parsers/refine.cjs +3 -1
  87. package/dist/dataParser/parsers/refine.mjs +4 -2
  88. package/dist/dataParser/parsers/string/checkers/email.cjs +2 -2
  89. package/dist/dataParser/parsers/string/checkers/email.mjs +3 -3
  90. package/dist/dataParser/parsers/string/checkers/max.cjs +3 -1
  91. package/dist/dataParser/parsers/string/checkers/max.mjs +4 -2
  92. package/dist/dataParser/parsers/string/checkers/min.cjs +3 -1
  93. package/dist/dataParser/parsers/string/checkers/min.mjs +4 -2
  94. package/dist/dataParser/parsers/string/checkers/regex.cjs +2 -2
  95. package/dist/dataParser/parsers/string/checkers/regex.mjs +3 -3
  96. package/dist/dataParser/parsers/string/checkers/url.cjs +4 -4
  97. package/dist/dataParser/parsers/string/checkers/url.mjs +5 -5
  98. package/dist/dataParser/parsers/string/index.cjs +2 -2
  99. package/dist/dataParser/parsers/string/index.mjs +3 -3
  100. package/dist/dataParser/parsers/templateLiteral/index.cjs +2 -2
  101. package/dist/dataParser/parsers/templateLiteral/index.mjs +3 -3
  102. package/dist/dataParser/parsers/time/checkers/max.cjs +3 -1
  103. package/dist/dataParser/parsers/time/checkers/max.mjs +4 -2
  104. package/dist/dataParser/parsers/time/checkers/min.cjs +3 -1
  105. package/dist/dataParser/parsers/time/checkers/min.mjs +4 -2
  106. package/dist/dataParser/parsers/time/index.cjs +4 -4
  107. package/dist/dataParser/parsers/time/index.mjs +5 -5
  108. package/dist/dataParser/parsers/transform.cjs +6 -6
  109. package/dist/dataParser/parsers/transform.d.ts +2 -2
  110. package/dist/dataParser/parsers/transform.mjs +4 -4
  111. package/dist/dataParser/parsers/tuple.cjs +14 -14
  112. package/dist/dataParser/parsers/tuple.mjs +4 -4
  113. package/dist/dataParser/parsers/union.cjs +26 -8
  114. package/dist/dataParser/parsers/union.mjs +26 -8
  115. package/dist/index.cjs +5 -0
  116. package/dist/index.mjs +1 -0
  117. package/dist/metadata.json +27 -0
  118. package/dist/number/types/isGreater.d.ts +26 -3
  119. package/dist/string/length.d.ts +2 -2
  120. package/dist/string/types/split.d.ts +6 -5
  121. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { dataParserInit } from '../../base.mjs';
2
- import { SymbolDataParserErrorIssue } from '../../error.mjs';
2
+ import { addIssue } from '../../error.mjs';
3
3
  import { createDataParserKind } from '../../kind.mjs';
4
4
  import { createTemplateLiteralPattern } from './createTemplateLiteralPattern.mjs';
5
5
  import { pipe } from '../../../common/pipe.mjs';
@@ -16,11 +16,11 @@ function templateLiteral(template, definition) {
16
16
  checkers: definition?.checkers ?? [],
17
17
  template,
18
18
  pattern,
19
- }, (data, _error, self) => {
19
+ }, (data, error, self) => {
20
20
  if (typeof data === "string" && self.definition.pattern.test(data)) {
21
21
  return data;
22
22
  }
23
- return SymbolDataParserErrorIssue;
23
+ return addIssue(error, `string matching template literal pattern ${self.definition.pattern.source}`, data, self.definition.errorMessage);
24
24
  }, templateLiteral.overrideHandler);
25
25
  return self;
26
26
  }
@@ -15,7 +15,9 @@ function checkerTimeMax(max, definition = {}) {
15
15
  ...definition,
16
16
  max,
17
17
  },
18
- }, (value, self) => lessTime.lessTime(value, self.definition.max) ? value : error.SymbolDataParserErrorIssue);
18
+ }, (value, error$1, self) => lessTime.lessTime(value, self.definition.max)
19
+ ? value
20
+ : error.addIssue(error$1, `time <= ${self.definition.max.toString()}`, value, self.definition.errorMessage));
19
21
  }
20
22
 
21
23
  exports.checkerTimeMax = checkerTimeMax;
@@ -1,5 +1,5 @@
1
1
  import { dataParserCheckerInit } from '../../../base.mjs';
2
- import { SymbolDataParserErrorIssue } from '../../../error.mjs';
2
+ import { addIssue } from '../../../error.mjs';
3
3
  import { createDataParserKind } from '../../../kind.mjs';
4
4
  import { lessTime } from '../../../../date/operators/lessTime.mjs';
5
5
 
@@ -13,7 +13,9 @@ function checkerTimeMax(max, definition = {}) {
13
13
  ...definition,
14
14
  max,
15
15
  },
16
- }, (value, self) => lessTime(value, self.definition.max) ? value : SymbolDataParserErrorIssue);
16
+ }, (value, error, self) => lessTime(value, self.definition.max)
17
+ ? value
18
+ : addIssue(error, `time <= ${self.definition.max.toString()}`, value, self.definition.errorMessage));
17
19
  }
18
20
 
19
21
  export { checkerTimeMax, checkerTimeMaxKind };
@@ -15,7 +15,9 @@ function checkerTimeMin(min, definition = {}) {
15
15
  ...definition,
16
16
  min,
17
17
  },
18
- }, (value, self) => greaterTime.greaterTime(value, self.definition.min) ? value : error.SymbolDataParserErrorIssue);
18
+ }, (value, error$1, self) => greaterTime.greaterTime(value, self.definition.min)
19
+ ? value
20
+ : error.addIssue(error$1, `time >= ${self.definition.min.toString()}`, value, self.definition.errorMessage));
19
21
  }
20
22
 
21
23
  exports.checkerTimeMin = checkerTimeMin;
@@ -1,5 +1,5 @@
1
1
  import { dataParserCheckerInit } from '../../../base.mjs';
2
- import { SymbolDataParserErrorIssue } from '../../../error.mjs';
2
+ import { addIssue } from '../../../error.mjs';
3
3
  import { createDataParserKind } from '../../../kind.mjs';
4
4
  import { greaterTime } from '../../../../date/operators/greaterTime.mjs';
5
5
 
@@ -13,7 +13,9 @@ function checkerTimeMin(min, definition = {}) {
13
13
  ...definition,
14
14
  min,
15
15
  },
16
- }, (value, self) => greaterTime(value, self.definition.min) ? value : SymbolDataParserErrorIssue);
16
+ }, (value, error, self) => greaterTime(value, self.definition.min)
17
+ ? value
18
+ : addIssue(error, `time >= ${self.definition.min.toString()}`, value, self.definition.errorMessage));
17
19
  }
18
20
 
19
21
  export { checkerTimeMin, checkerTimeMinKind };
@@ -22,12 +22,12 @@ function time(definition) {
22
22
  errorMessage: definition?.errorMessage,
23
23
  checkers: definition?.checkers ?? [],
24
24
  coerce: definition?.coerce ?? false,
25
- }, (data, _error, self) => {
25
+ }, (data, error$1, self) => {
26
26
  if (self.definition.coerce) {
27
27
  if (typeof data === "string" && constants.isoTimeRegex.test(data)) {
28
28
  const result = createTime.createTime({ value: data });
29
29
  if (is.isLeft(result)) {
30
- return error.SymbolDataParserErrorIssue;
30
+ return error.addIssue(error$1, "time", data, self.definition.errorMessage);
31
31
  }
32
32
  return unwrap.unwrap(result);
33
33
  }
@@ -40,11 +40,11 @@ function time(definition) {
40
40
  }
41
41
  else if (typeof data === "number") {
42
42
  if (!isSafeTimeValue.isSafeTimeValue(data)) {
43
- return error.SymbolDataParserErrorIssue;
43
+ return error.addIssue(error$1, "time", data, self.definition.errorMessage);
44
44
  }
45
45
  return theTime.TheTime.new(data);
46
46
  }
47
- return error.SymbolDataParserErrorIssue;
47
+ return error.addIssue(error$1, "time", data, self.definition.errorMessage);
48
48
  }, time.overrideHandler);
49
49
  return self;
50
50
  }
@@ -1,5 +1,5 @@
1
1
  import { dataParserInit } from '../../base.mjs';
2
- import { SymbolDataParserErrorIssue } from '../../error.mjs';
2
+ import { addIssue } from '../../error.mjs';
3
3
  import { createDataParserKind } from '../../kind.mjs';
4
4
  import { isoTimeRegex } from '../../../date/constants.mjs';
5
5
  import { createTime } from '../../../date/createTime.mjs';
@@ -20,12 +20,12 @@ function time(definition) {
20
20
  errorMessage: definition?.errorMessage,
21
21
  checkers: definition?.checkers ?? [],
22
22
  coerce: definition?.coerce ?? false,
23
- }, (data, _error, self) => {
23
+ }, (data, error, self) => {
24
24
  if (self.definition.coerce) {
25
25
  if (typeof data === "string" && isoTimeRegex.test(data)) {
26
26
  const result = createTime({ value: data });
27
27
  if (isLeft(result)) {
28
- return SymbolDataParserErrorIssue;
28
+ return addIssue(error, "time", data, self.definition.errorMessage);
29
29
  }
30
30
  return unwrap(result);
31
31
  }
@@ -38,11 +38,11 @@ function time(definition) {
38
38
  }
39
39
  else if (typeof data === "number") {
40
40
  if (!isSafeTimeValue(data)) {
41
- return SymbolDataParserErrorIssue;
41
+ return addIssue(error, "time", data, self.definition.errorMessage);
42
42
  }
43
43
  return TheTime.new(data);
44
44
  }
45
- return SymbolDataParserErrorIssue;
45
+ return addIssue(error, "time", data, self.definition.errorMessage);
46
46
  }, time.overrideHandler);
47
47
  return self;
48
48
  }
@@ -18,23 +18,23 @@ function transform(inner, theFunction, definition) {
18
18
  }, {
19
19
  sync: (data, error$1, self) => {
20
20
  const innerResult = self.definition.inner.exec(data, error$1);
21
- if (innerResult === base.SymbolDataParserError) {
22
- return base.SymbolDataParserError;
21
+ if (innerResult === error.SymbolDataParserError) {
22
+ return error.SymbolDataParserError;
23
23
  }
24
24
  const result = self.definition.theFunction(innerResult, error$1);
25
25
  if (result instanceof Promise) {
26
- return error.SymbolDataParserErrorPromiseIssue;
26
+ return error.addIssue(error$1, "non-promise transform result", result, self.definition.errorMessage);
27
27
  }
28
28
  return result;
29
29
  },
30
30
  async: async (data, error$1, self) => {
31
31
  const innerResult = await self.definition.inner.asyncExec(data, error$1);
32
- if (innerResult === base.SymbolDataParserError) {
33
- return base.SymbolDataParserError;
32
+ if (innerResult === error.SymbolDataParserError) {
33
+ return error.SymbolDataParserError;
34
34
  }
35
35
  let result = self.definition.theFunction(innerResult, error$1);
36
36
  if (result instanceof Promise) {
37
- result = result.catch(() => error.SymbolDataParserErrorPromiseIssue);
37
+ result = await result.catch(() => error.addIssue(error$1, "successful async transform result", result, self.definition.errorMessage));
38
38
  }
39
39
  return result;
40
40
  },
@@ -1,7 +1,7 @@
1
1
  import { type FixDeepFunctionInfer, type Kind, type NeverCoalescing } from "../../common";
2
2
  import { type DataParserDefinition, type DataParser, type Input, type Output, SymbolDataParserError, type DataParserChecker } from "../base";
3
3
  import { type AddCheckersToDefinition, type MergeDefinition } from "../../dataParser/types";
4
- import { type DataParserError, type SymbolDataParserErrorIssue, SymbolDataParserErrorPromiseIssue } from "../../dataParser/error";
4
+ import { type DataParserError } from "../../dataParser/error";
5
5
  import { type CheckerRefineImplementation } from "./refine";
6
6
  import { type GetPropsWithValueExtends } from "../../object";
7
7
  export interface DataParserTransformCheckerCustom<GenericInput extends unknown = unknown> {
@@ -12,7 +12,7 @@ export interface DataParserDefinitionTransform extends DataParserDefinition<Data
12
12
  theFunction(input: any, error: DataParserError): unknown;
13
13
  }
14
14
  export declare const transformKind: import("../../common").KindHandler<import("../../common").KindDefinition<"@DuplojsUtilsDataParser/transform", unknown>>;
15
- export type DataParserTransformOutput<GenericTheFunction extends DataParserDefinitionTransform["theFunction"]> = Exclude<Awaited<ReturnType<GenericTheFunction>>, SymbolDataParserError | SymbolDataParserErrorIssue | SymbolDataParserErrorPromiseIssue>;
15
+ export type DataParserTransformOutput<GenericTheFunction extends DataParserDefinitionTransform["theFunction"]> = Exclude<Awaited<ReturnType<GenericTheFunction>>, SymbolDataParserError>;
16
16
  type _DataParserTransform<GenericDefinition extends DataParserDefinitionTransform> = (DataParser<GenericDefinition, DataParserTransformOutput<GenericDefinition["theFunction"]>, Input<GenericDefinition["inner"]>> & Kind<typeof transformKind.definition>);
17
17
  export interface DataParserTransform<GenericDefinition extends DataParserDefinitionTransform = DataParserDefinitionTransform> extends _DataParserTransform<GenericDefinition> {
18
18
  addChecker<GenericChecker extends readonly [
@@ -1,5 +1,5 @@
1
- import { dataParserInit, SymbolDataParserError } from '../base.mjs';
2
- import { SymbolDataParserErrorPromiseIssue } from '../error.mjs';
1
+ import { dataParserInit } from '../base.mjs';
2
+ import { SymbolDataParserError, addIssue } from '../error.mjs';
3
3
  import { createDataParserKind } from '../kind.mjs';
4
4
  import { createOverride } from '../../common/override.mjs';
5
5
 
@@ -21,7 +21,7 @@ function transform(inner, theFunction, definition) {
21
21
  }
22
22
  const result = self.definition.theFunction(innerResult, error);
23
23
  if (result instanceof Promise) {
24
- return SymbolDataParserErrorPromiseIssue;
24
+ return addIssue(error, "non-promise transform result", result, self.definition.errorMessage);
25
25
  }
26
26
  return result;
27
27
  },
@@ -32,7 +32,7 @@ function transform(inner, theFunction, definition) {
32
32
  }
33
33
  let result = self.definition.theFunction(innerResult, error);
34
34
  if (result instanceof Promise) {
35
- result = result.catch(() => SymbolDataParserErrorPromiseIssue);
35
+ result = await result.catch(() => addIssue(error, "successful async transform result", result, self.definition.errorMessage));
36
36
  }
37
37
  return result;
38
38
  },
@@ -19,17 +19,17 @@ function tuple(shape, definition) {
19
19
  }, {
20
20
  sync: (data, error$1, self) => {
21
21
  if (!(data instanceof Array)) {
22
- return error.SymbolDataParserErrorIssue;
22
+ return error.addIssue(error$1, "tuple array", data, self.definition.errorMessage);
23
23
  }
24
24
  let output = [];
25
25
  const currentIndexPath = error$1.currentPath.length;
26
26
  for (let index = 0; index < self.definition.shape.length; index++) {
27
27
  error.setErrorPath(error$1, `[${index}]`, currentIndexPath);
28
28
  const result = self.definition.shape[index]?.exec(data[index], error$1);
29
- if (result === base.SymbolDataParserError) {
30
- output = base.SymbolDataParserError;
29
+ if (result === error.SymbolDataParserError) {
30
+ output = error.SymbolDataParserError;
31
31
  }
32
- else if (output !== base.SymbolDataParserError) {
32
+ else if (output !== error.SymbolDataParserError) {
33
33
  output.push(result);
34
34
  }
35
35
  }
@@ -37,10 +37,10 @@ function tuple(shape, definition) {
37
37
  for (let index = self.definition.shape.length; index < data.length; index++) {
38
38
  error.setErrorPath(error$1, `[${index}]`, currentIndexPath);
39
39
  const result = self.definition.rest.exec(data[index], error$1);
40
- if (result === base.SymbolDataParserError) {
41
- output = base.SymbolDataParserError;
40
+ if (result === error.SymbolDataParserError) {
41
+ output = error.SymbolDataParserError;
42
42
  }
43
- else if (output !== base.SymbolDataParserError) {
43
+ else if (output !== error.SymbolDataParserError) {
44
44
  output.push(result);
45
45
  }
46
46
  }
@@ -50,17 +50,17 @@ function tuple(shape, definition) {
50
50
  },
51
51
  async: async (data, error$1, self) => {
52
52
  if (!(data instanceof Array)) {
53
- return error.SymbolDataParserErrorIssue;
53
+ return error.addIssue(error$1, "tuple array", data, self.definition.errorMessage);
54
54
  }
55
55
  let output = [];
56
56
  const currentIndexPath = error$1.currentPath.length;
57
57
  for (let index = 0; index < self.definition.shape.length; index++) {
58
58
  error.setErrorPath(error$1, `[${index}]`, currentIndexPath);
59
59
  const result = await self.definition.shape[index]?.asyncExec(data[index], error$1);
60
- if (result === base.SymbolDataParserError) {
61
- output = base.SymbolDataParserError;
60
+ if (result === error.SymbolDataParserError) {
61
+ output = error.SymbolDataParserError;
62
62
  }
63
- else if (output !== base.SymbolDataParserError) {
63
+ else if (output !== error.SymbolDataParserError) {
64
64
  output.push(result);
65
65
  }
66
66
  }
@@ -68,10 +68,10 @@ function tuple(shape, definition) {
68
68
  for (let index = self.definition.shape.length; index < data.length; index++) {
69
69
  error.setErrorPath(error$1, `[${index}]`, currentIndexPath);
70
70
  const result = await self.definition.rest.asyncExec(data[index], error$1);
71
- if (result === base.SymbolDataParserError) {
72
- output = base.SymbolDataParserError;
71
+ if (result === error.SymbolDataParserError) {
72
+ output = error.SymbolDataParserError;
73
73
  }
74
- else if (output !== base.SymbolDataParserError) {
74
+ else if (output !== error.SymbolDataParserError) {
75
75
  output.push(result);
76
76
  }
77
77
  }
@@ -1,5 +1,5 @@
1
- import { dataParserInit, SymbolDataParserError } from '../base.mjs';
2
- import { SymbolDataParserErrorIssue, setErrorPath, popErrorPath } from '../error.mjs';
1
+ import { dataParserInit } from '../base.mjs';
2
+ import { addIssue, setErrorPath, SymbolDataParserError, popErrorPath } from '../error.mjs';
3
3
  import { createDataParserKind } from '../kind.mjs';
4
4
  import { some } from '../../array/some.mjs';
5
5
  import { createOverride } from '../../common/override.mjs';
@@ -17,7 +17,7 @@ function tuple(shape, definition) {
17
17
  }, {
18
18
  sync: (data, error, self) => {
19
19
  if (!(data instanceof Array)) {
20
- return SymbolDataParserErrorIssue;
20
+ return addIssue(error, "tuple array", data, self.definition.errorMessage);
21
21
  }
22
22
  let output = [];
23
23
  const currentIndexPath = error.currentPath.length;
@@ -48,7 +48,7 @@ function tuple(shape, definition) {
48
48
  },
49
49
  async: async (data, error, self) => {
50
50
  if (!(data instanceof Array)) {
51
- return SymbolDataParserErrorIssue;
51
+ return addIssue(error, "tuple array", data, self.definition.errorMessage);
52
52
  }
53
53
  let output = [];
54
54
  const currentIndexPath = error.currentPath.length;
@@ -17,22 +17,40 @@ function union(options, definition) {
17
17
  options,
18
18
  }, {
19
19
  sync: (data, error$1, self) => {
20
- for (const dataParser of self.definition.options) {
21
- const result = dataParser.exec(data, error$1);
22
- if (result !== base.SymbolDataParserError) {
20
+ const unionError = {
21
+ ...error$1,
22
+ currentPath: [...error$1.currentPath],
23
+ issues: [],
24
+ };
25
+ const currentIndexPath = unionError.currentPath.length;
26
+ for (let index = 0; index < self.definition.options.length; index++) {
27
+ error.setErrorPath(unionError, `(option: ${index})`, currentIndexPath);
28
+ const dataParser = self.definition.options[index];
29
+ const result = dataParser.exec(data, unionError);
30
+ if (result !== error.SymbolDataParserError) {
23
31
  return result;
24
32
  }
25
33
  }
26
- return error.SymbolDataParserErrorIssue;
34
+ error$1.issues.push(...unionError.issues);
35
+ return error.addIssue(error$1, "respect at least one union value", data, self.definition.errorMessage);
27
36
  },
28
37
  async: async (data, error$1, self) => {
29
- for (const dataParser of self.definition.options) {
30
- const result = await dataParser.asyncExec(data, error$1);
31
- if (result !== base.SymbolDataParserError) {
38
+ const unionError = {
39
+ ...error$1,
40
+ currentPath: [...error$1.currentPath],
41
+ issues: [],
42
+ };
43
+ const currentIndexPath = unionError.currentPath.length;
44
+ for (let index = 0; index < self.definition.options.length; index++) {
45
+ error.setErrorPath(unionError, `(option: ${index})`, currentIndexPath);
46
+ const dataParser = self.definition.options[index];
47
+ const result = await dataParser.asyncExec(data, unionError);
48
+ if (result !== error.SymbolDataParserError) {
32
49
  return result;
33
50
  }
34
51
  }
35
- return error.SymbolDataParserErrorIssue;
52
+ error$1.issues.push(...unionError.issues);
53
+ return error.addIssue(error$1, "respect at least one union value", data, self.definition.errorMessage);
36
54
  },
37
55
  isAsynchronous: (self) => some.some(self.definition.options, (element) => element.isAsynchronous()),
38
56
  }, union.overrideHandler);
@@ -1,5 +1,5 @@
1
- import { dataParserInit, SymbolDataParserError } from '../base.mjs';
2
- import { SymbolDataParserErrorIssue } from '../error.mjs';
1
+ import { dataParserInit } from '../base.mjs';
2
+ import { setErrorPath, SymbolDataParserError, addIssue } from '../error.mjs';
3
3
  import { createDataParserKind } from '../kind.mjs';
4
4
  import { some } from '../../array/some.mjs';
5
5
  import { createOverride } from '../../common/override.mjs';
@@ -15,22 +15,40 @@ function union(options, definition) {
15
15
  options,
16
16
  }, {
17
17
  sync: (data, error, self) => {
18
- for (const dataParser of self.definition.options) {
19
- const result = dataParser.exec(data, error);
18
+ const unionError = {
19
+ ...error,
20
+ currentPath: [...error.currentPath],
21
+ issues: [],
22
+ };
23
+ const currentIndexPath = unionError.currentPath.length;
24
+ for (let index = 0; index < self.definition.options.length; index++) {
25
+ setErrorPath(unionError, `(option: ${index})`, currentIndexPath);
26
+ const dataParser = self.definition.options[index];
27
+ const result = dataParser.exec(data, unionError);
20
28
  if (result !== SymbolDataParserError) {
21
29
  return result;
22
30
  }
23
31
  }
24
- return SymbolDataParserErrorIssue;
32
+ error.issues.push(...unionError.issues);
33
+ return addIssue(error, "respect at least one union value", data, self.definition.errorMessage);
25
34
  },
26
35
  async: async (data, error, self) => {
27
- for (const dataParser of self.definition.options) {
28
- const result = await dataParser.asyncExec(data, error);
36
+ const unionError = {
37
+ ...error,
38
+ currentPath: [...error.currentPath],
39
+ issues: [],
40
+ };
41
+ const currentIndexPath = unionError.currentPath.length;
42
+ for (let index = 0; index < self.definition.options.length; index++) {
43
+ setErrorPath(unionError, `(option: ${index})`, currentIndexPath);
44
+ const dataParser = self.definition.options[index];
45
+ const result = await dataParser.asyncExec(data, unionError);
29
46
  if (result !== SymbolDataParserError) {
30
47
  return result;
31
48
  }
32
49
  }
33
- return SymbolDataParserErrorIssue;
50
+ error.issues.push(...unionError.issues);
51
+ return addIssue(error, "respect at least one union value", data, self.definition.errorMessage);
34
52
  },
35
53
  isAsynchronous: (self) => some(self.definition.options, (element) => element.isAsynchronous()),
36
54
  }, union.overrideHandler);
package/dist/index.cjs CHANGED
@@ -69,6 +69,7 @@ var toRegExp = require('./common/toRegExp.cjs');
69
69
  var justExec = require('./common/justExec.cjs');
70
70
  var callThen = require('./common/callThen.cjs');
71
71
  var queue = require('./common/queue.cjs');
72
+ var printer = require('./common/printer.cjs');
72
73
 
73
74
 
74
75
 
@@ -176,3 +177,7 @@ exports.justExec = justExec.justExec;
176
177
  exports.callThen = callThen.callThen;
177
178
  exports.createQueue = queue.createQueue;
178
179
  exports.queueKind = queue.queueKind;
180
+ Object.defineProperty(exports, "Printer", {
181
+ enumerable: true,
182
+ get: function () { return printer.Printer; }
183
+ });
package/dist/index.mjs CHANGED
@@ -93,3 +93,4 @@ export { toRegExp } from './common/toRegExp.mjs';
93
93
  export { justExec } from './common/justExec.mjs';
94
94
  export { callThen } from './common/callThen.mjs';
95
95
  export { createQueue, queueKind } from './common/queue.mjs';
96
+ export { Printer } from './common/printer.mjs';
@@ -645,6 +645,15 @@
645
645
  {
646
646
  "name": "base.mjs"
647
647
  },
648
+ {
649
+ "name": "cast.cjs"
650
+ },
651
+ {
652
+ "name": "cast.d.ts"
653
+ },
654
+ {
655
+ "name": "cast.mjs"
656
+ },
648
657
  {
649
658
  "name": "index.d.ts"
650
659
  },
@@ -1038,6 +1047,15 @@
1038
1047
  {
1039
1048
  "name": "repository.mjs"
1040
1049
  },
1050
+ {
1051
+ "name": "toMapDataParser.cjs"
1052
+ },
1053
+ {
1054
+ "name": "toMapDataParser.d.ts"
1055
+ },
1056
+ {
1057
+ "name": "toMapDataParser.mjs"
1058
+ },
1041
1059
  {
1042
1060
  "name": "useCase.cjs"
1043
1061
  },
@@ -1561,6 +1579,15 @@
1561
1579
  {
1562
1580
  "name": "pipeCall.mjs"
1563
1581
  },
1582
+ {
1583
+ "name": "printer.cjs"
1584
+ },
1585
+ {
1586
+ "name": "printer.d.ts"
1587
+ },
1588
+ {
1589
+ "name": "printer.mjs"
1590
+ },
1564
1591
  {
1565
1592
  "name": "promiseObject.cjs"
1566
1593
  },
@@ -25,10 +25,33 @@ type CheckIsGreater<GreaterSplitValue extends AnyTuple<DString.Digit>, GreaterTa
25
25
  infer InferredRestSplitValue extends AnyTuple<DString.Digit>,
26
26
  infer InferredRestSplitReference extends AnyTuple<FigureGreaterThanTableValue>
27
27
  ] ? CheckIsGreater<InferredRestSplitValue, InferredRestSplitReference> : never : false;
28
- export type IsGreater<GenericValue extends number, GenericReference extends number> = IsEqual<GenericValue, GenericReference> extends true ? true : [
29
- `${GenericValue}`,
30
- `${GenericReference}`
28
+ type toStringDecimal<GenericValue extends number> = `${GenericValue}` extends `${DString.Number}.${DString.Number}` ? `${GenericValue}` : `${GenericValue}.0`;
29
+ type PrepareValues<GenericValue extends number, GenericReference extends number> = [
30
+ toStringDecimal<GenericValue>,
31
+ toStringDecimal<GenericReference>
31
32
  ] extends [
33
+ `${infer InferredValueInteger extends DString.Number}.${infer InferredValueDecimals extends DString.Number}`,
34
+ `${infer InferredReferenceInteger extends DString.Number}.${infer InferredReferenceDecimals extends DString.Number}`
35
+ ] ? And<[
36
+ IsEqual<InferredValueDecimals, "0">,
37
+ IsEqual<InferredReferenceDecimals, "0">
38
+ ]> extends true ? [InferredValueInteger, InferredReferenceInteger] : IsEqual<InferredValueInteger, InferredReferenceInteger> extends true ? [
39
+ DString.Split<InferredValueDecimals, "">,
40
+ DString.Split<InferredReferenceDecimals, "">
41
+ ] extends [
42
+ infer InferredSplitValue extends AnyTuple<DString.Digit>,
43
+ infer InferredSplitReference extends AnyTuple<DString.Digit>
44
+ ] ? (IsEqual<InferredSplitValue["length"], InferredSplitReference["length"]> extends true ? [
45
+ DArray.JoinTuple<InferredSplitValue, "">,
46
+ DArray.JoinTuple<InferredSplitReference, "">
47
+ ] : (DArray.CreateTuple<any, InferredSplitValue["length"]> extends [...DArray.CreateTuple<any, InferredSplitReference["length"]>, ...any[]] ? InferredSplitValue["length"] : InferredSplitReference["length"]) extends infer InferredLength extends number ? [
48
+ DArray.JoinTuple<Extract<IsEqual<InferredLength, InferredSplitValue["length"]> extends true ? InferredSplitValue : DArray.CreateTuple<"0", InferredLength, InferredSplitValue>, AnyTuple<string>>, "">,
49
+ DArray.JoinTuple<Extract<IsEqual<InferredLength, InferredSplitReference["length"]> extends true ? InferredSplitReference : DArray.CreateTuple<"0", InferredLength, InferredSplitReference>, AnyTuple<string>>, "">
50
+ ] : never) extends [
51
+ `${infer InferredResultValue}`,
52
+ `${infer InferredResultReference}`
53
+ ] ? [`${InferredResultValue}`, `${InferredResultReference}`] : never : never : [InferredValueInteger, InferredReferenceInteger] : never;
54
+ export type IsGreater<GenericValue extends number, GenericReference extends number> = IsEqual<GenericValue, GenericReference> extends true ? true : PrepareValues<GenericValue, GenericReference> extends [
32
55
  infer InferredValue extends DString.Number,
33
56
  infer InferredReference extends DString.Number
34
57
  ] ? And<[
@@ -1,4 +1,4 @@
1
- import { type StringLength } from "./types/stringLength";
1
+ import { type TemplateLiteralContainLargeType, type StringLength } from "./types";
2
2
  /**
3
3
  * Returns the length of a string.
4
4
  *
@@ -23,4 +23,4 @@ import { type StringLength } from "./types/stringLength";
23
23
  * @namespace S
24
24
  *
25
25
  */
26
- export declare function length<GenericInput extends string>(input: GenericInput): StringLength<GenericInput>;
26
+ export declare function length<GenericInput extends string>(input: GenericInput): TemplateLiteralContainLargeType<GenericInput> extends true ? number : StringLength<GenericInput>;
@@ -1,9 +1,10 @@
1
- import { type Or, type IsEqual } from "../../common";
1
+ import { type IsEqual } from "../../common";
2
2
  import { type Includes } from "./includes";
3
3
  import { type TemplateLiteralContainLargeType } from "./templateLiteralContainLargeType";
4
+ import { type CreateTuple } from "../../array";
4
5
  type _Split<GenericString extends string, GenericSeparator extends string, GenericLimit extends number = number, GenericLastResult extends string[] = []> = GenericString extends `${infer InferredBefore}${GenericSeparator}${infer InferredAfter}` ? [...GenericLastResult, InferredBefore] extends infer InferredResult extends any[] ? IsEqual<InferredAfter, ""> extends true ? InferredResult : IsEqual<InferredResult["length"], 250> extends true ? Includes<InferredAfter, GenericSeparator> extends true ? [...InferredResult, ...string[]] : InferredResult : IsEqual<InferredResult["length"], GenericLimit> extends true ? InferredResult : _Split<InferredAfter, GenericSeparator, GenericLimit, InferredResult> : never : [...GenericLastResult, GenericString];
5
- export type Split<GenericString extends string, GenericSeparator extends string, GenericLimit extends number = number> = IsEqual<GenericLimit, 0> extends true ? [] : Or<[
6
- TemplateLiteralContainLargeType<GenericString>,
7
- TemplateLiteralContainLargeType<GenericSeparator>
8
- ]> extends true ? [string, ...string[]] : _Split<GenericString, GenericSeparator, GenericLimit>;
6
+ export type Split<GenericString extends string, GenericSeparator extends string, GenericLimit extends number = number> = IsEqual<GenericLimit, 0> extends true ? [] : TemplateLiteralContainLargeType<GenericSeparator> extends true ? [string, ...string[]] : TemplateLiteralContainLargeType<GenericString> extends true ? [
7
+ ...CreateTuple<string, _Split<GenericString, GenericSeparator, GenericLimit>["length"]>,
8
+ ...string[]
9
+ ] : _Split<GenericString, GenericSeparator, GenericLimit>;
9
10
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "author": {
5
5
  "name": "mathcovax",
6
6
  "url": "https://github.com/mathcovax"