@clipboard-health/util-ts 2.2.7 → 2.2.8
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 +5 -3
- package/src/{index.ts → index.d.ts} +1 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +19 -0
- package/src/index.js.map +1 -0
- package/src/lib/{attributes.ts → attributes.d.ts} +1 -1
- package/src/lib/attributes.d.ts.map +1 -0
- package/src/lib/attributes.js +3 -0
- package/src/lib/attributes.js.map +1 -0
- package/src/lib/cbh-error.d.ts +15 -0
- package/src/lib/cbh-error.d.ts.map +1 -0
- package/src/lib/cbh-error.js +19 -0
- package/src/lib/cbh-error.js.map +1 -0
- package/src/lib/cbh-response.d.ts +18 -0
- package/src/lib/cbh-response.d.ts.map +1 -0
- package/src/lib/cbh-response.js +12 -0
- package/src/lib/cbh-response.js.map +1 -0
- package/src/lib/{defined-utils.ts → defined-utils.d.ts} +4 -9
- package/src/lib/defined-utils.d.ts.map +1 -0
- package/src/lib/defined-utils.js +21 -0
- package/src/lib/defined-utils.js.map +1 -0
- package/src/lib/delay.d.ts +2 -0
- package/src/lib/delay.d.ts.map +1 -0
- package/src/lib/delay.js +9 -0
- package/src/lib/delay.js.map +1 -0
- package/src/lib/{either.ts → either.d.ts} +9 -22
- package/src/lib/either.d.ts.map +1 -0
- package/src/lib/either.js +31 -0
- package/src/lib/either.js.map +1 -0
- package/src/lib/force-cast.d.ts +3 -0
- package/src/lib/force-cast.d.ts.map +1 -0
- package/src/lib/force-cast.js +8 -0
- package/src/lib/force-cast.js.map +1 -0
- package/src/lib/head.d.ts +3 -0
- package/src/lib/head.d.ts.map +1 -0
- package/src/lib/head.js +7 -0
- package/src/lib/head.js.map +1 -0
- package/src/lib/{identity.ts → identity.d.ts} +2 -3
- package/src/lib/identity.d.ts.map +1 -0
- package/src/lib/identity.js +17 -0
- package/src/lib/identity.js.map +1 -0
- package/src/lib/is-string.d.ts +2 -0
- package/src/lib/is-string.d.ts.map +1 -0
- package/src/lib/is-string.js +7 -0
- package/src/lib/is-string.js.map +1 -0
- package/src/lib/non-empty-array.d.ts +4 -0
- package/src/lib/non-empty-array.d.ts.map +1 -0
- package/src/lib/non-empty-array.js +7 -0
- package/src/lib/non-empty-array.js.map +1 -0
- package/src/lib/{null-to-undefined.ts → null-to-undefined.d.ts} +2 -4
- package/src/lib/null-to-undefined.d.ts.map +1 -0
- package/src/lib/null-to-undefined.js +17 -0
- package/src/lib/null-to-undefined.js.map +1 -0
- package/src/lib/{option.ts → option.d.ts} +8 -19
- package/src/lib/option.d.ts.map +1 -0
- package/src/lib/option.js +29 -0
- package/src/lib/option.js.map +1 -0
- package/src/lib/stringify.d.ts +2 -0
- package/src/lib/stringify.d.ts.map +1 -0
- package/src/lib/stringify.js +7 -0
- package/src/lib/stringify.js.map +1 -0
- package/src/lib/to-error.d.ts +4 -0
- package/src/lib/to-error.d.ts.map +1 -0
- package/src/lib/to-error.js +24 -0
- package/src/lib/to-error.js.map +1 -0
- package/.eslintrc.json +0 -12
- package/jest.config.ts +0 -18
- package/project.json +0 -33
- package/src/lib/cbh-error.spec.ts +0 -30
- package/src/lib/cbh-error.ts +0 -26
- package/src/lib/cbh-response.spec.ts +0 -25
- package/src/lib/cbh-response.ts +0 -15
- package/src/lib/defined-utils.spec.ts +0 -35
- package/src/lib/delay.spec.ts +0 -11
- package/src/lib/delay.ts +0 -5
- package/src/lib/either.spec.ts +0 -23
- package/src/lib/force-cast.spec.ts +0 -8
- package/src/lib/force-cast.ts +0 -4
- package/src/lib/head.spec.ts +0 -21
- package/src/lib/head.ts +0 -5
- package/src/lib/identity.spec.ts +0 -17
- package/src/lib/is-string.spec.ts +0 -11
- package/src/lib/is-string.ts +0 -3
- package/src/lib/non-empty-array.ts +0 -7
- package/src/lib/null-to-undefined.spec.ts +0 -33
- package/src/lib/option.spec.ts +0 -24
- package/src/lib/stringify.spec.ts +0 -11
- package/src/lib/stringify.ts +0 -5
- package/src/lib/to-error.spec.ts +0 -28
- package/src/lib/to-error.ts +0 -20
- package/tsconfig.json +0 -19
- package/tsconfig.lib.json +0 -8
- package/tsconfig.lint.json +0 -7
- package/tsconfig.spec.json +0 -13
- package/typedoc.json +0 -4
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isError = isError;
|
|
4
|
+
exports.toError = toError;
|
|
5
|
+
exports.toErrorMessage = toErrorMessage;
|
|
6
|
+
const is_string_1 = require("./is-string");
|
|
7
|
+
const stringify_1 = require("./stringify");
|
|
8
|
+
function isError(error) {
|
|
9
|
+
return error instanceof Error;
|
|
10
|
+
}
|
|
11
|
+
function toError(error) {
|
|
12
|
+
if (isError(error))
|
|
13
|
+
return error;
|
|
14
|
+
try {
|
|
15
|
+
return new Error((0, is_string_1.isString)(error) ? error : (0, stringify_1.stringify)(error));
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return new Error(String(error));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function toErrorMessage(error) {
|
|
22
|
+
return toError(error).message;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=to-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-error.js","sourceRoot":"","sources":["../../../../../packages/util-ts/src/lib/to-error.ts"],"names":[],"mappings":";;AAGA,0BAEC;AAED,0BAQC;AAED,wCAEC;AAnBD,2CAAuC;AACvC,2CAAwC;AAExC,SAAgB,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,KAAK,CAAC;AAChC,CAAC;AAED,SAAgB,OAAO,CAAC,KAAc;IACpC,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAEjC,IAAI,CAAC;QACH,OAAO,IAAI,KAAK,CAAC,IAAA,oBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,qBAAS,EAAC,KAAK,CAAC,CAAC,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AAED,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAChC,CAAC"}
|
package/.eslintrc.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": ["../../.eslintrc.json"],
|
|
3
|
-
"ignorePatterns": ["!**/*"],
|
|
4
|
-
"parserOptions": {
|
|
5
|
-
"project": "tsconfig.lint.json",
|
|
6
|
-
"tsconfigRootDir": "packages/util-ts"
|
|
7
|
-
},
|
|
8
|
-
"rules": {
|
|
9
|
-
// Block node dependencies so this library is usable in the browser.
|
|
10
|
-
"no-restricted-imports": ["error", { "patterns": ["node:*"] }]
|
|
11
|
-
}
|
|
12
|
-
}
|
package/jest.config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
coveragePathIgnorePatterns: [],
|
|
3
|
-
coverageThreshold: {
|
|
4
|
-
global: {
|
|
5
|
-
branches: 100,
|
|
6
|
-
functions: 100,
|
|
7
|
-
lines: 100,
|
|
8
|
-
statements: 100,
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
displayName: "util-ts",
|
|
12
|
-
moduleFileExtensions: ["ts", "js"],
|
|
13
|
-
preset: "../../jest.preset.js",
|
|
14
|
-
setupFiles: ["../../jest.setup.js"],
|
|
15
|
-
transform: {
|
|
16
|
-
"^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }],
|
|
17
|
-
},
|
|
18
|
-
};
|
package/project.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "util-ts",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"projectType": "library",
|
|
5
|
-
"sourceRoot": "packages/util-ts/src",
|
|
6
|
-
"tags": ["scope:no-external-imports"],
|
|
7
|
-
"targets": {
|
|
8
|
-
"build": {
|
|
9
|
-
"executor": "@nx/js:tsc",
|
|
10
|
-
"options": {
|
|
11
|
-
"assets": ["packages/util-ts/*.md"],
|
|
12
|
-
"main": "packages/util-ts/src/index.js",
|
|
13
|
-
"outputPath": "dist/packages/util-ts",
|
|
14
|
-
"tsConfig": "packages/util-ts/tsconfig.lib.json"
|
|
15
|
-
},
|
|
16
|
-
"outputs": ["{options.outputPath}"]
|
|
17
|
-
},
|
|
18
|
-
"lint": {
|
|
19
|
-
"executor": "@nx/eslint:lint",
|
|
20
|
-
"options": {
|
|
21
|
-
"maxWarnings": 0
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"test": {
|
|
25
|
-
"executor": "@nx/jest:jest",
|
|
26
|
-
"options": {
|
|
27
|
-
"jestConfig": "packages/util-ts/jest.config.ts",
|
|
28
|
-
"passWithNoTests": false
|
|
29
|
-
},
|
|
30
|
-
"outputs": ["{projectRoot}/coverage"]
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { CbhError } from "./cbh-error";
|
|
2
|
-
|
|
3
|
-
describe("CbhError", () => {
|
|
4
|
-
it("returns proper defaults", () => {
|
|
5
|
-
const message = "boom";
|
|
6
|
-
const statusCode = 500;
|
|
7
|
-
|
|
8
|
-
const error = new CbhError({ message, statusCode });
|
|
9
|
-
|
|
10
|
-
expect(error.name).toBe("CbhError");
|
|
11
|
-
expect(error.message).toBe(message);
|
|
12
|
-
expect(error.issues[0]?.statusCode).toBe(statusCode);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("sets the cause", () => {
|
|
16
|
-
const cause = new Error("cause");
|
|
17
|
-
|
|
18
|
-
const error = new CbhError({ message: "boom", cause });
|
|
19
|
-
|
|
20
|
-
expect(error.cause).toBe(cause);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("accpets an array", () => {
|
|
24
|
-
const message = "boom";
|
|
25
|
-
|
|
26
|
-
const error = new CbhError([{ message }]);
|
|
27
|
-
|
|
28
|
-
expect(error.message).toBe(message);
|
|
29
|
-
});
|
|
30
|
-
});
|
package/src/lib/cbh-error.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type OneOrNonEmptyArray, toNonEmptyArray } from "./non-empty-array";
|
|
2
|
-
|
|
3
|
-
const ERROR_STATUS_CODES = [400, 401, 403, 404, 409, 422, 429, 500] as const;
|
|
4
|
-
export type ErrorStatusCode = (typeof ERROR_STATUS_CODES)[number];
|
|
5
|
-
|
|
6
|
-
export interface CbhIssue {
|
|
7
|
-
cause?: Error;
|
|
8
|
-
id?: string;
|
|
9
|
-
message: string;
|
|
10
|
-
statusCode?: ErrorStatusCode;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class CbhError extends Error {
|
|
14
|
-
public readonly issues: CbhIssue[];
|
|
15
|
-
|
|
16
|
-
constructor(issues: OneOrNonEmptyArray<CbhIssue>) {
|
|
17
|
-
const is = toNonEmptyArray(issues);
|
|
18
|
-
const first = is[0];
|
|
19
|
-
super(first?.message, { cause: first?.cause });
|
|
20
|
-
// See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#example
|
|
21
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
22
|
-
|
|
23
|
-
this.issues = is;
|
|
24
|
-
this.name = "CbhError";
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { CbhError } from "./cbh-error";
|
|
2
|
-
import { toErrorCbhResponse, toSuccessCbhResponse } from "./cbh-response";
|
|
3
|
-
|
|
4
|
-
describe("toErrorCbhResponse", () => {
|
|
5
|
-
it("returns error", () => {
|
|
6
|
-
const message = "boom";
|
|
7
|
-
|
|
8
|
-
const response = toErrorCbhResponse({ message });
|
|
9
|
-
|
|
10
|
-
expect(response).toEqual({
|
|
11
|
-
success: false,
|
|
12
|
-
error: new CbhError({ message }),
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe("toSuccessCbhResponse", () => {
|
|
18
|
-
it("returns success", () => {
|
|
19
|
-
const message = "success";
|
|
20
|
-
|
|
21
|
-
const response = toSuccessCbhResponse({ message });
|
|
22
|
-
|
|
23
|
-
expect(response).toEqual({ success: true, data: { message } });
|
|
24
|
-
});
|
|
25
|
-
});
|
package/src/lib/cbh-response.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CbhError, type CbhIssue } from "./cbh-error";
|
|
2
|
-
import type { OneOrNonEmptyArray } from "./non-empty-array";
|
|
3
|
-
|
|
4
|
-
export type CbhResponse<T> = { success: true; data: T } | { success: false; error: CbhError };
|
|
5
|
-
|
|
6
|
-
export function toErrorCbhResponse(issues: OneOrNonEmptyArray<CbhIssue>): {
|
|
7
|
-
success: false;
|
|
8
|
-
error: CbhError;
|
|
9
|
-
} {
|
|
10
|
-
return { success: false, error: new CbhError(issues) };
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function toSuccessCbhResponse<T>(data: T): { success: true; data: T } {
|
|
14
|
-
return { success: true, data };
|
|
15
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { isDefined, isNullOrUndefined } from "./defined-utils";
|
|
2
|
-
|
|
3
|
-
const DEFINED_TEST_CASES = ["gandalf", " ", "", 42, 0, -0];
|
|
4
|
-
|
|
5
|
-
describe("isNullOrUndefined", () => {
|
|
6
|
-
it.each(DEFINED_TEST_CASES)("returns false for (%s)", (value) => {
|
|
7
|
-
expect(isNullOrUndefined(value)).toBe(false);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("returns true if null", () => {
|
|
11
|
-
// eslint-disable-next-line unicorn/no-null
|
|
12
|
-
expect(isNullOrUndefined(null)).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("returns true if undefined", () => {
|
|
16
|
-
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
17
|
-
expect(isNullOrUndefined(undefined)).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("isDefined", () => {
|
|
22
|
-
it.each(DEFINED_TEST_CASES)("returns true for (%s)", (value) => {
|
|
23
|
-
expect(isDefined(value)).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("returns false if undefined", () => {
|
|
27
|
-
// eslint-disable-next-line unicorn/no-null
|
|
28
|
-
expect(isDefined(null)).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("returns false if null", () => {
|
|
32
|
-
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
33
|
-
expect(isDefined(undefined)).toBe(false);
|
|
34
|
-
});
|
|
35
|
-
});
|
package/src/lib/delay.spec.ts
DELETED
package/src/lib/delay.ts
DELETED
package/src/lib/either.spec.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as E from "./either";
|
|
2
|
-
|
|
3
|
-
describe("Either", () => {
|
|
4
|
-
it("left works", () => {
|
|
5
|
-
const error = new Error("boom");
|
|
6
|
-
const either = E.left(error) as E.Left<Error>;
|
|
7
|
-
|
|
8
|
-
expect(E.isLeft(either)).toBe(true);
|
|
9
|
-
expect(E.isRight(either)).toBe(false);
|
|
10
|
-
expect(either.isRight).toBe(false);
|
|
11
|
-
expect(either.left).toBe(error);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("right works", () => {
|
|
15
|
-
const value = "my-value";
|
|
16
|
-
const either = E.right(value) as E.Right<string>;
|
|
17
|
-
|
|
18
|
-
expect(E.isRight(either)).toBe(true);
|
|
19
|
-
expect(E.isLeft(either)).toBe(false);
|
|
20
|
-
expect(either.isRight).toBe(true);
|
|
21
|
-
expect(either.right).toBe(value);
|
|
22
|
-
});
|
|
23
|
-
});
|
package/src/lib/force-cast.ts
DELETED
package/src/lib/head.spec.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { head } from "./head";
|
|
2
|
-
|
|
3
|
-
describe("head", () => {
|
|
4
|
-
it("returns head of list", () => {
|
|
5
|
-
expect(head([1, 2])).toBe(1);
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
it("returns undefined if empty list", () => {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
10
|
-
expect(head([])).toBeUndefined();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("returns undefined if passed", () => {
|
|
14
|
-
expect(head()).toBeUndefined();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("returns value if not an array", () => {
|
|
18
|
-
const value = { hi: "there" };
|
|
19
|
-
expect(head(value)).toEqual(value);
|
|
20
|
-
});
|
|
21
|
-
});
|
package/src/lib/head.ts
DELETED
package/src/lib/identity.spec.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { identity } from "./identity";
|
|
2
|
-
|
|
3
|
-
describe("identity", () => {
|
|
4
|
-
it("returns the provided input", () => {
|
|
5
|
-
expect(identity(1)).toBe(1);
|
|
6
|
-
expect(identity("text")).toBe("text");
|
|
7
|
-
expect(identity({})).toStrictEqual({});
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it("should correctly infer the type", () => {
|
|
11
|
-
const a = 1;
|
|
12
|
-
expect(typeof a).toBe("number");
|
|
13
|
-
|
|
14
|
-
const b = identity(a);
|
|
15
|
-
expect(typeof b).toBe("number");
|
|
16
|
-
});
|
|
17
|
-
});
|
package/src/lib/is-string.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { nullToUndefined } from "./null-to-undefined";
|
|
2
|
-
|
|
3
|
-
describe("nullToUndefined", () => {
|
|
4
|
-
it("returns undefined", async () => {
|
|
5
|
-
// eslint-disable-next-line unicorn/no-null
|
|
6
|
-
expect(await nullToUndefined(Promise.resolve(null))).toBeUndefined();
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
it("returns value", async () => {
|
|
10
|
-
const expected = "hi";
|
|
11
|
-
|
|
12
|
-
expect(await nullToUndefined(Promise.resolve(expected))).toBe(expected);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("supports PromiseLike objects", async () => {
|
|
16
|
-
const expected = "hello";
|
|
17
|
-
|
|
18
|
-
const promiseLike: PromiseLike<string> = {
|
|
19
|
-
// eslint-disable-next-line unicorn/no-thenable
|
|
20
|
-
then: function <TResult1, TResult2>(
|
|
21
|
-
onfulfilled?: ((value: string) => TResult1 | PromiseLike<TResult1>) | undefined,
|
|
22
|
-
): PromiseLike<TResult1 | TResult2> {
|
|
23
|
-
if (onfulfilled) {
|
|
24
|
-
return Promise.resolve(onfulfilled(expected));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return Promise.reject();
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
expect(await nullToUndefined(promiseLike)).toBe(expected);
|
|
32
|
-
});
|
|
33
|
-
});
|
package/src/lib/option.spec.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as O from "./option";
|
|
2
|
-
|
|
3
|
-
const { none, some } = O;
|
|
4
|
-
|
|
5
|
-
describe("Option", () => {
|
|
6
|
-
it("none is not some", () => {
|
|
7
|
-
const option = none;
|
|
8
|
-
|
|
9
|
-
expect(O.isNone(option)).toBe(true);
|
|
10
|
-
expect(O.isSome(option)).toBe(false);
|
|
11
|
-
expect(option.isSome).toBe(false);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it("some is some", () => {
|
|
15
|
-
const value = "my-value";
|
|
16
|
-
|
|
17
|
-
const option = some(value);
|
|
18
|
-
|
|
19
|
-
expect(O.isNone(option)).toBe(false);
|
|
20
|
-
expect(O.isSome(option)).toBe(true);
|
|
21
|
-
expect(option.isSome).toBe(true);
|
|
22
|
-
expect(option.value).toBe(value);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { stringify } from "./stringify";
|
|
2
|
-
|
|
3
|
-
describe("stringify", () => {
|
|
4
|
-
test.each([
|
|
5
|
-
[1n, '"1"'],
|
|
6
|
-
[{ a: 1 }, '{"a":1}'],
|
|
7
|
-
[{ a: 1n }, '{"a":"1"}'],
|
|
8
|
-
])("stringify(%i, %i)", (value, expected) => {
|
|
9
|
-
expect(stringify(value)).toBe(expected);
|
|
10
|
-
});
|
|
11
|
-
});
|
package/src/lib/stringify.ts
DELETED
package/src/lib/to-error.spec.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { stringify } from "./stringify";
|
|
2
|
-
import { toErrorMessage } from "./to-error";
|
|
3
|
-
|
|
4
|
-
const MESSAGE = "hi";
|
|
5
|
-
|
|
6
|
-
describe("toErrorMessage", () => {
|
|
7
|
-
it("returns message", () => {
|
|
8
|
-
expect(toErrorMessage(new Error(MESSAGE))).toEqual(MESSAGE);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it("returns message if non-error object", () => {
|
|
12
|
-
const error = { hello: MESSAGE };
|
|
13
|
-
|
|
14
|
-
expect(toErrorMessage(error)).toEqual(stringify(error));
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("returns message if unable to stringify", () => {
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
const circularReference = { a: { b: "c" }, d: {} } as any;
|
|
20
|
-
circularReference.a.d = circularReference.a;
|
|
21
|
-
|
|
22
|
-
expect(toErrorMessage(circularReference)).toBe("[object Object]");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("returns message if string", () => {
|
|
26
|
-
expect(toErrorMessage(MESSAGE)).toEqual(MESSAGE);
|
|
27
|
-
});
|
|
28
|
-
});
|
package/src/lib/to-error.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { isString } from "./is-string";
|
|
2
|
-
import { stringify } from "./stringify";
|
|
3
|
-
|
|
4
|
-
export function isError(error: unknown): error is Error {
|
|
5
|
-
return error instanceof Error;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function toError(error: unknown): Error {
|
|
9
|
-
if (isError(error)) return error;
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
return new Error(isString(error) ? error : stringify(error));
|
|
13
|
-
} catch {
|
|
14
|
-
return new Error(String(error));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function toErrorMessage(error: unknown): string {
|
|
19
|
-
return toError(error).message;
|
|
20
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/out-tsc"
|
|
5
|
-
},
|
|
6
|
-
"files": [],
|
|
7
|
-
"include": [],
|
|
8
|
-
"references": [
|
|
9
|
-
{
|
|
10
|
-
"path": "./tsconfig.lib.json"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"path": "./tsconfig.lint.json"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"path": "./tsconfig.spec.json"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|
package/tsconfig.lib.json
DELETED
package/tsconfig.lint.json
DELETED
package/tsconfig.spec.json
DELETED
package/typedoc.json
DELETED