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

err-code

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

err-code - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

20

index.js
'use strict';
function maybeDefineProperty(obj, name, value) {
var descriptor;
if (Object.isFrozen(obj)) {
return;
}
descriptor = Object.getOwnPropertyDescriptor(obj, name);
if (descriptor && !descriptor.writable) {
return;
}
obj[name] = value;
}
function createError(err, code, props) {

@@ -13,3 +29,3 @@ var key;

} else if (code != null) {
err.code = code;
maybeDefineProperty(err, 'code', code);
}

@@ -19,3 +35,3 @@

for (key in props) {
err[key] = props[key];
maybeDefineProperty(err, key, props[key]);
}

@@ -22,0 +38,0 @@ }

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.errCode = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';
function maybeDefineProperty(obj, name, value) {
var descriptor;
if (Object.isFrozen(obj)) {
return;
}
descriptor = Object.getOwnPropertyDescriptor(obj, name);
if (descriptor && !descriptor.writable) {
return;
}
obj[name] = value;
}
function createError(err, code, props) {

@@ -14,3 +30,3 @@ var key;

} else if (code != null) {
err.code = code;
maybeDefineProperty(err, 'code', code);
}

@@ -20,3 +36,3 @@

for (key in props) {
err[key] = props[key];
maybeDefineProperty(err, key, props[key]);
}

@@ -23,0 +39,0 @@ }

2

package.json
{
"name": "err-code",
"version": "2.0.0",
"version": "2.0.1",
"description": "Create an error with a code",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -58,3 +58,7 @@ # err-code

## Pre-existing fields
If the passed `Error` already has a `.code` field, or fields specified in the third argument to `errcode` they will be overwritten, unless the fields have been [defined as read-only](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) or the `Error` object has been [frozen](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze).
## Tests

@@ -61,0 +65,0 @@

@@ -51,2 +51,24 @@ 'use strict';

});
it('should not attempt to set non-writable field', function () {
var myErr = new Error('my message');
var err;
Object.defineProperty(myErr, 'code', {
value: 'derp',
writable: false,
});
err = errcode(myErr, 'ERR_WAT');
expect(err).to.be.an(Error);
expect(err.code).to.be('derp');
});
it('should not add code to frozen object', function () {
var myErr = new Error('my message');
var err = errcode(Object.freeze(myErr), 'ERR_WAT');
expect(err).to.be.an(Error);
expect(err.code).to.be(undefined);
});
});

@@ -53,0 +75,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