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

errorish

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

errorish - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

23

CHANGELOG.md

@@ -1,4 +0,25 @@

# 0.1.0 (2019-04-18)
# [0.2.0](https://github.com/rafamel/errorish/compare/v0.1.0...v0.2.0) (2019-04-21)
### Code Refactoring
* **types, rejects:** renames IExceptionOptions to IRejectionOptions ([770ccd5](https://github.com/rafamel/errorish/commit/770ccd5))
### Features
* **throws:** throws now takes a function instead of an error ([eac3b46](https://github.com/rafamel/errorish/commit/eac3b46))
### BREAKING CHANGES
* **types, rejects:** IExceptionOptions is now IRejectionOptions
* **throws:** throws now takes a function instead of an error; it will ensure and throw any error
thrown by that function, otherwise returning its value.
# [0.1.0](https://github.com/rafamel/errorish/compare/d68f3a7...v0.1.0) (2019-04-18)
### Bug Fixes

@@ -5,0 +26,0 @@

14

dist-node/index.js

@@ -118,8 +118,11 @@ 'use strict';

/**
* Throws an `error`, having called `ensure` on it.
* Returns the result of `fn`; if it throws, it will call `ensure` on the thrown error and throw it.
*/
function throws(error, options, data) {
const condition = options && options.hasOwnProperty('case') ? options.case : true;
if (condition) throw ensure(error, options, data);
function throws(fn, options, data) {
try {
return fn();
} catch (err) {
throw ensure(err, options, data);
}
}

@@ -132,3 +135,4 @@

async function rejects(error, options, data) {
return throws(error, options, data);
const condition = options && options.hasOwnProperty('case') ? options.case : true;
if (condition) throw ensure(error, options, data);
}

@@ -135,0 +139,0 @@

@@ -1,2 +0,2 @@

import throws from "./throws.js";
import ensure from "./ensure/index.js";
export default rejects;

@@ -8,3 +8,4 @@

async function rejects(error, options, data) {
return throws(error, options, data);
const condition = options && options.hasOwnProperty('case') ? options.case : true;
if (condition) throw ensure(error, options, data);
}
import ensure from "./ensure/index.js";
export default throws;
/**
* Throws an `error`, having called `ensure` on it.
* Returns the result of `fn`; if it throws, it will call `ensure` on the thrown error and throw it.
*/
function throws(error, options, data) {
const condition = options && options.hasOwnProperty('case') ? options.case : true;
if (condition) throw ensure(error, options, data);
export default function throws(fn, options, data) {
try {
return fn();
} catch (err) {
throw ensure(err, options, data);
}
}

@@ -1,7 +0,7 @@

import { IExceptionOptions, ICoreOptions, IOfType } from './types';
import { IRejectionOptions, ICoreOptions, IOfType } from './types';
export default rejects;
declare function rejects(error: any, options: IExceptionOptions & {
declare function rejects(error: any, options: IRejectionOptions & {
case: true;
}, data?: IOfType<any>): Promise<never>;
declare function rejects(error: any, options: IExceptionOptions, data?: IOfType<any>): Promise<void>;
declare function rejects(error: any, options: IRejectionOptions, data?: IOfType<any>): Promise<void>;
declare function rejects(error: any, options?: ICoreOptions | null, data?: IOfType<any>): Promise<never>;

@@ -1,7 +0,5 @@

import { IExceptionOptions, ICoreOptions, IOfType } from './types';
export default throws;
declare function throws(error: any, options: IExceptionOptions & {
case: true;
}, data?: IOfType<any>): never;
declare function throws(error: any, options: IExceptionOptions, data?: IOfType<any>): void;
declare function throws(error: any, options?: ICoreOptions | null, data?: IOfType<any>): never;
import { ICoreOptions, IOfType } from './types';
/**
* Returns the result of `fn`; if it throws, it will call `ensure` on the thrown error and throw it.
*/
export default function throws<T>(fn: () => T, options?: ICoreOptions | null, data?: IOfType<any>): T;

@@ -67,7 +67,7 @@ import Errorish from './Errorish';

}
export interface IExceptionOptions extends ICoreOptions {
export interface IRejectionOptions extends ICoreOptions {
/**
* If `case` exists, `throws` and `rejects` will only throw/reject when `true`, otherwise their response will be void.
* If `case` exists, `rejects` will only reject when `true`, otherwise its response will be void.
*/
case?: boolean;
}

@@ -150,8 +150,11 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {

/**
* Throws an `error`, having called `ensure` on it.
* Returns the result of `fn`; if it throws, it will call `ensure` on the thrown error and throw it.
*/
function throws(error, options, data) {
const condition = options && options.hasOwnProperty('case') ? options.case : true;
if (condition) throw ensure(error, options, data);
function throws(fn, options, data) {
try {
return fn();
} catch (err) {
throw ensure(err, options, data);
}
}

@@ -169,3 +172,4 @@

_rejects = _asyncToGenerator(function* (error, options, data) {
return throws(error, options, data);
const condition = options && options.hasOwnProperty('case') ? options.case : true;
if (condition) throw ensure(error, options, data);
});

@@ -172,0 +176,0 @@ return _rejects.apply(this, arguments);

{
"name": "errorish",
"description": "For those times you have an error-ish but what you really want is an Error",
"version": "0.1.0",
"version": "0.2.0",
"license": "MIT",

@@ -39,50 +39,50 @@ "files": [

"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-decorators": "^7.4.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/preset-typescript": "^7.1.0",
"@pika/pack": "^0.3.7",
"@pika/plugin-build-node": "^0.3.14",
"@pika/plugin-build-web": "^0.3.14",
"@pika/plugin-standard-pkg": "^0.3.14",
"@types/jest": "^24.0.9",
"@typescript-eslint/eslint-plugin": "^1.6.0",
"@typescript-eslint/parser": "^1.6.0",
"@zerollup/ts-transform-paths": "^1.7.1",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.7.1",
"babel-plugin-module-resolver": "^3.1.1",
"commitizen": "^3.0.5",
"concurrently": "^4.1.0",
"conventional-changelog-cli": "^2.0.11",
"conventional-recommended-bump": "^4.1.1",
"coveralls": "^3.0.2",
"cross-env": "^5.2.0",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^5.16.0",
"eslint-config-prettier": "^4.0.0",
"eslint-config-standard": "^12.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"eslint-restricted-globals": "^0.2.0",
"@babel/cli": "7.4.3",
"@babel/core": "7.4.3",
"@babel/plugin-proposal-class-properties": "7.4.0",
"@babel/plugin-proposal-decorators": "7.4.0",
"@babel/plugin-proposal-object-rest-spread": "7.4.3",
"@babel/preset-env": "7.4.3",
"@babel/preset-typescript": "7.3.3",
"@pika/pack": "0.3.7",
"@pika/plugin-build-node": "0.3.14",
"@pika/plugin-build-web": "0.3.14",
"@pika/plugin-standard-pkg": "0.3.14",
"@types/jest": "24.0.11",
"@typescript-eslint/eslint-plugin": "1.6.0",
"@typescript-eslint/parser": "1.6.0",
"@zerollup/ts-transform-paths": "1.7.1",
"babel-eslint": "10.0.1",
"babel-jest": "24.7.1",
"babel-plugin-module-resolver": "3.2.0",
"commitizen": "3.0.7",
"concurrently": "4.1.0",
"conventional-changelog-cli": "2.0.12",
"conventional-recommended-bump": "4.1.1",
"coveralls": "3.0.3",
"cross-env": "5.2.0",
"cz-conventional-changelog": "2.1.0",
"eslint": "5.16.0",
"eslint-config-prettier": "4.1.0",
"eslint-config-standard": "12.0.0",
"eslint-import-resolver-alias": "1.1.2",
"eslint-plugin-babel": "5.3.0",
"eslint-plugin-import": "2.17.2",
"eslint-plugin-jest": "22.4.1",
"eslint-plugin-node": "8.0.1",
"eslint-plugin-prettier": "3.0.1",
"eslint-plugin-promise": "4.1.1",
"eslint-plugin-standard": "4.0.0",
"eslint-restricted-globals": "0.2.0",
"husky": "1.3.0",
"jake": "^8.1.1",
"jest-cli": "^24.7.1",
"markdownlint-cli": "^0.15.0",
"nps": "^5.9.3",
"onchange": "^5.2.0",
"prettier": "^1.17.0",
"shx": "^0.3.2",
"slimconf": "^0.9.0",
"ttypescript": "^1.5.6",
"typedoc": "^0.14.2",
"jake": "8.1.1",
"jest-cli": "24.7.1",
"markdownlint-cli": "0.15.0",
"nps": "5.9.5",
"onchange": "5.2.0",
"prettier": "1.17.0",
"shx": "0.3.2",
"slimconf": "0.9.0",
"ttypescript": "1.5.6",
"typedoc": "0.14.2",
"typescript": "^3.4.3"

@@ -89,0 +89,0 @@ },

@@ -11,5 +11,5 @@ # errorish

> For those times you have an error-*ish* but what you really want is an *Error*
> For those times you have an error-*ish* but what you really want is an *Error.*
If you come to find it useful, consider [starring the project](https://github.com/rafamel/errorish) and/or following [its author](https://github.com/rafamel) to show your ❤️
If you find it useful, consider [starring the project](https://github.com/rafamel/errorish) 💪 and/or following [its author](https://github.com/rafamel) ❤️ -there's more on the way!

@@ -37,4 +37,4 @@ ## Install

* [`normalize`](https://rafamel.github.io/errorish/globals.html#normalize) ensures an `Error` has a `message`, `name`, and `stack` properties -filling them if they're not defined.
* [`rejects`](https://rafamel.github.io/errorish/globals.html#rejects) parses a `help` string and returns an object with options, aliases, arguments, and descriptions.
* [`throws`](https://rafamel.github.io/errorish/globals.html#throws) parses a `help` string and returns an object with options, aliases, arguments, and descriptions.
* [`rejects`](https://rafamel.github.io/errorish/globals.html#rejects) returns a promise rejection with an error, having called `ensure` on it.
* [`throws`](https://rafamel.github.io/errorish/globals.html#throws) takes a function and returns its value if it doesn't throw; otherwise, it will call `ensure` on the thrown error and throw it.

@@ -76,4 +76,5 @@ [Options](https://rafamel.github.io/errorish/interfaces/icoreoptions.html) can be passed directly to these functions, though they will be merged in all cases with the [defaults](https://rafamel.github.io/errorish/globals.html#defaults) -you can use [`scope.set`](https://rafamel.github.io/errorish/globals.html#scope) to set these.

```javascript
import { rejects } from 'errorish';
import { rejects, throws, ensure } from 'errorish';
/* rejects */
Promise.reject(10).catch(rejects) // Reject<Errorish: An error occurred>

@@ -84,2 +85,14 @@

Promise.reject(10).catch(err => rejects(err, { case: false })); // Resolve<undefined>
/* throws */
throws(() => { throw 10; }); // Throw<Errorish: An error occurred>
// The above is equivalent to:
try {
throw 10;
} catch(err) {
throw ensure(err);
}
throws(() => 10); // Return<10>
```

@@ -86,0 +99,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