@duplojs/utils 1.4.33 → 1.4.34

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 (69) hide show
  1. package/dist/common/createKindIdentifier.d.ts +2 -2
  2. package/dist/dataParser/base.cjs +0 -1
  3. package/dist/dataParser/base.d.ts +0 -4
  4. package/dist/dataParser/base.mjs +0 -1
  5. package/dist/dataParser/baseExtended.cjs +0 -3
  6. package/dist/dataParser/baseExtended.d.ts +0 -4
  7. package/dist/dataParser/baseExtended.mjs +0 -3
  8. package/dist/dataParser/extended/array.d.ts +3 -13
  9. package/dist/dataParser/extended/bigint.d.ts +3 -13
  10. package/dist/dataParser/extended/boolean.d.ts +1 -7
  11. package/dist/dataParser/extended/date.d.ts +1 -7
  12. package/dist/dataParser/extended/empty.d.ts +1 -7
  13. package/dist/dataParser/extended/lazy.d.ts +1 -7
  14. package/dist/dataParser/extended/literal.d.ts +1 -7
  15. package/dist/dataParser/extended/nil.d.ts +1 -7
  16. package/dist/dataParser/extended/nullable.d.ts +1 -7
  17. package/dist/dataParser/extended/number.d.ts +4 -16
  18. package/dist/dataParser/extended/object.d.ts +1 -7
  19. package/dist/dataParser/extended/optional.d.ts +1 -7
  20. package/dist/dataParser/extended/pipe.d.ts +1 -7
  21. package/dist/dataParser/extended/record.d.ts +1 -7
  22. package/dist/dataParser/extended/recover.d.ts +1 -7
  23. package/dist/dataParser/extended/string.d.ts +4 -16
  24. package/dist/dataParser/extended/templateLiteral.d.ts +1 -7
  25. package/dist/dataParser/extended/time.d.ts +3 -13
  26. package/dist/dataParser/extended/transform.d.ts +1 -7
  27. package/dist/dataParser/extended/tuple.d.ts +3 -13
  28. package/dist/dataParser/extended/union.d.ts +1 -7
  29. package/dist/dataParser/extended/unknown.d.ts +1 -7
  30. package/dist/dataParser/identifier.d.ts +2 -2
  31. package/dist/dataParser/parsers/array/index.d.ts +0 -4
  32. package/dist/dataParser/parsers/bigint/index.d.ts +0 -4
  33. package/dist/dataParser/parsers/boolean.d.ts +0 -4
  34. package/dist/dataParser/parsers/date.d.ts +0 -4
  35. package/dist/dataParser/parsers/empty.d.ts +0 -4
  36. package/dist/dataParser/parsers/lazy.d.ts +0 -4
  37. package/dist/dataParser/parsers/literal.d.ts +0 -4
  38. package/dist/dataParser/parsers/nil.d.ts +0 -4
  39. package/dist/dataParser/parsers/nullable.d.ts +0 -4
  40. package/dist/dataParser/parsers/number/index.d.ts +0 -4
  41. package/dist/dataParser/parsers/object/index.d.ts +0 -4
  42. package/dist/dataParser/parsers/optional.d.ts +0 -4
  43. package/dist/dataParser/parsers/pipe.d.ts +0 -4
  44. package/dist/dataParser/parsers/record/index.d.ts +0 -4
  45. package/dist/dataParser/parsers/recover.d.ts +0 -4
  46. package/dist/dataParser/parsers/string/index.d.ts +0 -4
  47. package/dist/dataParser/parsers/templateLiteral/createTemplateLiteralPattern.cjs +2 -2
  48. package/dist/dataParser/parsers/templateLiteral/createTemplateLiteralPattern.mjs +2 -2
  49. package/dist/dataParser/parsers/templateLiteral/index.d.ts +11 -15
  50. package/dist/dataParser/parsers/time/index.d.ts +0 -4
  51. package/dist/dataParser/parsers/transform.d.ts +0 -4
  52. package/dist/dataParser/parsers/tuple.d.ts +0 -4
  53. package/dist/dataParser/parsers/union.d.ts +0 -4
  54. package/dist/dataParser/parsers/unknown.d.ts +0 -4
  55. package/dist/dataParser/types/addCheckersToDefinition.d.ts +2 -2
  56. package/dist/either/future/create.d.ts +2 -2
  57. package/dist/either/right/asyncPipe.d.ts +7 -11
  58. package/dist/either/right/pipe.d.ts +7 -7
  59. package/dist/metadata.json +9 -0
  60. package/dist/object/countKeys.cjs +3 -0
  61. package/dist/object/countKeys.d.ts +27 -0
  62. package/dist/object/countKeys.mjs +3 -0
  63. package/dist/pattern/index.cjs +2 -0
  64. package/dist/pattern/index.d.ts +1 -0
  65. package/dist/pattern/index.mjs +1 -0
  66. package/dist/pattern/whenNot.cjs +17 -0
  67. package/dist/pattern/whenNot.d.ts +49 -0
  68. package/dist/pattern/whenNot.mjs +15 -0
  69. package/package.json +1 -1
@@ -5,6 +5,7 @@ export { match } from './match/index.mjs';
5
5
  export { isMatch } from './isMatch.mjs';
6
6
  export { union } from './union.mjs';
7
7
  export { when } from './when.mjs';
8
+ export { whenNot } from './whenNot.mjs';
8
9
  export { InvalidExhaustivePatternError, matchBuilder } from './match/builder.mjs';
9
10
  export { SymbolToolPatternFunctionLabel } from './types/pattern.mjs';
10
11
 
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var result = require('./result.cjs');
4
+
5
+ function whenNot(...args) {
6
+ if (args.length === 2) {
7
+ const [predicate, theFunction] = args;
8
+ return (input) => whenNot(input, predicate, theFunction);
9
+ }
10
+ const [input, predicate, theFunction] = args;
11
+ if (!result.isResult(input) && !predicate(input)) {
12
+ return result.result(theFunction(input));
13
+ }
14
+ return input;
15
+ }
16
+
17
+ exports.whenNot = whenNot;
@@ -0,0 +1,49 @@
1
+ import { type AnyValue, type BreakGenericLink, type IsEqual, type EscapeVoid } from "../common";
2
+ import { type PatternResult } from "./result";
3
+ /**
4
+ * Applies a handler when a predicate fails.
5
+ *
6
+ * **Supported call styles:**
7
+ * - Classic: `whenNot(input, predicate, handler)` -> returns a result or the input
8
+ * - Curried: `whenNot(predicate, handler)` -> returns a function waiting for the input
9
+ * - Classic predicate: `whenNot(input, isType, handler)` -> narrows input types
10
+ * - Curried predicate: `whenNot(isType, handler)` -> narrows input types
11
+ *
12
+ * If the predicate fails, the handler runs and the result is wrapped for chaining.
13
+ * The input is not mutated.
14
+ *
15
+ * ```ts
16
+ * pipe(
17
+ * 2,
18
+ * P.whenNot(
19
+ * (value) => value > 3,
20
+ * (value) => value * 2,
21
+ * ),
22
+ * P.otherwise((value) => value),
23
+ * ); // 4
24
+ *
25
+ * A.map(
26
+ * <const>["alpha", 2],
27
+ * innerPipe(
28
+ * P.whenNot(
29
+ * isType("string"),
30
+ * (value) => value + 1,
31
+ * ),
32
+ * P.otherwise((value) => value),
33
+ * ),
34
+ * ); // ["alpha", 3]
35
+ * ```
36
+ *
37
+ * @remarks
38
+ * - Predicate overloads (type guards) narrow the output type
39
+ *
40
+ * @see [`P.otherwise`](https://utils.duplojs.dev/en/v1/api/pattern/otherwise) For fallbacks
41
+ * @see https://utils.duplojs.dev/en/v1/api/pattern/whenNot
42
+ *
43
+ * @namespace P
44
+ *
45
+ */
46
+ export declare function whenNot<GenericInput extends unknown, GenericInputValue extends Exclude<IsEqual<GenericInput, unknown> extends true ? AnyValue : GenericInput, PatternResult>, GenericInputPatternResult extends Extract<GenericInput, PatternResult>, GenericPredicatedInput extends GenericInputValue, GenericOutput extends AnyValue | EscapeVoid>(predicate: (input: GenericInputValue) => input is GenericPredicatedInput, theFunction: (predicatedInput: Exclude<GenericInputValue, GenericPredicatedInput>) => GenericOutput): (input: (GenericInput | GenericInputPatternResult | GenericInputValue)) => (GenericInputPatternResult | Exclude<BreakGenericLink<GenericInput>, Exclude<GenericInputValue, GenericPredicatedInput> | PatternResult> | PatternResult<GenericOutput>);
47
+ export declare function whenNot<GenericInput extends unknown, GenericInputValue extends Exclude<IsEqual<GenericInput, unknown> extends true ? AnyValue : GenericInput, PatternResult>, GenericInputPatternResult extends Extract<GenericInput, PatternResult>, GenericOutput extends AnyValue | EscapeVoid>(predicate: (input: GenericInputValue) => boolean, theFunction: (predicatedInput: GenericInputValue) => GenericOutput): (input: (GenericInput | GenericInputPatternResult | GenericInputValue)) => (GenericInputPatternResult | GenericInputValue | PatternResult<GenericOutput>);
48
+ export declare function whenNot<GenericInput extends unknown, GenericInputValue extends Exclude<IsEqual<GenericInput, unknown> extends true ? AnyValue : GenericInput, PatternResult>, GenericInputPatternResult extends Extract<GenericInput, PatternResult>, GenericPredicatedInput extends GenericInputValue, GenericOutput extends AnyValue | EscapeVoid>(input: (GenericInput | GenericInputPatternResult | GenericInputValue), predicate: (input: GenericInputValue) => input is GenericPredicatedInput, theFunction: (predicatedInput: Exclude<GenericInputValue, GenericPredicatedInput>) => GenericOutput): (GenericInputPatternResult | Exclude<BreakGenericLink<GenericInput>, Exclude<GenericInputValue, GenericPredicatedInput> | PatternResult> | PatternResult<GenericOutput>);
49
+ export declare function whenNot<GenericInput extends unknown, GenericInputValue extends Exclude<IsEqual<GenericInput, unknown> extends true ? AnyValue : GenericInput, PatternResult>, GenericInputPatternResult extends Extract<GenericInput, PatternResult>, GenericOutput extends AnyValue | EscapeVoid>(input: (GenericInput | GenericInputPatternResult | GenericInputValue), predicate: (input: GenericInputValue) => boolean, theFunction: (predicatedInput: GenericInputValue) => GenericOutput): (GenericInputPatternResult | GenericInputValue | PatternResult<GenericOutput>);
@@ -0,0 +1,15 @@
1
+ import { isResult, result } from './result.mjs';
2
+
3
+ function whenNot(...args) {
4
+ if (args.length === 2) {
5
+ const [predicate, theFunction] = args;
6
+ return (input) => whenNot(input, predicate, theFunction);
7
+ }
8
+ const [input, predicate, theFunction] = args;
9
+ if (!isResult(input) && !predicate(input)) {
10
+ return result(theFunction(input));
11
+ }
12
+ return input;
13
+ }
14
+
15
+ export { whenNot };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.4.33",
3
+ "version": "1.4.34",
4
4
  "author": {
5
5
  "name": "mathcovax",
6
6
  "url": "https://github.com/mathcovax"