@clipboard-health/util-ts 2.9.6 → 2.10.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipboard-health/util-ts",
3
3
  "description": "TypeScript utilities.",
4
- "version": "2.9.6",
4
+ "version": "2.10.0",
5
5
  "dependencies": {
6
6
  "tslib": "2.8.0"
7
7
  },
package/src/index.d.ts CHANGED
@@ -1,20 +1,8 @@
1
- export * from "./lib/arrays/head";
2
- export * from "./lib/arrays/nonEmptyArray";
1
+ export * from "./lib/arrays";
3
2
  export * from "./lib/deepFreeze";
4
- export * from "./lib/errors/cbhError";
5
- export * from "./lib/errors/isError";
6
- export * from "./lib/errors/serviceError";
7
- export * from "./lib/errors/toError";
8
- export * from "./lib/errors/toErrorMessage";
3
+ export * from "./lib/errors";
9
4
  export * from "./lib/forceCast";
10
- export * from "./lib/functional/cbhResponse";
11
- export * as either from "./lib/functional/either";
12
- export * as option from "./lib/functional/option";
13
- export * from "./lib/functional/pipe";
14
- export * from "./lib/functional/serviceResult";
15
- export * from "./lib/nullish/isDefined";
16
- export * from "./lib/nullish/isNil";
17
- export * from "./lib/nullish/nullToUndefined";
18
- export * from "./lib/strings/isString";
19
- export * from "./lib/strings/stringify";
5
+ export * from "./lib/functional";
6
+ export * from "./lib/nullish";
7
+ export * from "./lib/strings";
20
8
  export * from "./lib/types";
package/src/index.js CHANGED
@@ -1,25 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.option = exports.either = void 0;
4
3
  const tslib_1 = require("tslib");
5
- tslib_1.__exportStar(require("./lib/arrays/head"), exports);
6
- tslib_1.__exportStar(require("./lib/arrays/nonEmptyArray"), exports);
4
+ tslib_1.__exportStar(require("./lib/arrays"), exports);
7
5
  tslib_1.__exportStar(require("./lib/deepFreeze"), exports);
8
- tslib_1.__exportStar(require("./lib/errors/cbhError"), exports);
9
- tslib_1.__exportStar(require("./lib/errors/isError"), exports);
10
- tslib_1.__exportStar(require("./lib/errors/serviceError"), exports);
11
- tslib_1.__exportStar(require("./lib/errors/toError"), exports);
12
- tslib_1.__exportStar(require("./lib/errors/toErrorMessage"), exports);
6
+ tslib_1.__exportStar(require("./lib/errors"), exports);
13
7
  tslib_1.__exportStar(require("./lib/forceCast"), exports);
14
- tslib_1.__exportStar(require("./lib/functional/cbhResponse"), exports);
15
- exports.either = tslib_1.__importStar(require("./lib/functional/either"));
16
- exports.option = tslib_1.__importStar(require("./lib/functional/option"));
17
- tslib_1.__exportStar(require("./lib/functional/pipe"), exports);
18
- tslib_1.__exportStar(require("./lib/functional/serviceResult"), exports);
19
- tslib_1.__exportStar(require("./lib/nullish/isDefined"), exports);
20
- tslib_1.__exportStar(require("./lib/nullish/isNil"), exports);
21
- tslib_1.__exportStar(require("./lib/nullish/nullToUndefined"), exports);
22
- tslib_1.__exportStar(require("./lib/strings/isString"), exports);
23
- tslib_1.__exportStar(require("./lib/strings/stringify"), exports);
8
+ tslib_1.__exportStar(require("./lib/functional"), exports);
9
+ tslib_1.__exportStar(require("./lib/nullish"), exports);
10
+ tslib_1.__exportStar(require("./lib/strings"), exports);
24
11
  tslib_1.__exportStar(require("./lib/types"), exports);
25
12
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":";;;;AAAA,4DAAkC;AAClC,qEAA2C;AAC3C,2DAAiC;AACjC,gEAAsC;AACtC,+DAAqC;AACrC,oEAA0C;AAC1C,+DAAqC;AACrC,sEAA4C;AAC5C,0DAAgC;AAChC,uEAA6C;AAC7C,0EAAkD;AAClD,0EAAkD;AAClD,gEAAsC;AACtC,yEAA+C;AAC/C,kEAAwC;AACxC,8DAAoC;AACpC,wEAA8C;AAC9C,iEAAuC;AACvC,kEAAwC;AACxC,sDAA4B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,2DAAiC;AACjC,uDAA6B;AAC7B,0DAAgC;AAChC,2DAAiC;AACjC,wDAA8B;AAC9B,wDAA8B;AAC9B,sDAA4B"}
@@ -0,0 +1,2 @@
1
+ export * from "./head";
2
+ export * from "./nonEmptyArray";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./head"), exports);
5
+ tslib_1.__exportStar(require("./nonEmptyArray"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/arrays/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,0DAAgC"}
@@ -0,0 +1,5 @@
1
+ export * from "./cbhError";
2
+ export * from "./isError";
3
+ export * from "./serviceError";
4
+ export * from "./toError";
5
+ export * from "./toErrorMessage";
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./cbhError"), exports);
5
+ tslib_1.__exportStar(require("./isError"), exports);
6
+ tslib_1.__exportStar(require("./serviceError"), exports);
7
+ tslib_1.__exportStar(require("./toError"), exports);
8
+ tslib_1.__exportStar(require("./toErrorMessage"), exports);
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/errors/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,oDAA0B;AAC1B,yDAA+B;AAC/B,oDAA0B;AAC1B,2DAAiC"}
@@ -81,6 +81,6 @@ export declare function getOrElse<E, A>(onLeft: (left: E) => A): (either: Either
81
81
  *
82
82
  * @param onLeft - Function to handle the `Left` case
83
83
  * @param onRight - Function to handle the `Right` case
84
- * @returns The result of `Either` `onLeft` or `onRight` based on the `Either` state
84
+ * @returns The result of either `onLeft` or `onRight` based on the `Either` state
85
85
  */
86
- export declare function match<E, A, B>(onLeft: (left: E) => B, onRight: (right: A) => B): (either: Either<E, A>) => B;
86
+ export declare function match<E, A, B, C>(onLeft: (left: E) => B, onRight: (right: A) => C): (either: Either<E, A>) => B | C;
@@ -89,7 +89,7 @@ function getOrElse(onLeft) {
89
89
  *
90
90
  * @param onLeft - Function to handle the `Left` case
91
91
  * @param onRight - Function to handle the `Right` case
92
- * @returns The result of `Either` `onLeft` or `onRight` based on the `Either` state
92
+ * @returns The result of either `onLeft` or `onRight` based on the `Either` state
93
93
  */
94
94
  function match(onLeft, onRight) {
95
95
  return (either) => (isRight(either) ? onRight(either.right) : onLeft(either.left));
@@ -0,0 +1,5 @@
1
+ export * from "./cbhResponse";
2
+ export * as either from "./either";
3
+ export * as option from "./option";
4
+ export * from "./pipe";
5
+ export * from "./serviceResult";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.option = exports.either = void 0;
4
+ const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./cbhResponse"), exports);
6
+ exports.either = tslib_1.__importStar(require("./either"));
7
+ exports.option = tslib_1.__importStar(require("./option"));
8
+ tslib_1.__exportStar(require("./pipe"), exports);
9
+ tslib_1.__exportStar(require("./serviceResult"), exports);
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/functional/index.ts"],"names":[],"mappings":";;;;AAAA,wDAA8B;AAC9B,2DAAmC;AACnC,2DAAmC;AACnC,iDAAuB;AACvB,0DAAgC"}
@@ -68,4 +68,12 @@ export declare function getOrElse<A>(defaultValue: A): (option: Option<A>) => A;
68
68
  * @param onSome - Function to handle the `Some` case
69
69
  * @returns The result of either `onNone` or `onSome` based on the `Option` state
70
70
  */
71
- export declare function match<A, B>(onNone: () => B, onSome: (value: A) => B): (option: Option<A>) => B;
71
+ export declare function match<A, B, C>(onNone: () => B, onSome: (value: A) => C): (option: Option<A>) => B | C;
72
+ /**
73
+ * Converts a nullable value to an `Option`. If the value is `null` or `undefined`, returns `None`.
74
+ * Otherwise, returns `Some(value)`.
75
+ *
76
+ * @param value - The value to convert
77
+ * @returns An `Option` representing the nullable value
78
+ */
79
+ export declare function fromNullable<A>(value: A | null | undefined): Option<A>;
@@ -8,6 +8,8 @@ exports.map = map;
8
8
  exports.flatMap = flatMap;
9
9
  exports.getOrElse = getOrElse;
10
10
  exports.match = match;
11
+ exports.fromNullable = fromNullable;
12
+ const nullish_1 = require("../nullish");
11
13
  /**
12
14
  * Constructs an `Option` of `None`, representing a missing value.
13
15
  */
@@ -79,4 +81,15 @@ function getOrElse(defaultValue) {
79
81
  function match(onNone, onSome) {
80
82
  return (option) => (isSome(option) ? onSome(option.value) : onNone());
81
83
  }
84
+ /**
85
+ * Converts a nullable value to an `Option`. If the value is `null` or `undefined`, returns `None`.
86
+ * Otherwise, returns `Some(value)`.
87
+ *
88
+ * @param value - The value to convert
89
+ * @returns An `Option` representing the nullable value
90
+ */
91
+ // eslint-disable-next-line @typescript-eslint/ban-types
92
+ function fromNullable(value) {
93
+ return (0, nullish_1.isNil)(value) ? exports.none : some(value);
94
+ }
82
95
  //# sourceMappingURL=option.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"option.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/functional/option.ts"],"names":[],"mappings":";;;AA4BA,oBAEC;AAQD,wBAEC;AAQD,wBAEC;AASD,kBAEC;AASD,0BAEC;AASD,8BAEC;AASD,sBAEC;AA7ED;;GAEG;AACU,QAAA,IAAI,GAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAE5C;;;;;GAKG;AACH,SAAgB,IAAI,CAAI,KAAQ;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ACH,SAAgB,KAAK,CACnB,MAAe,EACf,MAAuB;IAEvB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;GAMG;AACH,wDAAwD;AACxD,SAAgB,YAAY,CAAI,KAA2B;IACzD,OAAO,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./isDefined";
2
+ export * from "./isNil";
3
+ export * from "./nullToUndefined";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./isDefined"), exports);
5
+ tslib_1.__exportStar(require("./isNil"), exports);
6
+ tslib_1.__exportStar(require("./nullToUndefined"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/nullish/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,kDAAwB;AACxB,4DAAkC"}
@@ -0,0 +1,2 @@
1
+ export * from "./isString";
2
+ export * from "./stringify";
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./isString"), exports);
5
+ tslib_1.__exportStar(require("./stringify"), exports);
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/strings/index.ts"],"names":[],"mappings":";;;AAAA,qDAA2B;AAC3B,sDAA4B"}