@clipboard-health/util-ts 2.12.0 → 2.13.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/README.md CHANGED
@@ -28,8 +28,7 @@ See `./src/lib` for each utility.
28
28
 
29
29
  <!-- prettier-ignore -->
30
30
  ```ts
31
- // ./examples/serviceError.ts
32
-
31
+ // packages/util-ts/examples/serviceError.ts
33
32
  import { deepEqual, equal } from "node:assert/strict";
34
33
 
35
34
  import { ERROR_CODES, ServiceError } from "@clipboard-health/util-ts";
@@ -116,8 +115,7 @@ try {
116
115
 
117
116
  <!-- prettier-ignore -->
118
117
  ```ts
119
- // ./examples/serviceResult.ts
120
-
118
+ // packages/util-ts/examples/serviceResult.ts
121
119
  import { ok } from "node:assert/strict";
122
120
 
123
121
  import {
@@ -154,9 +152,7 @@ ok(E.isRight(validateUser({ email: "user@example.com", phone: "555-555-5555" }))
154
152
 
155
153
  <!-- prettier-ignore -->
156
154
  ```ts
157
- // ./examples/pipe.ts
158
-
159
- // packages/util-ts/src/lib/functional/pipe.ts
155
+ // packages/util-ts/examples/pipe.ts
160
156
  import { equal } from "node:assert/strict";
161
157
 
162
158
  import { pipe } from "@clipboard-health/util-ts";
@@ -177,9 +173,7 @@ equal(result, "Hello World");
177
173
 
178
174
  <!-- prettier-ignore -->
179
175
  ```ts
180
- // ./examples/option.ts
181
-
182
- // packages/util-ts/src/lib/functional/option.ts
176
+ // packages/util-ts/examples/option.ts
183
177
  import { equal } from "node:assert/strict";
184
178
 
185
179
  import { option as O, pipe } from "@clipboard-health/util-ts";
@@ -210,9 +204,7 @@ equal(result, "Result is 0.1");
210
204
 
211
205
  <!-- prettier-ignore -->
212
206
  ```ts
213
- // ./examples/either.ts
214
-
215
- // packages/util-ts/src/lib/functional/either.ts
207
+ // packages/util-ts/examples/either.ts
216
208
  import { equal } from "node:assert/strict";
217
209
 
218
210
  import { either as E, pipe } from "@clipboard-health/util-ts";
package/package.json CHANGED
@@ -1,22 +1,28 @@
1
1
  {
2
2
  "name": "@clipboard-health/util-ts",
3
3
  "description": "TypeScript utilities.",
4
- "version": "2.12.0",
4
+ "version": "2.13.0",
5
+ "bugs": "https://github.com/ClipboardHealth/core-utils/issues",
5
6
  "dependencies": {
6
7
  "tslib": "2.8.0"
7
8
  },
8
9
  "devDependencies": {
9
- "type-fest": "4.26.1",
10
+ "type-fest": "4.27.0",
10
11
  "zod": "3.23.8"
11
12
  },
12
- "keywords": [],
13
+ "keywords": [
14
+ "typescript",
15
+ "utility"
16
+ ],
13
17
  "license": "MIT",
14
18
  "main": "./src/index.js",
15
19
  "publishConfig": {
16
20
  "access": "public"
17
21
  },
18
- "scripts": {
19
- "embed": "embedme README.md"
22
+ "repository": {
23
+ "directory": "packages/util-ts",
24
+ "type": "git",
25
+ "url": "git+https://github.com/ClipboardHealth/core-utils.git"
20
26
  },
21
27
  "type": "commonjs",
22
28
  "typings": "./src/index.d.ts",
@@ -5,7 +5,7 @@ import * as E from "../functional/either";
5
5
  *
6
6
  * @see {@link https://www.notion.so/BP-REST-API-f769b7fe745c4cf38f6eca2e9ad8a843?pvs=4#e0b4e9ea30f041409ce39505650098ea}
7
7
  */
8
- declare const ERROR_STATUS_CODES: readonly [400, 401, 403, 404, 409, 422, 429, 500];
8
+ export declare const ERROR_STATUS_CODES: readonly [400, 401, 403, 404, 409, 422, 429, 500];
9
9
  /**
10
10
  * @deprecated Use {@link ErrorCode} instead.
11
11
  */
@@ -30,4 +30,3 @@ export declare class CbhError extends Error {
30
30
  * @deprecated Use {@link failure} instead.
31
31
  */
32
32
  export declare function toLeft<A = never>(issues: Arrayable<CbhIssue> | string): E.Either<CbhError, A>;
33
- export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CbhError = void 0;
3
+ exports.CbhError = exports.ERROR_STATUS_CODES = void 0;
4
4
  exports.toLeft = toLeft;
5
5
  const tslib_1 = require("tslib");
6
6
  const E = tslib_1.__importStar(require("../functional/either"));
@@ -9,7 +9,7 @@ const E = tslib_1.__importStar(require("../functional/either"));
9
9
  *
10
10
  * @see {@link https://www.notion.so/BP-REST-API-f769b7fe745c4cf38f6eca2e9ad8a843?pvs=4#e0b4e9ea30f041409ce39505650098ea}
11
11
  */
12
- const ERROR_STATUS_CODES = [400, 401, 403, 404, 409, 422, 429, 500];
12
+ exports.ERROR_STATUS_CODES = [400, 401, 403, 404, 409, 422, 429, 500];
13
13
  /**
14
14
  * @deprecated Use {@link ServiceError} instead.
15
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"cbhError.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/errors/cbhError.ts"],"names":[],"mappings":";;;AAqDA,wBAEC;;AArDD,gEAA0C;AAE1C;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAC;AAiB7E;;GAEG;AACH,MAAa,QAAS,SAAQ,KAAK;IACjB,MAAM,CAAsB;IAE5C,YAAY,eAA6C;QACvD,MAAM,EAAE,GACN,OAAO,eAAe,KAAK,QAAQ;YACjC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;YAChC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;gBAC9B,CAAC,CAAC,eAAe;gBACjB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;QAE1B,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;QACpD,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC7E,6FAA6F;QAC7F,MAAM,CAA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,MAAM,CAAC,SAAS,CAAC,CAAC;QAElD,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAnBD,4BAmBC;AAED;;GAEG;AACH,SAAgB,MAAM,CAAY,MAAoC;IACpE,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACtC,CAAC"}
@@ -71,7 +71,7 @@ declare const ERROR_METADATA: {
71
71
  };
72
72
  };
73
73
  type Status = (typeof ERROR_METADATA)[keyof typeof ERROR_METADATA]["status"];
74
- interface Issue extends ServiceIssue {
74
+ export interface Issue extends ServiceIssue {
75
75
  code: Required<ServiceIssue>["code"];
76
76
  title: string;
77
77
  }
@@ -9,7 +9,7 @@ export type Right<A> = Readonly<{
9
9
  /**
10
10
  * A value of `Either` type `Left<E>` or type `Right<A>`; a disjoint union.
11
11
  *
12
- * A common use case is as an alternative to {@link Option} where `Left<E>` contains useful
12
+ * A common use case is as an alternative to `Option` where `Left<E>` contains useful
13
13
  * information. Convention dictates that `Left<E>` is used for failure and `Right<A>` for success.
14
14
  * To help remember, the success case is "right"; it's the result you want.
15
15
  *
@@ -53,7 +53,7 @@ export declare function left<E, A = never>(left: E): Either<E, A>;
53
53
  /**
54
54
  * Constructs an `Either` holding a `Right<A>`, representing a success.
55
55
  *
56
- * @param value - The value to wrap in a `Right`
56
+ * @param right - The value to wrap in a `Right`
57
57
  * @returns A `Right` containing the value
58
58
  */
59
59
  export declare function right<A, E = never>(right: A): Either<E, A>;
@@ -98,8 +98,8 @@ export declare function flatMap<E, A, B>(f: (right: A) => Either<E, B>): (either
98
98
  * Safely extracts the value from an `Either` with a fallback. Use this function when you need to
99
99
  * convert an `Either<E, A>` to an `A`, providing a default value for the `Left` case.
100
100
  *
101
- * @param defaultValue - The value to return if the `Either` is `Left`
102
- * @returns The contained value if `Right`, `defaultValue` if `Left`
101
+ * @param onLeft - The value to return if the `Either` is `Left`
102
+ * @returns The contained value if `Right`, the result of `onLeft` if `Left`
103
103
  */
104
104
  export declare function getOrElse<E, A>(onLeft: (left: E) => A): (either: Either<E, A>) => A;
105
105
  /**
@@ -21,7 +21,7 @@ function left(left) {
21
21
  /**
22
22
  * Constructs an `Either` holding a `Right<A>`, representing a success.
23
23
  *
24
- * @param value - The value to wrap in a `Right`
24
+ * @param right - The value to wrap in a `Right`
25
25
  * @returns A `Right` containing the value
26
26
  */
27
27
  function right(right) {
@@ -78,8 +78,8 @@ function flatMap(f) {
78
78
  * Safely extracts the value from an `Either` with a fallback. Use this function when you need to
79
79
  * convert an `Either<E, A>` to an `A`, providing a default value for the `Left` case.
80
80
  *
81
- * @param defaultValue - The value to return if the `Either` is `Left`
82
- * @returns The contained value if `Right`, `defaultValue` if `Left`
81
+ * @param onLeft - The value to return if the `Either` is `Left`
82
+ * @returns The contained value if `Right`, the result of `onLeft` if `Left`
83
83
  */
84
84
  function getOrElse(onLeft) {
85
85
  return (either) => (isRight(either) ? either.right : onLeft(either.left));
@@ -1,29 +1,3 @@
1
- /**
2
- * Pipes a value through a series of functions from left to right. Currently supports up to 10
3
- * functions.
4
- *
5
- * @param a - The initial value to transform
6
- * @param fs - Functions to apply sequentially
7
- * @returns The final transformed value
8
- * @example
9
- * ```ts
10
- * // packages/util-ts/examples/pipe.ts
11
- * import { equal } from "node:assert/strict";
12
- *
13
- * import { pipe } from "@clipboard-health/util-ts";
14
- *
15
- * const result = pipe(
16
- * " hello world ",
17
- * (s) => s.trim(),
18
- * (s) => s.split(" "),
19
- * (array) => array.map((word) => word.charAt(0).toUpperCase() + word.slice(1)),
20
- * (array) => array.join(" "),
21
- * );
22
- *
23
- * equal(result, "Hello World");
24
- *
25
- * ```
26
- */
27
1
  export declare function pipe<A>(a: A): A;
28
2
  export declare function pipe<A, B>(a: A, ab: (a: A) => B): B;
29
3
  export declare function pipe<A, B, C>(a: A, ab: (a: A) => B, bc: (b: B) => C): C;
@@ -1,6 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pipe = pipe;
4
+ /**
5
+ * Pipes a value through a series of functions from left to right. Currently supports up to 10
6
+ * functions.
7
+ *
8
+ * @param a - The initial value to transform
9
+ * @param fs - Functions to apply sequentially
10
+ * @returns The final transformed value
11
+ * @example
12
+ * ```ts
13
+ * // packages/util-ts/examples/pipe.ts
14
+ * import { equal } from "node:assert/strict";
15
+ *
16
+ * import { pipe } from "@clipboard-health/util-ts";
17
+ *
18
+ * const result = pipe(
19
+ * " hello world ",
20
+ * (s) => s.trim(),
21
+ * (s) => s.split(" "),
22
+ * (array) => array.map((word) => word.charAt(0).toUpperCase() + word.slice(1)),
23
+ * (array) => array.join(" "),
24
+ * );
25
+ *
26
+ * equal(result, "Hello World");
27
+ *
28
+ * ```
29
+ */
4
30
  function pipe(a, ...fs) {
5
31
  return fs.reduce((accumulator, f) => f(accumulator), a);
6
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/functional/pipe.ts"],"names":[],"mappings":";;AAuFA,oBAEC;AAFD,SAAgB,IAAI,CAAC,CAAU,EAAE,GAAG,EAAkC;IACpE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1D,CAAC"}
1
+ {"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../../../../../packages/util-ts/src/lib/functional/pipe.ts"],"names":[],"mappings":";;AAuFA,oBAEC;AA5BD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,IAAI,CAAC,CAAU,EAAE,GAAG,EAAkC;IACpE,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1D,CAAC"}