@clipboard-health/util-ts 2.9.7 → 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
|
@@ -69,3 +69,11 @@ export declare function getOrElse<A>(defaultValue: A): (option: Option<A>) => A;
|
|
|
69
69
|
* @returns The result of either `onNone` or `onSome` based on the `Option` state
|
|
70
70
|
*/
|
|
71
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":";;;
|
|
1
|
+
{"version":3,"file":"option.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/functional/option.ts"],"names":[],"mappings":";;;AA8BA,oBAEC;AAQD,wBAEC;AAQD,wBAEC;AASD,kBAEC;AASD,0BAEC;AASD,8BAEC;AASD,sBAKC;AAUD,oCAEC;AA/GD,wCAAmC;AAmBnC;;GAEG;AACU,QAAA,IAAI,GAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAE5C;;;;;GAKG;AACH,SAAgB,IAAI,CAAI,KAAQ;IAC9B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,MAAM,CAAI,MAAiB;IACzC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;AACxB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,MAAM,CAAI,MAAiB;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,GAAG,CAAO,CAAc;IACtC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,YAAI,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,OAAO,CAAO,CAAsB;IAClD,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAA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