@alessiofrittoli/exception 0.1.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 ADDED
@@ -0,0 +1,132 @@
1
+ # Exception 🚦
2
+
3
+ Version 0.1.0
4
+
5
+ ## Handle errors with ease
6
+
7
+ ### Table of Contents
8
+
9
+ - [Getting started](#getting-started)
10
+ - [Development](#development)
11
+ - [ESLint](#eslint)
12
+ - [Jest](#jest)
13
+ - [Contributing](#contributing)
14
+ - [Security](#security)
15
+ - [Credits](#made-with-)
16
+
17
+ ---
18
+
19
+ ### Getting started
20
+
21
+ Run the following command to start using `@alessiofrittoli/exception` in your projects:
22
+
23
+ ```bash
24
+ npm i @alessiofrittoli/exception
25
+ ```
26
+
27
+ or using `pnpm`
28
+
29
+ ```bash
30
+ pnpm i @alessiofrittoli/exception
31
+ ```
32
+
33
+ ---
34
+
35
+ ### Development
36
+
37
+ #### Install depenendencies
38
+
39
+ ```bash
40
+ npm install
41
+ ```
42
+
43
+ or using `pnpm`
44
+
45
+ ```bash
46
+ pnpm i
47
+ ```
48
+
49
+ #### Build your source code
50
+
51
+ Run the following command to build code for distribution.
52
+
53
+ ```bash
54
+ pnpm build
55
+ ```
56
+
57
+ #### [ESLint](https://www.npmjs.com/package/eslint)
58
+
59
+ warnings / errors check.
60
+
61
+ ```bash
62
+ pnpm lint
63
+ ```
64
+
65
+ #### [Jest](https://npmjs.com/package/jest)
66
+
67
+ Run all the defined test suites by running the following:
68
+
69
+ ```bash
70
+ # Run tests and watch file changes.
71
+ pnpm test
72
+
73
+ # Run tests and watch file changes with jest-environment-jsdom.
74
+ pnpm test:jsdom
75
+
76
+ # Run tests in a CI environment.
77
+ pnpm test:ci
78
+
79
+ # Run tests in a CI environment with jest-environment-jsdom.
80
+ pnpm test:ci:jsdom
81
+ ```
82
+
83
+ You can eventually run specific suits like so:
84
+
85
+ ```bash
86
+ pnpm test:jest
87
+ pnpm test:jest:jsdom
88
+ ```
89
+
90
+ ---
91
+
92
+ ### Contributing
93
+
94
+ Contributions are truly welcome!\
95
+ Please refer to the [Contributing Doc](./CONTRIBUTING.md) for more information on how to start contributing to this project.
96
+
97
+ ---
98
+
99
+ ### Security
100
+
101
+ If you believe you have found a security vulnerability, we encourage you to **_responsibly disclose this and NOT open a public issue_**. We will investigate all legitimate reports. Email `security@alessiofrittoli.it` to disclose any security vulnerabilities.
102
+
103
+ ### Made with ☕
104
+
105
+ <table style='display:flex;gap:20px;'>
106
+ <tbody>
107
+ <tr>
108
+ <td>
109
+ <img src='https://avatars.githubusercontent.com/u/35973186' style='width:60px;border-radius:50%;object-fit:contain;'>
110
+ </td>
111
+ <td>
112
+ <table style='display:flex;gap:2px;flex-direction:column;'>
113
+ <tbody>
114
+ <tr>
115
+ <td>
116
+ <a href='https://github.com/alessiofrittoli' target='_blank' rel='noopener'>Alessio Frittoli</a>
117
+ </td>
118
+ </tr>
119
+ <tr>
120
+ <td>
121
+ <small>
122
+ <a href='https://alessiofrittoli.it' target='_blank' rel='noopener'>https://alessiofrittoli.it</a> |
123
+ <a href='mailto:info@alessiofrittoli.it' target='_blank' rel='noopener'>info@alessiofrittoli.it</a>
124
+ </small>
125
+ </td>
126
+ </tr>
127
+ </tbody>
128
+ </table>
129
+ </td>
130
+ </tr>
131
+ </tbody>
132
+ </table>
@@ -0,0 +1,14 @@
1
+ interface ExceptionOptions<TCode = number> extends ErrorOptions {
2
+ code: TCode;
3
+ name?: string;
4
+ status?: number;
5
+ }
6
+ declare class Exception<TCode = number> extends Error implements ExceptionOptions<TCode> {
7
+ status: number | undefined;
8
+ name: string;
9
+ code: TCode;
10
+ constructor(message: string, options: ExceptionOptions<TCode>);
11
+ static isException<TCause = number>(error: any): error is Exception<TCause>;
12
+ }
13
+
14
+ export { type ExceptionOptions, Exception as default };
@@ -0,0 +1,14 @@
1
+ interface ExceptionOptions<TCode = number> extends ErrorOptions {
2
+ code: TCode;
3
+ name?: string;
4
+ status?: number;
5
+ }
6
+ declare class Exception<TCode = number> extends Error implements ExceptionOptions<TCode> {
7
+ status: number | undefined;
8
+ name: string;
9
+ code: TCode;
10
+ constructor(message: string, options: ExceptionOptions<TCode>);
11
+ static isException<TCause = number>(error: any): error is Exception<TCause>;
12
+ }
13
+
14
+ export { type ExceptionOptions, Exception as default };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var s=class n extends Error{status;name;code;constructor(e,t){super(e,t),this.name=t.name||"Exception",this.message=e,this.code=t.code,this.status=t.status;}static isException(e){return e instanceof n}},o=s;module.exports=o;
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var s=class n extends Error{status;name;code;constructor(e,t){super(e,t),this.name=t.name||"Exception",this.message=e,this.code=t.code,this.status=t.status;}static isException(e){return e instanceof n}},i=s;export{i as default};
package/license.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Alessio Frittoli.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@alessiofrittoli/exception",
3
+ "version": "0.1.0",
4
+ "description": "Handle errors with ease",
5
+ "author": {
6
+ "name": "Alessio Frittoli",
7
+ "email": "info@alessiofrittoli.it",
8
+ "url": "https://alessiofrittoli.it"
9
+ },
10
+ "license": "MIT",
11
+ "keywords": [
12
+ "exceptions",
13
+ "errors"
14
+ ],
15
+ "homepage": "https://github.com/alessiofrittoli/exception#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/alessiofrittoli/exception/issues",
18
+ "email": "info@alessiofrittoli.it"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/alessiofrittoli/exception.git"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "sideEffects": false,
31
+ "scripts": {
32
+ "build": "eslint && pnpm test:ci && pnpm test:ci:jsdom && tsup",
33
+ "lint": "eslint",
34
+ "test": "jest --watchAll --verbose",
35
+ "test:jsdom": "JSDOM=true pnpm test",
36
+ "test:ci": "jest --ci --verbose",
37
+ "test:ci:jsdom": "JSDOM=true pnpm test:ci",
38
+ "test:jest": "pnpm test jest.test.ts",
39
+ "test:jest:jsdom": "JSDOM=true pnpm test:jest"
40
+ },
41
+ "devDependencies": {
42
+ "@eslint/js": "^9.17.0",
43
+ "@jest/globals": "^29.7.0",
44
+ "@types/jest": "^29.5.14",
45
+ "@types/node": "^22.10.2",
46
+ "dotenv": "^16.4.7",
47
+ "eslint": "^9.17.0",
48
+ "globals": "^15.13.0",
49
+ "jest": "^29.7.0",
50
+ "jest-environment-jsdom": "^29.7.0",
51
+ "ts-jest": "^29.2.5",
52
+ "ts-node": "^10.9.2",
53
+ "tsup": "^8.3.5",
54
+ "typescript": "^5.7.2",
55
+ "typescript-eslint": "^8.18.0"
56
+ }
57
+ }