New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

error-ninja

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

error-ninja - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

38

errorNinja.js

@@ -39,2 +39,4 @@ /*

err.id = id;
err.isError = true;
err.isNinja = true;
err.name = 'Error [' + id + ']';

@@ -53,1 +55,37 @@ err.message = message + dataStr;

};
/*
* Returns true if the given input is an error, or optionally an ErrorNinja.
*/
ME.isError = function (err, ninjaOnly) {
if (typeof ninjaOnly === 'undefined') { ninjaOnly = false; }
// Must be an object first, there is no typeof 'error'.
if (typeof err !== 'object') { return false; }
// Must have a valid constructor name.
var constructorName = err.constructor.name.tolowerCase();
if (
constructorName !== 'error' &&
constructorName !== 'RangeError' &&
constructorName !== 'ReferenceError' &&
constructorName !== 'TypeError' &&
constructorName !== 'SyntaxError'
) {
return false;
}
// Do we also need to be an ErrorNinja?
if (ninjaOnly && (!err.isError || !err.isNinja)) { return false; }
// Success! We have an error.
return true;
};
/*
* Returns true if the given input is specifically an ErrorNinja.
*/
ME.isNinja = function (err) {
return ME.isError(err, true);
};

2

package.json

@@ -10,3 +10,3 @@ {

"name": "error-ninja",
"version": "0.0.2",
"version": "0.0.3",
"description": "Allows us to pre-define error types and error messages in each module.",

@@ -13,0 +13,0 @@ "keywords": [

@@ -10,2 +10,3 @@ # Error-Ninja

5. Throws just like a plain old JavaScript Error.
6. Allows you to detect if a variable is a JavaScript error or an ErrorNinja error.

@@ -85,6 +86,21 @@ ## Define Your Error Messages

err.id; // "attachment-too-big"
err.human; // "You cannot upload an attachment that big!"
err.data; // (mixed) e.g. { fileSize: 17483, maxSize: 1024 }
// data defaults to {}
err.id; // "attachment-too-big"
err.isError; // True
err.isNinja; // True
err.human; // "You cannot upload an attachment that big!"
err.data; // (mixed) e.g. { fileSize: 17483, maxSize: 1024 }
// data defaults to {}
```
## How to Tell if a Variable is an Error?
ErrorNinja provides two methods to detect if a variable is an error, or more specifically an ErrorNinja error.
```javascript
// Ordinary JavaScript errors.
var err1 = new Error();
if (ErrorNinja.isError(err1)) { ... }
// ErrorNinja errors.
var err2 = new ErrorNinja('...');
if (ErrorNinja.isNinja(err2)) { ... }
```

Sorry, the diff of this file is not supported yet

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