Add barcode-detector-api-polyfill dependency and update environment variable declarations in SvelteKit project
This commit is contained in:
+149
@@ -0,0 +1,149 @@
|
||||
## [3.3.1](https://github.com/adriengibrat/ts-custom-error/compare/v3.3.0...v3.3.1) (2022-11-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* avoid error Cannot find name 'ErrorOptions' ([7535f79](https://github.com/adriengibrat/ts-custom-error/commit/7535f79f3ad8e0554a1f6062bb62e11e245ea792))
|
||||
|
||||
# [3.3.0](https://github.com/adriengibrat/ts-custom-error/compare/v3.2.2...v3.3.0) (2022-10-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add es2022 typescript lib ([e04a6b1](https://github.com/adriengibrat/ts-custom-error/commit/e04a6b1ef9870b731144670fbde5a83a5b3959c6))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **cause:** add suport for error cause ([683cf2b](https://github.com/adriengibrat/ts-custom-error/commit/683cf2bbc84f773a50dbacfe12477db13cdb6b2b))
|
||||
|
||||
## [3.2.2](https://github.com/adriengibrat/ts-custom-error/compare/v3.2.1...v3.2.2) (2022-08-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* build badge & publish semantic release branch ([b44245c](https://github.com/adriengibrat/ts-custom-error/commit/b44245ccd5fb90eb44a3d99d47080da600d67714))
|
||||
* publish new release ([436918e](https://github.com/adriengibrat/ts-custom-error/commit/436918e1d6d333c15da48ffd45aa22b37e213464))
|
||||
* renamed branch to main & updated all dev deps / CI ([7733299](https://github.com/adriengibrat/ts-custom-error/commit/773329995ac394f42199c3fcef6f5a44ad886881))
|
||||
|
||||
## [3.2.1](https://github.com/adriengibrat/ts-custom-error/compare/v3.2.0...v3.2.1) (2022-08-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update types to support TS 4.8.2 ([80f5eb0](https://github.com/adriengibrat/ts-custom-error/commit/80f5eb08a1786ac397d6b7dd27e586e386dbe1ef))
|
||||
|
||||
# [3.2.0](https://github.com/adriengibrat/ts-custom-error/compare/v3.1.1...v3.2.0) (2020-08-24)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **name:** Allow to redefine error name property ([94efde0](https://github.com/adriengibrat/ts-custom-error/commit/94efde0a70b62eea191bc9ff204b43101f367da8))
|
||||
|
||||
## [3.1.1](https://github.com/adriengibrat/ts-custom-error/compare/v3.1.0...v3.1.1) (2019-07-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **package:** Remove codeclimate-reporter binary from npm package ([52a6db9](https://github.com/adriengibrat/ts-custom-error/commit/52a6db9)), closes [#32](https://github.com/adriengibrat/ts-custom-error/issues/32)
|
||||
|
||||
# [3.1.0](https://github.com/adriengibrat/ts-custom-error/compare/v3.0.0...v3.1.0) (2019-05-17)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **log:** Behave like native Error when using console.log ([f884c51](https://github.com/adriengibrat/ts-custom-error/commit/f884c51)), closes [#30](https://github.com/adriengibrat/ts-custom-error/issues/30)
|
||||
|
||||
# [3.0.0](https://github.com/adriengibrat/ts-custom-error/compare/v2.2.2...v3.0.0) (2019-03-15)
|
||||
|
||||
|
||||
### chore
|
||||
|
||||
* **licence:** Change licence to MIT instead of WTFPL ([7ff194c](https://github.com/adriengibrat/ts-custom-error/commit/7ff194c)), closes [#27](https://github.com/adriengibrat/ts-custom-error/issues/27)
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* **licence:** Change licence to MIT!
|
||||
|
||||
## [2.2.2](https://github.com/adriengibrat/ts-custom-error/compare/v2.2.1...v2.2.2) (2018-12-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **release:** Fix umd minification issue, add typescript definitions for all bundles formats ([a091837](https://github.com/adriengibrat/ts-custom-error/commit/a091837))
|
||||
|
||||
<a name="2.2.1"></a>
|
||||
## [2.2.1](https://github.com/adriengibrat/ts-custom-error/compare/v2.2.0...v2.2.1) (2018-04-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Fix latest travis deploy fail status ([0b18352](https://github.com/adriengibrat/ts-custom-error/commit/0b18352))
|
||||
|
||||
<a name="2.2.0"></a>
|
||||
# [2.2.0](https://github.com/adriengibrat/ts-custom-error/compare/v2.1.0...v2.2.0) (2018-04-04)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add custom error name support ([7791153](https://github.com/adriengibrat/ts-custom-error/commit/7791153))
|
||||
|
||||
<a name="2.1.0"></a>
|
||||
# [2.1.0](https://github.com/adriengibrat/ts-custom-error/compare/v2.0.0...v2.1.0) (2018-03-24)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Improve factory typings ([dc1eed6](https://github.com/adriengibrat/ts-custom-error/commit/dc1eed6))
|
||||
|
||||
|
||||
|
||||
<a name="2.0.0"></a>
|
||||
# [2.0.0](https://github.com/adriengibrat/ts-custom-error/compare/v1.0.1...v2.0.0) (2018-03-16)
|
||||
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
* Change factory export name to customErrorFactory ([e8f51a0](https://github.com/adriengibrat/ts-custom-error/commit/e8f51a0))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Export factory Typescript Interfaces ([d03b476](https://github.com/adriengibrat/ts-custom-error/commit/d03b476))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* the factory export name changed from `factory `to more expliit `customErrorFactory`
|
||||
|
||||
|
||||
|
||||
<a name="1.0.1"></a>
|
||||
## [1.0.1](https://github.com/adriengibrat/ts-custom-error/compare/v1.0.0...v1.0.1) (2018-03-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* Expose constructor in prototype when using factory ([387cc8d](https://github.com/adriengibrat/ts-custom-error/commit/387cc8d))
|
||||
|
||||
|
||||
|
||||
<a name="1.0.0"></a>
|
||||
# [1.0.0](https://github.com/adriengibrat/ts-custom-error/compare/v0.0.2...v1.0.0) (2018-03-12)
|
||||
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
* Rewrite factory to be Higher order function ([720940c](https://github.com/adriengibrat/ts-custom-error/commit/720940c))
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* The factory now accept a function as first parameter where previously it used an error name and a list of property keys
|
||||
|
||||
|
||||
|
||||
<a name="0.0.2"></a>
|
||||
## 0.0.2 (2018-03-12)
|
||||
|
||||
First release
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Adrien Gibrat https://github.com/adriengibrat
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
# Typescript Custom Error
|
||||
|
||||
[](https://www.npmjs.com/package/ts-custom-error)
|
||||
[](#automate-all-the-things)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||
[](https://github.com/adriengibrat/ts-custom-error/actions/workflows/build.yml)
|
||||
[](https://bettercodehub.com/results/adriengibrat/ts-custom-error)
|
||||
[](https://github.com/adriengibrat/ts-custom-error/actions/workflows/codeql.yml)
|
||||
[](https://codeclimate.com/github/adriengibrat/ts-custom-error/maintainability)
|
||||
[](https://codeclimate.com/github/adriengibrat/ts-custom-error/test_coverage)
|
||||
[](http://commitizen.github.io/cz-cli/)
|
||||
[](https://packagephobia.now.sh/result?p=ts-custom-error)
|
||||
[](https://bundlephobia.com/result?p=ts-custom-error)
|
||||
|
||||
## Extend native Error to create custom errors
|
||||
|
||||
`ts-custom-error` is a tiny (~500 bytes of minified & gzipped Javascript) package providing a `CustomError` class and a `customErrorFactory` function to easily extends native Error in node and evergreen browsers.
|
||||
|
||||
It's written in Typescript and try to offer the best development and debug experiences: bundled in Javascript with Typescript definition files, map files and bundled js files for various environments: transpiled to es5 with commonjs, module and umd exports, the umd bundle is also available minified for easy import in browsers.
|
||||
|
||||
## Why
|
||||
|
||||
Because [extending native Error in node and in browsers is tricky](https://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript)
|
||||
```js
|
||||
class MyError extends Error {
|
||||
constructor(m) {
|
||||
super(m)
|
||||
}
|
||||
}
|
||||
```
|
||||
[doesn't work as expected in ES6](https://stackoverflow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax-babel) and [is broken in Typescript](https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work).
|
||||
|
||||
### Use `CustomError` class
|
||||
|
||||
Simply extends and call `super` in you custom constructor.
|
||||
|
||||
```ts
|
||||
import { CustomError } from 'ts-custom-error'
|
||||
|
||||
class HttpError extends CustomError {
|
||||
public constructor(
|
||||
public code: number,
|
||||
message?: string,
|
||||
) {
|
||||
super(message)
|
||||
}
|
||||
}
|
||||
|
||||
...
|
||||
|
||||
new HttpError(404, 'Not found')
|
||||
```
|
||||
You may want more advanced contructor logic and custom methods, see [examples](https://github.com/adriengibrat/ts-custom-error/tree/main/src/example)
|
||||
|
||||
### Use `customErrorFactory` factory
|
||||
|
||||
*Custom error contructor returned by the factory pass the same unit tests as Class constructor.*
|
||||
|
||||
Factory still allows custom logic inside constructor:
|
||||
|
||||
```ts
|
||||
import { customErrorFactory } from 'ts-custom-error'
|
||||
|
||||
const HttpError = customErrorFactory(function HttpError (code: number, message= '') {
|
||||
this.code = code
|
||||
this.message = message
|
||||
})
|
||||
|
||||
...
|
||||
|
||||
new HttpError(404, 'Not found')
|
||||
```
|
||||
|
||||
Custom Error from `customErrorFactory` can:
|
||||
- Be called as a simple function
|
||||
```ts
|
||||
HttpError(404, 'Not found')
|
||||
```
|
||||
- Extend any native Error, using the second optional argument
|
||||
```ts
|
||||
import { customErrorFactory } from 'ts-custom-error'
|
||||
|
||||
const ValidationError = customErrorFactory(function ValidationError (message= 'Invalid parameter') {
|
||||
this.message = message
|
||||
}, TypeError)
|
||||
```
|
||||
|
||||
### Known limitations
|
||||
|
||||
#### Minification and transpilation mangle custom Error names.
|
||||
Unexpected results are:
|
||||
- Minified identifiers in place of custom Error name in Stacktrace
|
||||
- Wrong error recognition where using errors name (bad practice) instead of `instanceof`
|
||||
|
||||
You may fix this behaviour by:
|
||||
- Using [uglifyjs options](https://github.com/mishoo/UglifyJS2/blob/harmony/README.md) `--mangle 'except=["MyError"]'` (need to specify all custom error names) or `--keep_fnames` / `--keep_classnames` (nothing to specify but your bundle size will be larger)
|
||||
- Setting explicitly error name:
|
||||
|
||||
```ts
|
||||
import { CustomError } from 'ts-custom-error'
|
||||
|
||||
class MyError extends CustomError {
|
||||
constructor() {
|
||||
super()
|
||||
// Set name explicitly as minification can mangle class names
|
||||
Object.defineProperty(this, 'name', { value: 'MyError' })
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
import { customErrorFactory } from 'ts-custom-error'
|
||||
|
||||
const MyError = customErrorFactory(function MyError () {
|
||||
// Set name explicitly as minification can remove function expression names
|
||||
Object.defineProperty(this, 'name', { value: 'MyError' })
|
||||
})
|
||||
```
|
||||
|
||||
### Usefull development commands
|
||||
|
||||
- Watch source changes and run corresponding unit tests
|
||||
```
|
||||
npm start
|
||||
```
|
||||
|
||||
- Run all unit tests
|
||||
```
|
||||
npm test
|
||||
```
|
||||
|
||||
- Get coverage report
|
||||
```
|
||||
npm run coverage
|
||||
```
|
||||
|
||||
- Format staged code and run commitizen (enforce commit message convention)
|
||||
```
|
||||
npm run commit
|
||||
```
|
||||
|
||||
### Automate all the things
|
||||
|
||||
⚠️ This project is mainly a pet project and its first purpose is to be a playground for various external services and tools:
|
||||
- opinionated code style mostly inspired from [standardjs](https://standardjs.com)
|
||||
- automatic code formating with [prettier](https://github.com/prettier/prettier)
|
||||
- code quality analysis by [codeclimate](https://codeclimate.com/github/adriengibrat/ts-custom-error)~~, [bithound](https://www.bithound.io/github/adriengibrat/ts-custom-error)~~, [bettercodehub](https://bettercodehub.com/results/adriengibrat/ts-custom-error) & [CodeQL](https://github.com/adriengibrat/ts-custom-error/security/code-scanning)
|
||||
- automated continuous integration on ~~[travis](https://travis-ci.org/adriengibrat/ts-custom-error)~~ [github actions](https://github.com/adriengibrat/ts-custom-error/actions) & [Dependabot](https://github.com/adriengibrat/ts-custom-error/security/dependabot)
|
||||
- automated semantic versioning with [changelog](CHANGELOG.md) generation and release deployment on [npm](https://www.npmjs.com/package/ts-custom-error) and [github](https://github.com/adriengibrat/ts-custom-error/releases) thanks to [semantic-release](https://github.com/semantic-release/semantic-release)
|
||||
|
||||
## Licence
|
||||
|
||||
Starting [version 3.0.0](https://github.com/adriengibrat/ts-custom-error/releases/tag/v3.0.0) this project is under [MIT licence](LICENSE), there are no code change between [version 2.2.2](https://github.com/adriengibrat/ts-custom-error/releases/tag/v2.2.2) and [version 3.0.0](https://github.com/adriengibrat/ts-custom-error/releases/tag/v3.0.0) but changing licence was considered as a breaking change. All [versions < 3.0.0](https://github.com/adriengibrat/ts-custom-error/releases) are under [WTFPL](http://www.wtfpl.net).
|
||||
|
||||
## Similar packages
|
||||
|
||||
- [](https://www.npmjs.com/package/custom-error) [custom-error](https://github.com/andrezsanchez/custom-error) provides a factory with custom name and parent error
|
||||
- [](https://www.npmjs.com/package/custom-errors) [custom-errors](https://github.com/techjacker/custom-errors) provides a class and a factory with custom name and message, easy integration with with [express](https://github.com/expressjs/express) and (log)[https://github.com/visionmedia/log.js]
|
||||
- [](https://www.npmjs.com/package/custom-error-generator) [custom-error-generator](https://github.com/jproulx/node-custom-error) provides a factory with custom name, default properties and a constructor (node only)
|
||||
- [](https://www.npmjs.com/package/custom-error-instance) [custom-error-instance](https://github.com/Gi60s/custom-error-instance) provides a factory with custom name, properties and construction logic (! browser compatibility: redefine constructor name)
|
||||
- [](https://www.npmjs.com/package/node-custom-errors) [node-custom-errors](https://github.com/axyjs/node-custom-errors) provides factories to create abstract or concrete error with default message, an optional constructor function allow more custom properties/methods (node/chrome only, because no feature detection)
|
||||
- [](https://www.npmjs.com/package/extendable-error) [extendable-error](https://github.com/vilic/extendable-error) provides a class with clean stacktrace even in non v8 environments
|
||||
- [](https://www.npmjs.com/package/extendable-error-class) [extendable-error-class](https://github.com/brillout/extendable-error-class) provides simple class
|
||||
- [](https://www.npmjs.com/package/extend-error) [extend-error](https://github.com/jayyvis/extend-error) provides a factory attached to global Error object, allows custom name, code & message error
|
||||
- [](https://www.npmjs.com/package/error-extend) [error-extend](https://github.com/tilap/error-extend) provides a factory with custom name, default code & message properties, an optional init function allow more custom properties/methods
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 3.x.x | :white_check_mark: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please [create an issue with the "security" label](https://github.com/adriengibrat/ts-custom-error/issues/new?labels=security).
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
interface ErrorOptions {
|
||||
cause?: unknown;
|
||||
}
|
||||
export declare class CustomError extends Error {
|
||||
name: string;
|
||||
constructor(message?: string, options?: ErrorOptions);
|
||||
}
|
||||
export {};
|
||||
export interface CustomErrorInterface extends Error {
|
||||
}
|
||||
export interface CustomErrorProperties {
|
||||
[property: string]: any;
|
||||
}
|
||||
export interface CustomErrorConstructor<Properties extends CustomErrorProperties> extends ErrorConstructor {
|
||||
readonly prototype: CustomErrorInterface;
|
||||
new (...args: any[]): CustomErrorInterface & Properties;
|
||||
(...args: any[]): CustomErrorInterface & Properties;
|
||||
}
|
||||
export declare type GenericErrorConstructor = ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor | URIErrorConstructor | CustomErrorConstructor<CustomErrorProperties>;
|
||||
declare type CustomErrorFunction<Properties> = (this: Properties, ...args: any[]) => void;
|
||||
export declare function customErrorFactory<Properties extends CustomErrorProperties>(fn: CustomErrorFunction<Properties>, parent?: GenericErrorConstructor): CustomErrorConstructor<Properties>;
|
||||
export {};
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
function fixProto(target, prototype) {
|
||||
var setPrototypeOf = Object.setPrototypeOf;
|
||||
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
||||
}
|
||||
function fixStack(target, fn) {
|
||||
if (fn === void 0) {
|
||||
fn = target.constructor;
|
||||
}
|
||||
|
||||
var captureStackTrace = Error.captureStackTrace;
|
||||
captureStackTrace && captureStackTrace(target, fn);
|
||||
}
|
||||
|
||||
var __extends = undefined && undefined.__extends || function () {
|
||||
var _extendStatics = function extendStatics(d, b) {
|
||||
_extendStatics = Object.setPrototypeOf || {
|
||||
__proto__: []
|
||||
} instanceof Array && function (d, b) {
|
||||
d.__proto__ = b;
|
||||
} || function (d, b) {
|
||||
for (var p in b) {
|
||||
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
||||
}
|
||||
};
|
||||
|
||||
return _extendStatics(d, b);
|
||||
};
|
||||
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
|
||||
_extendStatics(d, b);
|
||||
|
||||
function __() {
|
||||
this.constructor = d;
|
||||
}
|
||||
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
}();
|
||||
|
||||
var CustomError = function (_super) {
|
||||
__extends(CustomError, _super);
|
||||
|
||||
function CustomError(message, options) {
|
||||
var _newTarget = this.constructor;
|
||||
|
||||
var _this = _super.call(this, message, options) || this;
|
||||
|
||||
Object.defineProperty(_this, 'name', {
|
||||
value: _newTarget.name,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
fixProto(_this, _newTarget.prototype);
|
||||
fixStack(_this);
|
||||
return _this;
|
||||
}
|
||||
|
||||
return CustomError;
|
||||
}(Error);
|
||||
|
||||
var __spreadArray = undefined && undefined.__spreadArray || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
function customErrorFactory(fn, parent) {
|
||||
if (parent === void 0) {
|
||||
parent = Error;
|
||||
}
|
||||
|
||||
function CustomError() {
|
||||
var args = [];
|
||||
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
|
||||
if (!(this instanceof CustomError)) return new (CustomError.bind.apply(CustomError, __spreadArray([void 0], args, false)))();
|
||||
parent.apply(this, args);
|
||||
Object.defineProperty(this, 'name', {
|
||||
value: fn.name || parent.name,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
fn.apply(this, args);
|
||||
fixStack(this, CustomError);
|
||||
}
|
||||
|
||||
return Object.defineProperties(CustomError, {
|
||||
prototype: {
|
||||
value: Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: CustomError,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.CustomError = CustomError;
|
||||
exports.customErrorFactory = customErrorFactory;
|
||||
//# sourceMappingURL=custom-error.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+109
@@ -0,0 +1,109 @@
|
||||
function fixProto(target, prototype) {
|
||||
var setPrototypeOf = Object.setPrototypeOf;
|
||||
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
||||
}
|
||||
function fixStack(target, fn) {
|
||||
if (fn === void 0) {
|
||||
fn = target.constructor;
|
||||
}
|
||||
|
||||
var captureStackTrace = Error.captureStackTrace;
|
||||
captureStackTrace && captureStackTrace(target, fn);
|
||||
}
|
||||
|
||||
var __extends = undefined && undefined.__extends || function () {
|
||||
var _extendStatics = function extendStatics(d, b) {
|
||||
_extendStatics = Object.setPrototypeOf || {
|
||||
__proto__: []
|
||||
} instanceof Array && function (d, b) {
|
||||
d.__proto__ = b;
|
||||
} || function (d, b) {
|
||||
for (var p in b) {
|
||||
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
||||
}
|
||||
};
|
||||
|
||||
return _extendStatics(d, b);
|
||||
};
|
||||
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
|
||||
_extendStatics(d, b);
|
||||
|
||||
function __() {
|
||||
this.constructor = d;
|
||||
}
|
||||
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
}();
|
||||
|
||||
var CustomError = function (_super) {
|
||||
__extends(CustomError, _super);
|
||||
|
||||
function CustomError(message, options) {
|
||||
var _newTarget = this.constructor;
|
||||
|
||||
var _this = _super.call(this, message, options) || this;
|
||||
|
||||
Object.defineProperty(_this, 'name', {
|
||||
value: _newTarget.name,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
fixProto(_this, _newTarget.prototype);
|
||||
fixStack(_this);
|
||||
return _this;
|
||||
}
|
||||
|
||||
return CustomError;
|
||||
}(Error);
|
||||
|
||||
var __spreadArray = undefined && undefined.__spreadArray || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
function customErrorFactory(fn, parent) {
|
||||
if (parent === void 0) {
|
||||
parent = Error;
|
||||
}
|
||||
|
||||
function CustomError() {
|
||||
var args = [];
|
||||
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
|
||||
if (!(this instanceof CustomError)) return new (CustomError.bind.apply(CustomError, __spreadArray([void 0], args, false)))();
|
||||
parent.apply(this, args);
|
||||
Object.defineProperty(this, 'name', {
|
||||
value: fn.name || parent.name,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
fn.apply(this, args);
|
||||
fixStack(this, CustomError);
|
||||
}
|
||||
|
||||
return Object.defineProperties(CustomError, {
|
||||
prototype: {
|
||||
value: Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: CustomError,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { CustomError, customErrorFactory };
|
||||
//# sourceMappingURL=custom-error.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+107
@@ -0,0 +1,107 @@
|
||||
function fixProto(target, prototype) {
|
||||
var setPrototypeOf = Object.setPrototypeOf;
|
||||
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
||||
}
|
||||
function fixStack(target, fn) {
|
||||
if (fn === void 0) {
|
||||
fn = target.constructor;
|
||||
}
|
||||
|
||||
var captureStackTrace = Error.captureStackTrace;
|
||||
captureStackTrace && captureStackTrace(target, fn);
|
||||
}
|
||||
|
||||
var __extends = undefined && undefined.__extends || function () {
|
||||
var _extendStatics = function extendStatics(d, b) {
|
||||
_extendStatics = Object.setPrototypeOf || {
|
||||
__proto__: []
|
||||
} instanceof Array && function (d, b) {
|
||||
d.__proto__ = b;
|
||||
} || function (d, b) {
|
||||
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
||||
};
|
||||
|
||||
return _extendStatics(d, b);
|
||||
};
|
||||
|
||||
return function (d, b) {
|
||||
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
|
||||
_extendStatics(d, b);
|
||||
|
||||
function __() {
|
||||
this.constructor = d;
|
||||
}
|
||||
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
}();
|
||||
|
||||
var CustomError = function (_super) {
|
||||
__extends(CustomError, _super);
|
||||
|
||||
function CustomError(message, options) {
|
||||
var _newTarget = this.constructor;
|
||||
|
||||
var _this = _super.call(this, message, options) || this;
|
||||
|
||||
Object.defineProperty(_this, 'name', {
|
||||
value: _newTarget.name,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
fixProto(_this, _newTarget.prototype);
|
||||
fixStack(_this);
|
||||
return _this;
|
||||
}
|
||||
|
||||
return CustomError;
|
||||
}(Error);
|
||||
|
||||
var __spreadArray = undefined && undefined.__spreadArray || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
function customErrorFactory(fn, parent) {
|
||||
if (parent === void 0) {
|
||||
parent = Error;
|
||||
}
|
||||
|
||||
function CustomError() {
|
||||
var args = [];
|
||||
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
|
||||
if (!(this instanceof CustomError)) return new (CustomError.bind.apply(CustomError, __spreadArray([void 0], args, false)))();
|
||||
parent.apply(this, args);
|
||||
Object.defineProperty(this, 'name', {
|
||||
value: fn.name || parent.name,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
fn.apply(this, args);
|
||||
fixStack(this, CustomError);
|
||||
}
|
||||
|
||||
return Object.defineProperties(CustomError, {
|
||||
prototype: {
|
||||
value: Object.create(parent.prototype, {
|
||||
constructor: {
|
||||
value: CustomError,
|
||||
writable: true,
|
||||
configurable: true
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export { CustomError, customErrorFactory };
|
||||
//# sourceMappingURL=custom-error.modern.mjs.map
|
||||
+1
File diff suppressed because one or more lines are too long
+22
@@ -0,0 +1,22 @@
|
||||
interface ErrorOptions {
|
||||
cause?: unknown;
|
||||
}
|
||||
export declare class CustomError extends Error {
|
||||
name: string;
|
||||
constructor(message?: string, options?: ErrorOptions);
|
||||
}
|
||||
export {};
|
||||
export interface CustomErrorInterface extends Error {
|
||||
}
|
||||
export interface CustomErrorProperties {
|
||||
[property: string]: any;
|
||||
}
|
||||
export interface CustomErrorConstructor<Properties extends CustomErrorProperties> extends ErrorConstructor {
|
||||
readonly prototype: CustomErrorInterface;
|
||||
new (...args: any[]): CustomErrorInterface & Properties;
|
||||
(...args: any[]): CustomErrorInterface & Properties;
|
||||
}
|
||||
export declare type GenericErrorConstructor = ErrorConstructor | EvalErrorConstructor | RangeErrorConstructor | ReferenceErrorConstructor | SyntaxErrorConstructor | TypeErrorConstructor | URIErrorConstructor | CustomErrorConstructor<CustomErrorProperties>;
|
||||
declare type CustomErrorFunction<Properties> = (this: Properties, ...args: any[]) => void;
|
||||
export declare function customErrorFactory<Properties extends CustomErrorProperties>(fn: CustomErrorFunction<Properties>, parent?: GenericErrorConstructor): CustomErrorConstructor<Properties>;
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports):"function"==typeof define&&define.amd?define(["exports"],factory):factory((global=global||self).tsCustomError={})}(this,function(exports){function fixStack(target,fn){void 0===fn&&(fn=target.constructor);var captureStackTrace=Error.captureStackTrace;captureStackTrace&&captureStackTrace(target,fn)}_extendStatics=function(d,b){return(_extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)Object.prototype.hasOwnProperty.call(b,p)&&(d[p]=b[p])})(d,b)};var _extendStatics,__extends=function(d,b){if("function"!=typeof b&&null!==b)throw new TypeError("Class extends value "+String(b)+" is not a constructor or null");function __(){this.constructor=d}_extendStatics(d,b),d.prototype=null===b?Object.create(b):(__.prototype=b.prototype,new __)},CustomError=function(_super){function CustomError(message,options){var setPrototypeOf,_newTarget=this.constructor,message=_super.call(this,message,options)||this;return Object.defineProperty(message,"name",{value:_newTarget.name,enumerable:!1,configurable:!0}),options=message,_newTarget=_newTarget.prototype,(setPrototypeOf=Object.setPrototypeOf)?setPrototypeOf(options,_newTarget):options.__proto__=_newTarget,fixStack(message),message}return __extends(CustomError,_super),CustomError}(Error),__spreadArray=function(to,from,pack){if(pack||2===arguments.length)for(var ar,i=0,l=from.length;i<l;i++)!ar&&i in from||((ar=ar||Array.prototype.slice.call(from,0,i))[i]=from[i]);return to.concat(ar||Array.prototype.slice.call(from))};exports.CustomError=CustomError,exports.customErrorFactory=function(fn,parent){function CustomError(){for(var args=[],_i=0;_i<arguments.length;_i++)args[_i]=arguments[_i];if(!(this instanceof CustomError))return new(CustomError.bind.apply(CustomError,__spreadArray([void 0],args,!1)));parent.apply(this,args),Object.defineProperty(this,"name",{value:fn.name||parent.name,enumerable:!1,configurable:!0}),fn.apply(this,args),fixStack(this,CustomError)}return void 0===parent&&(parent=Error),Object.defineProperties(CustomError,{prototype:{value:Object.create(parent.prototype,{constructor:{value:CustomError,writable:!0,configurable:!0}})}})}});
|
||||
+1
File diff suppressed because one or more lines are too long
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./custom-error";
|
||||
export * from "./factory";
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
{
|
||||
"name": "ts-custom-error",
|
||||
"version": "3.3.1",
|
||||
"description": "Extend native Error to create custom errors",
|
||||
"repository": "github:adriengibrat/ts-custom-error",
|
||||
"bugs": "https://github.com/adriengibrat/ts-custom-error/issues",
|
||||
"keywords": [
|
||||
"custom Error",
|
||||
"extend",
|
||||
"Error"
|
||||
],
|
||||
"author": "Adrien Gibrat <adrien.gibrat@gmail.com>",
|
||||
"license": "MIT",
|
||||
"main": "dist/custom-error.js",
|
||||
"module": "dist/custom-error.mjs",
|
||||
"unpkg": "dist/custom-error.umd.js",
|
||||
"types": "dist/custom-error.d.ts",
|
||||
"engines": {
|
||||
"node": ">=14.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "jest --watch --notify",
|
||||
"prebuild": "rm -rf dist",
|
||||
"build": "tsc --build tsconfig.json && microbundle build --no-compress --entry dist/src/index.js",
|
||||
"postbuild": "npm run minify:umd && npm run types:concat && npm run dist:cleanup",
|
||||
"minify:umd": "uglifyjs --compress --output dist/custom-error.umd.js -- dist/custom-error.umd.js",
|
||||
"types:concat": "cat dist/src/factory.d.ts >> dist/src/custom-error.d.ts && cat dist/src/custom-error.d.ts > dist/custom-error.d.ts && cat dist/custom-error.d.ts > dist/custom-error.umd.d.ts",
|
||||
"dist:cleanup": "rm -rf dist/src",
|
||||
"test": "jest",
|
||||
"coverage": "jest --coverage",
|
||||
"commit": "lint-staged && git-cz"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@semantic-release/changelog": "^6.0.1",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@types/jest": "^28.1.8",
|
||||
"@types/node": "^18.7.13",
|
||||
"commitizen": "^4.2.5",
|
||||
"cz-conventional-changelog": "^3.3.0",
|
||||
"jest": "^28.0.0",
|
||||
"jest-tap-reporter": "^1.9.0",
|
||||
"lint-staged": "^13.0.3",
|
||||
"microbundle": "^0.15.1",
|
||||
"prettier": "^2.7.1",
|
||||
"semantic-release": "^19.0.5",
|
||||
"ts-jest": "^28.0.8",
|
||||
"tslint": "^6.1.2",
|
||||
"tslint-config-prettier": "^1.18.0",
|
||||
"tslint-config-standard": "^9.0.0",
|
||||
"typescript": "^4.8.2",
|
||||
"uglifyjs": "^2.4.11"
|
||||
},
|
||||
"mangle": {
|
||||
"regex": "^(?!CustomError\b).*"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "cz-conventional-changelog"
|
||||
}
|
||||
},
|
||||
"prettier": {
|
||||
"useTabs": true,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.ts": [
|
||||
"prettier --write",
|
||||
"tslint",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"jest": {
|
||||
"reporters": [
|
||||
"jest-tap-reporter"
|
||||
],
|
||||
"testRegex": "\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.tsx?$": "ts-jest"
|
||||
},
|
||||
"moduleFileExtensions": [
|
||||
"ts",
|
||||
"js"
|
||||
],
|
||||
"preset": "ts-jest",
|
||||
"testMatch": null
|
||||
},
|
||||
"release": {
|
||||
"branches": [
|
||||
"main"
|
||||
],
|
||||
"verifyConditions": [
|
||||
"@semantic-release/changelog",
|
||||
"@semantic-release/npm",
|
||||
"@semantic-release/git"
|
||||
],
|
||||
"prepare": [
|
||||
"@semantic-release/changelog",
|
||||
"@semantic-release/npm",
|
||||
"@semantic-release/git"
|
||||
],
|
||||
"publish": [
|
||||
"@semantic-release/npm",
|
||||
{
|
||||
"path": "@semantic-release/github",
|
||||
"assets": [
|
||||
{
|
||||
"path": "dist/custom-error.d.ts",
|
||||
"label": "Typescript typings"
|
||||
},
|
||||
{
|
||||
"path": "dist/custom-error.js",
|
||||
"label": "Common JS"
|
||||
},
|
||||
{
|
||||
"path": "dist/custom-error.js.map",
|
||||
"label": "Common JS - sourcemap"
|
||||
},
|
||||
{
|
||||
"path": "dist/custom-error.mjs",
|
||||
"label": "ES module"
|
||||
},
|
||||
{
|
||||
"path": "dist/custom-error.mjs.map",
|
||||
"label": "ES module - sourcemap"
|
||||
},
|
||||
{
|
||||
"path": "dist/custom-error.umd.js",
|
||||
"label": "UMD (minified, CDN ready)"
|
||||
},
|
||||
{
|
||||
"path": "dist/custom-error.umd.js.map",
|
||||
"label": "UMD - sourcemap"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user