@clipboard-health/util-ts 2.1.3 → 2.2.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@clipboard-health/util-ts",
3
- "version": "2.1.3",
3
+ "version": "2.2.1",
4
4
  "main": "./src/index.js",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
package/src/index.d.ts CHANGED
@@ -3,12 +3,14 @@ export * from "./lib/cbh-error";
3
3
  export * from "./lib/cbh-response";
4
4
  export * from "./lib/defined-utils";
5
5
  export * from "./lib/delay";
6
+ export * from "./lib/either";
6
7
  export * from "./lib/force-cast";
7
8
  export * from "./lib/head";
8
9
  export * from "./lib/identity";
9
10
  export * from "./lib/is-string";
10
11
  export * from "./lib/non-empty-array";
11
12
  export * from "./lib/null-to-undefined";
13
+ export * from "./lib/option";
12
14
  export * from "./lib/stringify";
13
15
  export * from "./lib/to-error";
14
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
package/src/index.js CHANGED
@@ -6,12 +6,14 @@ tslib_1.__exportStar(require("./lib/cbh-error"), exports);
6
6
  tslib_1.__exportStar(require("./lib/cbh-response"), exports);
7
7
  tslib_1.__exportStar(require("./lib/defined-utils"), exports);
8
8
  tslib_1.__exportStar(require("./lib/delay"), exports);
9
+ tslib_1.__exportStar(require("./lib/either"), exports);
9
10
  tslib_1.__exportStar(require("./lib/force-cast"), exports);
10
11
  tslib_1.__exportStar(require("./lib/head"), exports);
11
12
  tslib_1.__exportStar(require("./lib/identity"), exports);
12
13
  tslib_1.__exportStar(require("./lib/is-string"), exports);
13
14
  tslib_1.__exportStar(require("./lib/non-empty-array"), exports);
14
15
  tslib_1.__exportStar(require("./lib/null-to-undefined"), exports);
16
+ tslib_1.__exportStar(require("./lib/option"), exports);
15
17
  tslib_1.__exportStar(require("./lib/stringify"), exports);
16
18
  tslib_1.__exportStar(require("./lib/to-error"), exports);
17
19
  //# 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,2DAAiC;AACjC,0DAAgC;AAChC,6DAAmC;AACnC,8DAAoC;AACpC,sDAA4B;AAC5B,2DAAiC;AACjC,qDAA2B;AAC3B,yDAA+B;AAC/B,0DAAgC;AAChC,gEAAsC;AACtC,kEAAwC;AACxC,0DAAgC;AAChC,yDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/util-ts/src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAiC;AACjC,0DAAgC;AAChC,6DAAmC;AACnC,8DAAoC;AACpC,sDAA4B;AAC5B,uDAA6B;AAC7B,2DAAiC;AACjC,qDAA2B;AAC3B,yDAA+B;AAC/B,0DAAgC;AAChC,gEAAsC;AACtC,kEAAwC;AACxC,uDAA6B;AAC7B,0DAAgC;AAChC,yDAA+B"}
@@ -0,0 +1,32 @@
1
+ export interface Left<E> {
2
+ isRight: false;
3
+ left: E;
4
+ }
5
+ export interface Right<A> {
6
+ isRight: true;
7
+ right: A;
8
+ }
9
+ /**
10
+ * A value of either type `Left<E>` or type `Right<A>`; a disjoint union.
11
+ *
12
+ * A common use case is as an alternative to {@link Option} where `Left<E>` contains useful
13
+ * information. Convention dictates that `Left<E>` is used for failure and `Right<A>` for success.
14
+ */
15
+ export type Either<E, A> = Left<E> | Right<A>;
16
+ /**
17
+ * Constructs an `Either` holding a `Left<E>` value, usually representing a failure.
18
+ */
19
+ export declare function left<E, A = never>(left: E): Either<E, A>;
20
+ /**
21
+ * Constructs an `Either` holding a `Right<A>` value, usually representing a success.
22
+ */
23
+ export declare function right<A, E = never>(right: A): Either<E, A>;
24
+ /**
25
+ * Returns `true` if the either is `Left<E>`, `false` otherwise.
26
+ */
27
+ export declare function isLeft<E, A>(either: Either<E, A>): either is Left<E>;
28
+ /**
29
+ * Returns `true` if the either is `Right<A>`, `false` otherwise.
30
+ */
31
+ export declare function isRight<E, A>(either: Either<E, A>): either is Right<A>;
32
+ //# sourceMappingURL=either.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"either.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/either.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,OAAO,EAAE,KAAK,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,OAAO,EAAE,IAAI,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;;;;GAKG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;AAE9C;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAExD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAE1D;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,CAEpE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAEtE"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.left = left;
4
+ exports.right = right;
5
+ exports.isLeft = isLeft;
6
+ exports.isRight = isRight;
7
+ /**
8
+ * Constructs an `Either` holding a `Left<E>` value, usually representing a failure.
9
+ */
10
+ function left(left) {
11
+ return { isRight: false, left };
12
+ }
13
+ /**
14
+ * Constructs an `Either` holding a `Right<A>` value, usually representing a success.
15
+ */
16
+ function right(right) {
17
+ return { isRight: true, right };
18
+ }
19
+ /**
20
+ * Returns `true` if the either is `Left<E>`, `false` otherwise.
21
+ */
22
+ function isLeft(either) {
23
+ return !either.isRight;
24
+ }
25
+ /**
26
+ * Returns `true` if the either is `Right<A>`, `false` otherwise.
27
+ */
28
+ function isRight(either) {
29
+ return either.isRight;
30
+ }
31
+ //# sourceMappingURL=either.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"either.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/either.ts"],"names":[],"mappings":";;AAqBA,oBAEC;AAKD,sBAEC;AAKD,wBAEC;AAKD,0BAEC;AA1BD;;GAEG;AACH,SAAgB,IAAI,CAAe,IAAO;IACxC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,SAAgB,KAAK,CAAe,KAAQ;IAC1C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,SAAgB,MAAM,CAAO,MAAoB;IAC/C,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,SAAgB,OAAO,CAAO,MAAoB;IAChD,OAAO,MAAM,CAAC,OAAO,CAAC;AACxB,CAAC"}
@@ -0,0 +1,28 @@
1
+ export interface None {
2
+ isSome: false;
3
+ }
4
+ export interface Some<A> {
5
+ isSome: true;
6
+ value: A;
7
+ }
8
+ /**
9
+ * An optional value. If the value exists, it's of type `Some<A>`, otherwise it's of type `None`.
10
+ */
11
+ export type Option<A> = None | Some<A>;
12
+ /**
13
+ * Constructs an `Option` of `None`, representing a missing value.
14
+ */
15
+ export declare const none: None;
16
+ /**
17
+ * Constructs an `Option` holding a `Some<A>`, representing an optional value that exists.
18
+ */
19
+ export declare function some<A>(value: A): Some<A>;
20
+ /**
21
+ * Returns `true` if the option is `None`, `false` otherwise.
22
+ */
23
+ export declare function isNone<A>(option: Option<A>): option is None;
24
+ /**
25
+ * Returns `true` if the option is `Some<A>`, `false` otherwise.
26
+ */
27
+ export declare function isSome<A>(option: Option<A>): option is Some<A>;
28
+ //# sourceMappingURL=option.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option.d.ts","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/option.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,KAAK,CAAC;CACf;AAED,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AAEvC;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,IAAwB,CAAC;AAE5C;;GAEG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAEzC;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,CAE3D;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,CAE9D"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.none = void 0;
4
+ exports.some = some;
5
+ exports.isNone = isNone;
6
+ exports.isSome = isSome;
7
+ /**
8
+ * Constructs an `Option` of `None`, representing a missing value.
9
+ */
10
+ exports.none = { isSome: false };
11
+ /**
12
+ * Constructs an `Option` holding a `Some<A>`, representing an optional value that exists.
13
+ */
14
+ function some(value) {
15
+ return { isSome: true, value };
16
+ }
17
+ /**
18
+ * Returns `true` if the option is `None`, `false` otherwise.
19
+ */
20
+ function isNone(option) {
21
+ return !option.isSome;
22
+ }
23
+ /**
24
+ * Returns `true` if the option is `Some<A>`, `false` otherwise.
25
+ */
26
+ function isSome(option) {
27
+ return option.isSome;
28
+ }
29
+ //# sourceMappingURL=option.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/option.ts"],"names":[],"mappings":";;;AAsBA,oBAEC;AAKD,wBAEC;AAKD,wBAEC;AAxBD;;GAEG;AACU,QAAA,IAAI,GAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AAE5C;;GAEG;AACH,SAAgB,IAAI,CAAI,KAAQ;IAC9B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,SAAgB,MAAM,CAAI,MAAiB;IACzC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,SAAgB,MAAM,CAAI,MAAiB;IACzC,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC"}