@clipboard-health/util-ts 2.12.0 → 2.12.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 +12 -3
- package/src/lib/errors/cbhError.d.ts +1 -2
- package/src/lib/errors/cbhError.js +2 -2
- package/src/lib/errors/cbhError.js.map +1 -1
- package/src/lib/errors/serviceError.d.ts +1 -1
- package/src/lib/functional/either.d.ts +4 -4
- package/src/lib/functional/either.js +3 -3
- package/src/lib/functional/pipe.d.ts +0 -26
- package/src/lib/functional/pipe.js +26 -0
- package/src/lib/functional/pipe.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipboard-health/util-ts",
|
|
3
3
|
"description": "TypeScript utilities.",
|
|
4
|
-
"version": "2.12.
|
|
4
|
+
"version": "2.12.1",
|
|
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.
|
|
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
|
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"directory": "packages/util-ts",
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/ClipboardHealth/core-utils.git"
|
|
26
|
+
},
|
|
18
27
|
"scripts": {
|
|
19
28
|
"embed": "embedme README.md"
|
|
20
29
|
},
|
|
@@ -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
|
-
|
|
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;;A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
|
|
@@ -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
|
|
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
|
|
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
|
|
102
|
-
* @returns The contained value if `Right`, `
|
|
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
|
|
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
|
|
82
|
-
* @returns The contained value if `Right`, `
|
|
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;
|
|
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"}
|