@chubbyts/chubbyts-throwable-to-error 1.0.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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2022 Dominik Zogg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is furnished
8
+ to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # chubbyts-throwable-to-error
2
+
3
+ [![CI](https://github.com/chubbyts/chubbyts-throwable-to-error/workflows/CI/badge.svg?branch=master)](https://github.com/chubbyts/chubbyts-throwable-to-error/actions?query=workflow%3ACI)
4
+ [![Coverage Status](https://coveralls.io/repos/github/chubbyts/chubbyts-throwable-to-error/badge.svg?branch=master)](https://coveralls.io/github/chubbyts/chubbyts-throwable-to-error?branch=master)
5
+ [![Infection MSI](https://badge.stryker-mutator.io/github.com/chubbyts/chubbyts-throwable-to-error/master)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyts/chubbyts-throwable-to-error/master)
6
+ [![npm-version](https://img.shields.io/npm/v/@chubbyts/chubbyts-throwable-to-error.svg)](https://www.npmjs.com/package/@chubbyts/chubbyts-throwable-to-error)
7
+
8
+ [![bugs](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=bugs)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
9
+ [![code_smells](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=code_smells)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
10
+ [![coverage](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=coverage)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
11
+ [![duplicated_lines_density](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
12
+ [![ncloc](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=ncloc)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
13
+ [![sqale_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
14
+ [![alert_status](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=alert_status)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
15
+ [![reliability_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
16
+ [![security_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=security_rating)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
17
+ [![sqale_index](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=sqale_index)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
18
+ [![vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=chubbyts_chubbyts-throwable-to-error&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=chubbyts_chubbyts-throwable-to-error)
19
+
20
+ ## Description
21
+
22
+ It converts any throwable into an Error.
23
+
24
+ ## Requirements
25
+
26
+ * node: 14
27
+
28
+ ## Installation
29
+
30
+ Through [NPM](https://www.npmjs.com) as [@chubbyts/chubbyts-throwable-to-error][1].
31
+
32
+ ```ts
33
+ npm i @chubbyts/chubbyts-throwable-to-error@^1.0.0
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ```ts
39
+ try {
40
+ throw {key: 'value'};
41
+ } catch (e) {
42
+ const error = throwableToError(e);
43
+ }
44
+ ```
45
+
46
+ ## Copyright
47
+
48
+ Dominik Zogg 2022
49
+
50
+ [1]: https://www.npmjs.com/package/@chubbyts/chubbyts-throwable-to-error
@@ -0,0 +1 @@
1
+ export declare const throwableToError: (e: unknown) => Error;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwableToError = void 0;
4
+ const throwableToError = (e) => {
5
+ if (e instanceof Error) {
6
+ return e;
7
+ }
8
+ const error = new Error(typeof e === 'object' ? `${JSON.stringify(e)}` : `${String(e)}`);
9
+ error.name = typeof e;
10
+ error.stack = undefined;
11
+ return error;
12
+ };
13
+ exports.throwableToError = throwableToError;
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@chubbyts/chubbyts-throwable-to-error",
3
+ "version": "1.0.0",
4
+ "description": "It converts any throwable into an Error.",
5
+ "keywords": [
6
+ "chubbyts",
7
+ "throwable",
8
+ "error"
9
+ ],
10
+ "author": "Dominik Zogg",
11
+ "license": "MIT",
12
+ "repository": "chubbyts/chubbyts-throwable-to-error",
13
+ "scripts": {
14
+ "cs-fix": "prettier --write src tests",
15
+ "cs": "prettier --check src tests",
16
+ "test": "jest",
17
+ "infection": "stryker run",
18
+ "build": "tsc",
19
+ "prepare": "rm -Rf dist && npm run build && npm run cs && npm run test"
20
+ },
21
+ "jest": {
22
+ "preset": "ts-jest",
23
+ "testEnvironment": "node",
24
+ "collectCoverageFrom": [
25
+ "src/**/*.ts"
26
+ ],
27
+ "coverageThreshold": {
28
+ "global": {
29
+ "lines": 100
30
+ }
31
+ }
32
+ },
33
+ "prettier": {
34
+ "printWidth": 120,
35
+ "tabWidth": 2,
36
+ "singleQuote": true,
37
+ "trailingComma": "all"
38
+ },
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "engines": {
43
+ "node": ">=14"
44
+ },
45
+ "dependencies": {},
46
+ "devDependencies": {
47
+ "@stryker-mutator/core": "^6.0.2",
48
+ "@stryker-mutator/jest-runner": "^6.0.2",
49
+ "@types/jest": "^27.5.1",
50
+ "@types/node": "^14",
51
+ "jest": "^28.1.0",
52
+ "prettier": "^2.6.2",
53
+ "ts-jest": "^28.0.3",
54
+ "typescript": "^4.7.2"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ }
59
+ }