Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

defekt

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defekt - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

16

dist/defekt.js

@@ -15,8 +15,16 @@ 'use strict';

errorDefinitions.forEach(function (errorDefinition) {
var errorName = errorDefinition;
var errorName = void 0;
var errorCode = void 0;
if ((typeof errorDefinition === 'undefined' ? 'undefined' : _typeof(errorDefinition)) === 'object') {
errorName = errorDefinition.name;
errorCode = errorDefinition.code;
switch (typeof errorDefinition === 'undefined' ? 'undefined' : _typeof(errorDefinition)) {
case 'string':
errorName = errorDefinition;
errorCode = 'E' + errorDefinition.toUpperCase();
break;
case 'object':
errorName = errorDefinition.name;
errorCode = errorDefinition.code;
break;
default:
throw new Error('Invalid error definition.');
}

@@ -23,0 +31,0 @@

@@ -13,8 +13,16 @@ 'use strict';

errorDefinitions.forEach(errorDefinition => {
let errorName = errorDefinition;
let errorName;
let errorCode;
if (typeof errorDefinition === 'object') {
errorName = errorDefinition.name;
errorCode = errorDefinition.code;
switch (typeof errorDefinition) {
case 'string':
errorName = errorDefinition;
errorCode = `E${errorDefinition.toUpperCase()}`;
break;
case 'object':
errorName = errorDefinition.name;
errorCode = errorDefinition.code;
break;
default:
throw new Error('Invalid error definition.');
}

@@ -21,0 +29,0 @@

{
"name": "defekt",
"version": "0.1.3",
"version": "0.2.0",
"description": "defekt is custom errors made simple.",

@@ -13,2 +13,6 @@ "contributors": [

"email": "matthias.wagler@thenativeweb.io"
},
{
"name": "Michael Scherer",
"email": "mail@michael-scherer.net"
}

@@ -21,5 +25,5 @@ ],

"devDependencies": {
"assertthat": "0.8.3",
"roboter": "0.14.6",
"roboter-server": "0.14.6"
"assertthat": "0.10.3",
"roboter": "0.15.4",
"roboter-server": "0.15.4"
},

@@ -26,0 +30,0 @@ "repository": {

@@ -9,3 +9,3 @@ # defekt

```bash
```shell
$ npm install defekt

@@ -54,4 +54,6 @@ ```

Additionally, you may want to provide error codes. For that specify an object with a `name` and a `code` property instead of only providing the error name.
By default, each custom error uses its uppercased name with an `E` prefix as error code. E.g., an `InvalidOperation` error uses `EINVALIDOPERATION` as its code.
From time to time, you may want to provide custom error codes. For that specify an object with a `name` and a `code` property instead of only providing the error name.
```javascript

@@ -71,3 +73,3 @@ const errors = defekt([

```bash
```shell
$ bot

@@ -74,0 +76,0 @@ ```

@@ -38,2 +38,5 @@ 'use strict';

// BSD-3-Clause, see https://github.com/estools/esquery/blob/v1.0.0/license.txt
esquery: '1.0.0',
// MIT, see https://github.com/mklabs/node-fileset/blob/v0.2.1/LICENSE-MIT

@@ -45,4 +48,4 @@ fileset: '0.2.1',

// BSD-2-Clause, see https://github.com/facebook/regenerator/blob/e22c9317987ebcf4041e9188cb208b94f662df35/LICENSE
'regenerator-transform': '0.9.8',
// BSD-2-Clause, see https://github.com/facebook/regenerator/blob/30d34536b9e3f7a2873b04a16ec66fec9c8246f6/LICENSE
'regenerator-transform': '0.10.1',

@@ -49,0 +52,0 @@ // BSD-2-Clause, see https://github.com/jviereck/regjsparser/blob/0.1.5/LICENSE.BSD

@@ -64,7 +64,7 @@ 'use strict';

suite('code', () => {
test('is undefined by default.', done => {
test('is the E-prefixed upper-cased name by default.', done => {
const errors = defekt([ 'InvalidOperation', 'ArgumentNull' ]);
const error = new errors.InvalidOperation();
assert.that(error.code).is.undefined();
assert.that(error.code).is.equalTo('EINVALIDOPERATION');
done();

@@ -71,0 +71,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc