@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
@@ -33,3 +33,4 @@ export * from "./repository";
33
33
  export * from "./useCase";
34
34
  export * from "./flag";
35
35
  export * from "./maybe";
36
+ export * from "./toMapDataParser";
@@ -1,14 +1,16 @@
1
1
  export { createCleanKind } from './kind.mjs';
2
2
  export { CreateNewTypeError, createNewType, newTypeHandlerKind, newTypeKind } from './newType.mjs';
3
- export { CreateEntityError, createEntity, entityKind } from './entity/index.mjs';
3
+ export { CreateEntityError, createEntity, entityHandlerKind, entityKind } from './entity/index.mjs';
4
4
  export { createRepository, repositoryHandlerKind } from './repository.mjs';
5
5
  export { createUseCase, useCaseHandlerKind, useCaseInstances } from './useCase.mjs';
6
6
  export { createFlag, flagKind } from './flag.mjs';
7
7
  export { none, some } from './maybe.mjs';
8
+ export { toMapDataParser } from './toMapDataParser.mjs';
8
9
  export { entityPropertyArrayKind, entityPropertyDefinitionToDataParser, entityPropertyDefinitionTools, entityPropertyIdentifierKind, entityPropertyNullableKind, entityPropertyStructureKind, entityPropertyUnionKind } from './entity/property.mjs';
9
10
  export { unwrapEntity, unwrapEntityProperty } from './entity/unwrap.mjs';
10
11
  export { CreateConstrainedTypeError, constrainedTypeKind, constraintHandlerKind, createConstraint } from './constraint/base.mjs';
11
- export { Int, Negative, NumberMax, NumberMin, Positive, PositiveInt } from './constraint/defaultConstraint/number.mjs';
12
+ export { castConstraint } from './constraint/cast.mjs';
13
+ export { Int, Negative, NumberMax, NumberMin, Positive } from './constraint/defaultConstraint/number.mjs';
12
14
  export { Email, StringMax, StringMin, Url } from './constraint/defaultConstraint/string.mjs';
13
15
  export { NegativeTime, PositiveTime } from './constraint/defaultConstraint/time.mjs';
14
16
  export { CreateConstraintsSetError, constraintsSetHandlerKind, createConstraintsSet } from './constraint/set.mjs';
@@ -35,7 +35,7 @@ class CreateNewTypeError extends kind$1.kindHeritage("create-new-type-error", er
35
35
  */
36
36
  function createNewType(name, dataParser, constraint) {
37
37
  const constraints = coalescing.coalescing(constraint ?? []);
38
- const checkers = flatMap.flatMap(constraints, ({ checkers }) => checkers);
38
+ const checkers = flatMap.flatMap(constraints, ({ internal }) => internal.checkers);
39
39
  const dataParserWithCheckers = constraint
40
40
  ? dataParser.addChecker(...checkers)
41
41
  : dataParser;
@@ -85,6 +85,11 @@ function createNewType(name, dataParser, constraint) {
85
85
  name,
86
86
  dataParser: dataParserWithCheckers,
87
87
  constraints,
88
+ internal: {
89
+ dataParser: dataParserWithCheckers,
90
+ constraints,
91
+ constraintKindValue,
92
+ },
88
93
  getConstraint,
89
94
  create: create$2,
90
95
  createOrThrow,
@@ -17,15 +17,30 @@ export interface NewTypeHandler<GenericName extends string = string, GenericValu
17
17
  */
18
18
  readonly name: GenericName;
19
19
  /**
20
- * The DataParser used to validate and transform raw inputs.
21
- *
20
+ * @deprecated
22
21
  */
23
22
  readonly dataParser: DDataParser.Contract<GenericValue, unknown>;
24
23
  /**
25
- * The list of constraints applied to this NewType.
26
- *
24
+ * @deprecated
27
25
  */
28
26
  readonly constraints: GenericConstraintsHandler;
27
+ readonly internal: {
28
+ /**
29
+ * The DataParser used to validate and transform raw inputs.
30
+ *
31
+ */
32
+ readonly dataParser: DDataParser.Contract<GenericValue, unknown>;
33
+ /**
34
+ * The list of constraints applied to this NewType.
35
+ *
36
+ */
37
+ readonly constraints: GenericConstraintsHandler;
38
+ /**
39
+ * The constraint kind metadata applied to this NewType.
40
+ *
41
+ */
42
+ readonly constraintKindValue: Record<string, null>;
43
+ };
29
44
  /**
30
45
  * Creates a NewType value and returns an Either.
31
46
  *
@@ -156,5 +171,5 @@ export declare function createNewType<GenericName extends string, GenericDataPar
156
171
  export declare namespace createNewType {
157
172
  var overrideHandler: import("..").OverrideHandler<NewTypeHandler<string, unknown, readonly ConstraintHandler<string, EligiblePrimitive, readonly DDataParser.DataParserChecker<DDataParser.DataParserCheckerDefinition, unknown>[], unknown>[], unknown>>;
158
173
  }
159
- export type GetNewType<GenericHandler extends NewTypeHandler<string, unknown, readonly any[]>, GenericValue extends DDataParser.Output<GenericHandler["dataParser"]> = DDataParser.Output<GenericHandler["dataParser"]>> = Extract<GenericHandler extends any ? NewType<GenericHandler["name"], GenericValue, GenericHandler["constraints"][number]["name"]> : never, any>;
174
+ export type GetNewType<GenericHandler extends NewTypeHandler<string, unknown, readonly any[]>, GenericValue extends DDataParser.Output<GenericHandler["internal"]["dataParser"]> = DDataParser.Output<GenericHandler["internal"]["dataParser"]>> = Extract<GenericHandler extends any ? NewType<GenericHandler["name"], GenericValue, GenericHandler["internal"]["constraints"][number]["name"]> : never, any>;
160
175
  export {};
@@ -33,7 +33,7 @@ class CreateNewTypeError extends kindHeritage("create-new-type-error", createErr
33
33
  */
34
34
  function createNewType(name, dataParser, constraint) {
35
35
  const constraints = coalescing(constraint ?? []);
36
- const checkers = flatMap(constraints, ({ checkers }) => checkers);
36
+ const checkers = flatMap(constraints, ({ internal }) => internal.checkers);
37
37
  const dataParserWithCheckers = constraint
38
38
  ? dataParser.addChecker(...checkers)
39
39
  : dataParser;
@@ -83,6 +83,11 @@ function createNewType(name, dataParser, constraint) {
83
83
  name,
84
84
  dataParser: dataParserWithCheckers,
85
85
  constraints,
86
+ internal: {
87
+ dataParser: dataParserWithCheckers,
88
+ constraints,
89
+ constraintKindValue,
90
+ },
86
91
  getConstraint,
87
92
  create,
88
93
  createOrThrow,
@@ -8,6 +8,9 @@ function equal(...args) {
8
8
  return (input) => equal(input, value);
9
9
  }
10
10
  const [input, value] = args;
11
+ if (input === null || value === null) {
12
+ return input === value;
13
+ }
11
14
  return unwrap.unwrap(input).toString() === unwrap.unwrap(value).toString();
12
15
  }
13
16
 
@@ -34,5 +34,5 @@ import { type Primitive, type Primitives } from "../base";
34
34
  * @namespace C
35
35
  *
36
36
  */
37
- export declare function equal<GenericInput extends Primitives, GenericValue extends (Primitive<Unwrap<GenericInput>> | Unwrap<GenericInput>)>(value: GenericValue): (input: GenericInput) => input is GenericInput & Primitive<Unwrap<GenericValue>>;
38
- export declare function equal<GenericInput extends Primitives, GenericValue extends (Primitive<Unwrap<GenericInput>> | Unwrap<GenericInput>)>(input: GenericInput, value: GenericValue): input is GenericInput & Primitive<Unwrap<GenericValue>>;
37
+ export declare function equal<GenericInput extends Primitives | null, const GenericValue extends (Primitive<Unwrap<Exclude<GenericInput, null>>> | Unwrap<GenericInput>)>(value: GenericValue): (input: GenericInput) => input is (GenericInput & (GenericValue extends null ? GenericValue : Primitive<Unwrap<Exclude<GenericValue, null>>>));
38
+ export declare function equal<GenericInput extends Primitives | null, const GenericValue extends (Primitive<Unwrap<Exclude<GenericInput, null>>> | Unwrap<GenericInput>)>(input: GenericInput, value: GenericValue): input is (GenericInput & (GenericValue extends null ? GenericValue : Primitive<Unwrap<Exclude<GenericValue, null>>>));
@@ -6,6 +6,9 @@ function equal(...args) {
6
6
  return (input) => equal(input, value);
7
7
  }
8
8
  const [input, value] = args;
9
+ if (input === null || value === null) {
10
+ return input === value;
11
+ }
9
12
  return unwrap(input).toString() === unwrap(value).toString();
10
13
  }
11
14
 
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ var newType = require('./newType.cjs');
4
+ var base = require('./primitive/base.cjs');
5
+ var base$1 = require('./constraint/base.cjs');
6
+ var set = require('./constraint/set.cjs');
7
+ var hasSomeKinds = require('../common/hasSomeKinds.cjs');
8
+ var index = require('../pattern/match/index.cjs');
9
+ var transform = require('../dataParser/parsers/transform.cjs');
10
+ var index$1 = require('../dataParser/parsers/string/index.cjs');
11
+ var index$2 = require('../dataParser/parsers/number/index.cjs');
12
+ var index$3 = require('../dataParser/parsers/bigint/index.cjs');
13
+ var boolean = require('../dataParser/parsers/boolean.cjs');
14
+ var date = require('../dataParser/parsers/date.cjs');
15
+ var index$4 = require('../dataParser/parsers/time/index.cjs');
16
+ var empty = require('../dataParser/parsers/empty.cjs');
17
+ var nil = require('../dataParser/parsers/nil.cjs');
18
+ var wrapValue = require('../common/wrapValue.cjs');
19
+
20
+ function toMapDataParser(input, params) {
21
+ const dataParser = (base.primitiveHandlerKind.has(input)
22
+ ? input.dataParser.clone()
23
+ : input.internal.dataParser.clone());
24
+ if (params?.coerce
25
+ && hasSomeKinds.hasSomeKinds(dataParser, [
26
+ index$1.stringKind,
27
+ index$2.numberKind,
28
+ index$3.bigIntKind,
29
+ index$3.bigIntKind,
30
+ boolean.booleanKind,
31
+ date.dateKind,
32
+ index$4.timeKind,
33
+ empty.emptyKind,
34
+ nil.nilKind,
35
+ ])) {
36
+ dataParser.definition.coerce = true;
37
+ }
38
+ const valueContainer = index.match(input)
39
+ .when(newType.newTypeHandlerKind.has, (newType$1) => ({
40
+ ...newType.newTypeKind.setTo({}, newType$1.name),
41
+ ...base$1.constrainedTypeKind.setTo({}, newType$1.internal.constraintKindValue),
42
+ }))
43
+ .when(hasSomeKinds.hasSomeKinds([base$1.constraintHandlerKind, set.constraintsSetHandlerKind]), (constraintOrSet) => base$1.constrainedTypeKind.setTo({}, constraintOrSet.internal.constraintKindValue))
44
+ .when(base.primitiveHandlerKind.has, () => ({}))
45
+ .exhaustive();
46
+ return transform.transform(dataParser, (value) => ({
47
+ ...valueContainer,
48
+ [wrapValue.keyWrappedValue]: value,
49
+ }));
50
+ }
51
+
52
+ exports.toMapDataParser = toMapDataParser;
@@ -0,0 +1,53 @@
1
+ import * as DDataParser from "../dataParser";
2
+ import { type ConstraintHandler, type ConstraintsSetHandler, type GetConstraint, type GetConstraints } from "./constraint";
3
+ import { type GetNewType, type NewTypeHandler } from "./newType";
4
+ import { type PrimitiveHandler } from "./primitive";
5
+ type ToMapDataParserInput = NewTypeHandler<any, any, readonly any[], any> | ConstraintHandler<any, any, readonly any[], any> | ConstraintsSetHandler<any, readonly any[], any> | PrimitiveHandler;
6
+ type OutputDataParser<GenericInput extends ToMapDataParserInput> = GenericInput extends NewTypeHandler<any, any, readonly any[], any> ? GetNewType<GenericInput> : GenericInput extends ConstraintHandler<any, any, readonly any[], any> ? GetConstraint<GenericInput> : GenericInput extends ConstraintsSetHandler<any, readonly any[], any> ? GetConstraints<GenericInput> : GenericInput extends PrimitiveHandler ? ReturnType<GenericInput["createWithUnknownOrThrow"]> : never;
7
+ interface ToMapDataParserParams {
8
+ coerce?: boolean;
9
+ }
10
+ /**
11
+ * Creates a DataParser that maps Clean handlers or primitives into a wrapped value object.
12
+ *
13
+ * **Supported call styles:**
14
+ * - Classic: `toMapDataParser(handler, params?)` -> returns a DataParser
15
+ * - Pipe: `pipe(handler, toMapDataParser)` -> returns a DataParser
16
+ *
17
+ * The resulting parser preserves kind tags (`newTypeKind`, `constrainedTypeKind`) and stores the parsed value under the wrapped value key. When `coerce` is enabled, compatible primitive parsers will coerce inputs before validation.
18
+ *
19
+ * ```ts
20
+ * const ShortLabel = C.createNewType(
21
+ * "ShortLabel",
22
+ * DP.string(),
23
+ * [C.StringMax(5)],
24
+ * );
25
+ *
26
+ * const labelParser = C.toMapDataParser(ShortLabel);
27
+ * labelParser.parseOrThrow("hello");
28
+ *
29
+ * const userIdParser = pipe(
30
+ * C.Number,
31
+ * C.toMapDataParser,
32
+ * );
33
+ * userIdParser.parseOrThrow(42);
34
+ *
35
+ * const coerceParser = C.toMapDataParser(
36
+ * C.String,
37
+ * { coerce: true },
38
+ * );
39
+ * coerceParser.parseOrThrow(123);
40
+ *
41
+ * ```
42
+ *
43
+ * @remarks
44
+ * - Supported inputs: `NewTypeHandler`, `ConstraintHandler`, `ConstraintsSetHandler`, and `PrimitiveHandler`.
45
+ * - Use `coerce: true` to allow conversions (e.g. number to string) on compatible parsers.
46
+ *
47
+ * @see https://utils.duplojs.dev/en/v1/api/clean/toMapDataParser
48
+ *
49
+ * @namespace C
50
+ *
51
+ */
52
+ export declare function toMapDataParser<GenericInput extends ToMapDataParserInput, GenericInputDataParser extends unknown = unknown>(input: GenericInput, params?: ToMapDataParserParams): DDataParser.Contract<OutputDataParser<GenericInput>, GenericInputDataParser>;
53
+ export {};
@@ -0,0 +1,50 @@
1
+ import { newTypeHandlerKind, newTypeKind } from './newType.mjs';
2
+ import { primitiveHandlerKind } from './primitive/base.mjs';
3
+ import { constrainedTypeKind, constraintHandlerKind } from './constraint/base.mjs';
4
+ import { constraintsSetHandlerKind } from './constraint/set.mjs';
5
+ import { hasSomeKinds } from '../common/hasSomeKinds.mjs';
6
+ import { match } from '../pattern/match/index.mjs';
7
+ import { transform } from '../dataParser/parsers/transform.mjs';
8
+ import { stringKind } from '../dataParser/parsers/string/index.mjs';
9
+ import { numberKind } from '../dataParser/parsers/number/index.mjs';
10
+ import { bigIntKind } from '../dataParser/parsers/bigint/index.mjs';
11
+ import { booleanKind } from '../dataParser/parsers/boolean.mjs';
12
+ import { dateKind } from '../dataParser/parsers/date.mjs';
13
+ import { timeKind } from '../dataParser/parsers/time/index.mjs';
14
+ import { emptyKind } from '../dataParser/parsers/empty.mjs';
15
+ import { nilKind } from '../dataParser/parsers/nil.mjs';
16
+ import { keyWrappedValue } from '../common/wrapValue.mjs';
17
+
18
+ function toMapDataParser(input, params) {
19
+ const dataParser = (primitiveHandlerKind.has(input)
20
+ ? input.dataParser.clone()
21
+ : input.internal.dataParser.clone());
22
+ if (params?.coerce
23
+ && hasSomeKinds(dataParser, [
24
+ stringKind,
25
+ numberKind,
26
+ bigIntKind,
27
+ bigIntKind,
28
+ booleanKind,
29
+ dateKind,
30
+ timeKind,
31
+ emptyKind,
32
+ nilKind,
33
+ ])) {
34
+ dataParser.definition.coerce = true;
35
+ }
36
+ const valueContainer = match(input)
37
+ .when(newTypeHandlerKind.has, (newType) => ({
38
+ ...newTypeKind.setTo({}, newType.name),
39
+ ...constrainedTypeKind.setTo({}, newType.internal.constraintKindValue),
40
+ }))
41
+ .when(hasSomeKinds([constraintHandlerKind, constraintsSetHandlerKind]), (constraintOrSet) => constrainedTypeKind.setTo({}, constraintOrSet.internal.constraintKindValue))
42
+ .when(primitiveHandlerKind.has, () => ({}))
43
+ .exhaustive();
44
+ return transform(dataParser, (value) => ({
45
+ ...valueContainer,
46
+ [keyWrappedValue]: value,
47
+ }));
48
+ }
49
+
50
+ export { toMapDataParser };
@@ -80,3 +80,4 @@ export * from "./toRegExp";
80
80
  export * from "./justExec";
81
81
  export * from "./callThen";
82
82
  export * from "./queue";
83
+ export * from "./printer";
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+
3
+ var repeat = require('../string/repeat.cjs');
4
+
5
+ exports.Printer = void 0;
6
+ (function (Printer) {
7
+ const codeColors = {
8
+ red: "\x1b[31m",
9
+ green: "\x1b[32m",
10
+ yellow: "\x1b[33m",
11
+ blue: "\x1b[34m",
12
+ magenta: "\x1b[35m",
13
+ cyan: "\x1b[36m",
14
+ gray: "\x1b[90m",
15
+ };
16
+ const codeBold = "\x1b[1m";
17
+ const codeReset = "\x1b[0m";
18
+ Printer.tab = "\t";
19
+ Printer.back = "\n";
20
+ Printer.dash = "-";
21
+ function colorized(...args) {
22
+ if (args.length === 1) {
23
+ const [color] = args;
24
+ return (input) => colorized(input, color);
25
+ }
26
+ const [input, color] = args;
27
+ return `${codeColors[color]}${input}${codeReset}`;
28
+ }
29
+ Printer.colorized = colorized;
30
+ /**
31
+ * {@include common/printer/bold/index.md}
32
+ */
33
+ function bold(input) {
34
+ return `${codeBold}${input}${codeReset}`;
35
+ }
36
+ Printer.bold = bold;
37
+ function colorizedBold(...args) {
38
+ if (args.length === 1) {
39
+ const [color] = args;
40
+ return (input) => colorizedBold(input, color);
41
+ }
42
+ const [input, color] = args;
43
+ return bold(colorized(input, color));
44
+ }
45
+ Printer.colorizedBold = colorizedBold;
46
+ function indent(level) {
47
+ return repeat.repeat(Printer.tab, level);
48
+ }
49
+ Printer.indent = indent;
50
+ function stringify(value) {
51
+ try {
52
+ return JSON.stringify(value);
53
+ }
54
+ catch {
55
+ return String(value);
56
+ }
57
+ }
58
+ Printer.stringify = stringify;
59
+ function render(...args) {
60
+ if (args.length === 1) {
61
+ const [joinCharacter] = args;
62
+ return (values) => render(values, joinCharacter);
63
+ }
64
+ const [values, joinCharacter] = args;
65
+ return values
66
+ .flat(Infinity)
67
+ .filter((value) => typeof value === "string" || value === true)
68
+ .join(joinCharacter);
69
+ }
70
+ Printer.render = render;
71
+ Printer.renderLine = render(" ");
72
+ Printer.renderParagraph = render(Printer.back);
73
+ })(exports.Printer || (exports.Printer = {}));
@@ -0,0 +1,139 @@
1
+ export declare namespace Printer {
2
+ const codeColors: {
3
+ readonly red: "\u001B[31m";
4
+ readonly green: "\u001B[32m";
5
+ readonly yellow: "\u001B[33m";
6
+ readonly blue: "\u001B[34m";
7
+ readonly magenta: "\u001B[35m";
8
+ readonly cyan: "\u001B[36m";
9
+ readonly gray: "\u001B[90m";
10
+ };
11
+ export const tab = "\t";
12
+ export const back = "\n";
13
+ export const dash = "-";
14
+ export type Colors = keyof typeof codeColors;
15
+ /**
16
+ * Wraps a string with the ANSI escape sequence of the selected color. Exists in immediate or curried form.
17
+ *
18
+ * **Supported call styles:**
19
+ * - Classic: `Printer.colorized(input, color)` -> returns the colored string
20
+ * - Curried: `Printer.colorized(color)` -> returns a function waiting for the string
21
+ *
22
+ * The function only adds the opening color code and the reset code around the input string.
23
+ *
24
+ * ```ts
25
+ * const directResult = Printer.colorized("Hello", "green");
26
+ * // directResult: "\x1b[32mHello\x1b[0m"
27
+ *
28
+ * const pipedResult = pipe(
29
+ * "Warning",
30
+ * Printer.colorized("yellow"),
31
+ * );
32
+ * // pipedResult: "\x1b[33mWarning\x1b[0m"
33
+ *
34
+ * const errorResult = Printer.colorized("Error", "red");
35
+ * // errorResult: "\x1b[31mError\x1b[0m"
36
+ *
37
+ * ```
38
+ *
39
+ * @see https://utils.duplojs.dev/en/v1/api/common/printer/colorized
40
+ *
41
+ */
42
+ export function colorized<GenericInput extends string>(color: Colors): (input: GenericInput) => string;
43
+ export function colorized<GenericInput extends string>(input: GenericInput, color: Colors): string;
44
+ /**
45
+ * Wraps a string with the ANSI escape sequence for bold text.
46
+ *
47
+ * Signature: `Printer.bold(input)` -> returns the bold string
48
+ *
49
+ * The function prepends the bold code and appends the reset code without altering the input content.
50
+ *
51
+ * ```ts
52
+ * const title = Printer.bold("Build report");
53
+ * // title: "\x1b[1mBuild report\x1b[0m"
54
+ *
55
+ * const symbol = Printer.bold("!");
56
+ * // symbol: "\x1b[1m!\x1b[0m"
57
+ *
58
+ * const empty = Printer.bold("");
59
+ * // empty: "\x1b[1m\x1b[0m"
60
+ *
61
+ * ```
62
+ *
63
+ * @see https://utils.duplojs.dev/en/v1/api/common/printer/bold
64
+ *
65
+ */
66
+ export function bold(input: string): string;
67
+ /**
68
+ * Applies a color and bold formatting to a string by combining `Printer.colorized()` and `Printer.bold()`. Exists in immediate or curried form.
69
+ *
70
+ * **Supported call styles:**
71
+ * - Classic: `Printer.colorizedBold(input, color)` -> returns the formatted string
72
+ * - Curried: `Printer.colorizedBold(color)` -> returns a function waiting for the string
73
+ *
74
+ * The produced string contains the bold ANSI code, then the colorized content, and finally the reset codes.
75
+ *
76
+ * ```ts
77
+ * const directResult = Printer.colorizedBold("Fatal", "red");
78
+ * // directResult: "\x1b[1m\x1b[31mFatal\x1b[0m\x1b[0m"
79
+ *
80
+ * const pipedResult = pipe(
81
+ * "Info",
82
+ * Printer.colorizedBold("cyan"),
83
+ * );
84
+ * // pipedResult: "\x1b[1m\x1b[36mInfo\x1b[0m\x1b[0m"
85
+ *
86
+ * const successResult = Printer.colorizedBold("Done", "green");
87
+ * // successResult: "\x1b[1m\x1b[32mDone\x1b[0m\x1b[0m"
88
+ *
89
+ * ```
90
+ *
91
+ * @see https://utils.duplojs.dev/en/v1/api/common/printer/colorizedBold
92
+ *
93
+ */
94
+ export function colorizedBold<GenericInput extends string>(color: Colors): (input: GenericInput) => string;
95
+ export function colorizedBold<GenericInput extends string>(input: GenericInput, color: Colors): string;
96
+ export function indent(level: number): string;
97
+ export function stringify(value: unknown): string;
98
+ export type RenderInput = string | boolean | null | undefined | RenderInput[];
99
+ /**
100
+ * Flattens printable values, keeps strings and `true`, then joins the result with a custom separator. Exists in immediate or curried form.
101
+ *
102
+ * **Supported call styles:**
103
+ * - Classic: `Printer.render(values, joinCharacter)` -> returns the rendered string
104
+ * - Curried: `Printer.render(joinCharacter)` -> returns a function waiting for the values array
105
+ *
106
+ * Nested arrays are flattened recursively. `false`, `null`, and `undefined` are ignored, while `true` is kept as the string `"true"`.
107
+ * The namespace also exposes two ready-to-use defaults: `Printer.renderLine`, which joins with a space, and `Printer.renderParagraph`, which joins with `Printer.back`.
108
+ *
109
+ * ```ts
110
+ * const customResult = Printer.render(
111
+ * ["alpha", ["beta", false], true, undefined],
112
+ * " | ",
113
+ * );
114
+ * // customResult: "alpha | beta | true"
115
+ *
116
+ * const lineResult = Printer.renderLine([
117
+ * "hello",
118
+ * ["world", null],
119
+ * true,
120
+ * ]);
121
+ * // lineResult: "hello world true"
122
+ *
123
+ * const paragraphResult = pipe(
124
+ * ["title", ["", "body"], false, true] as const,
125
+ * Printer.renderParagraph,
126
+ * );
127
+ * // paragraphResult: "title\n\nbody\ntrue"
128
+ *
129
+ * ```
130
+ *
131
+ * @see https://utils.duplojs.dev/en/v1/api/common/printer/render
132
+ *
133
+ */
134
+ export function render<GenericValues extends readonly RenderInput[]>(joinCharacter: string): (values: GenericValues) => string;
135
+ export function render<GenericValues extends readonly RenderInput[]>(values: GenericValues, joinCharacter: string): string;
136
+ export const renderLine: (values: readonly RenderInput[]) => string;
137
+ export const renderParagraph: (values: readonly RenderInput[]) => string;
138
+ export {};
139
+ }
@@ -0,0 +1,73 @@
1
+ import { repeat } from '../string/repeat.mjs';
2
+
3
+ var Printer;
4
+ (function (Printer) {
5
+ const codeColors = {
6
+ red: "\x1b[31m",
7
+ green: "\x1b[32m",
8
+ yellow: "\x1b[33m",
9
+ blue: "\x1b[34m",
10
+ magenta: "\x1b[35m",
11
+ cyan: "\x1b[36m",
12
+ gray: "\x1b[90m",
13
+ };
14
+ const codeBold = "\x1b[1m";
15
+ const codeReset = "\x1b[0m";
16
+ Printer.tab = "\t";
17
+ Printer.back = "\n";
18
+ Printer.dash = "-";
19
+ function colorized(...args) {
20
+ if (args.length === 1) {
21
+ const [color] = args;
22
+ return (input) => colorized(input, color);
23
+ }
24
+ const [input, color] = args;
25
+ return `${codeColors[color]}${input}${codeReset}`;
26
+ }
27
+ Printer.colorized = colorized;
28
+ /**
29
+ * {@include common/printer/bold/index.md}
30
+ */
31
+ function bold(input) {
32
+ return `${codeBold}${input}${codeReset}`;
33
+ }
34
+ Printer.bold = bold;
35
+ function colorizedBold(...args) {
36
+ if (args.length === 1) {
37
+ const [color] = args;
38
+ return (input) => colorizedBold(input, color);
39
+ }
40
+ const [input, color] = args;
41
+ return bold(colorized(input, color));
42
+ }
43
+ Printer.colorizedBold = colorizedBold;
44
+ function indent(level) {
45
+ return repeat(Printer.tab, level);
46
+ }
47
+ Printer.indent = indent;
48
+ function stringify(value) {
49
+ try {
50
+ return JSON.stringify(value);
51
+ }
52
+ catch {
53
+ return String(value);
54
+ }
55
+ }
56
+ Printer.stringify = stringify;
57
+ function render(...args) {
58
+ if (args.length === 1) {
59
+ const [joinCharacter] = args;
60
+ return (values) => render(values, joinCharacter);
61
+ }
62
+ const [values, joinCharacter] = args;
63
+ return values
64
+ .flat(Infinity)
65
+ .filter((value) => typeof value === "string" || value === true)
66
+ .join(joinCharacter);
67
+ }
68
+ Printer.render = render;
69
+ Printer.renderLine = render(" ");
70
+ Printer.renderParagraph = render(Printer.back);
71
+ })(Printer || (Printer = {}));
72
+
73
+ export { Printer };
@@ -1,2 +1 @@
1
- import { type IsEqual } from "./isEqual";
2
- export type And<GenericBooleans extends [boolean, ...boolean[]]> = IsEqual<GenericBooleans[number], true>;
1
+ export type And<GenericBooleans extends [boolean, ...boolean[]]> = GenericBooleans[number] extends true ? true : false;
@@ -1,2 +1 @@
1
- import { type IsEqual } from "./isEqual";
2
- export type Or<GenericBooleans extends [boolean, ...boolean[]]> = IsEqual<GenericBooleans[number] | false, boolean>;
1
+ export type Or<GenericBooleans extends [boolean, ...boolean[]]> = GenericBooleans[number] extends false ? false : true;