Socket
Socket
Sign inDemoInstall

@jsdevtools/ono

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsdevtools/ono - npm Package Compare versions

Comparing version 7.0.1 to 7.1.0

14

CHANGELOG.md

@@ -7,2 +7,13 @@ Change Log

[v7.1.0](https://github.com/JS-DevTools/ono/tree/v7.1.0) (2020-03-03)
----------------------------------------------------------------------------------------------------
- Added a static `Ono.extend()` method that allows Ono to extend errors that were created outside of Ono. The extended error gets all the Ono functionality, including nested stack traces, custom properties, improved support for `JSON.stringify()`, etc.
[Full Changelog](https://github.com/JS-DevTools/ono/compare/v7.0.1...v7.1.0)
[v7.0.0](https://github.com/JS-DevTools/ono/tree/v7.0.0) (2020-02-16)

@@ -19,2 +30,3 @@ ----------------------------------------------------------------------------------------------------

[v6.0.0](https://github.com/JS-DevTools/ono/tree/v6.0.0) (2019-12-28)

@@ -39,6 +51,6 @@ ----------------------------------------------------------------------------------------------------

[Full Changelog](https://github.com/JS-DevTools/ono/compare/v5.1.0...v6.0.0)
[v5.1.0](https://github.com/JS-DevTools/ono/tree/v5.1.0) (2019-09-10)

@@ -45,0 +57,0 @@ ----------------------------------------------------------------------------------------------------

32

cjs/constructor.js

@@ -9,9 +9,2 @@ "use strict";

/**
* Returns an object containing all properties of the given Error object,
* which can be used with `JSON.stringify()`.
*/
Ono.toJSON = function toJSON(error) {
return to_json_1.toJSON.call(error);
};
/**
* Creates an `Ono` instance for a specifc error type.

@@ -27,4 +20,3 @@ */

// Extend the error with the properties of the original error and the `props` object
extend_error_1.extendError(newError, originalError, props);
return newError;
return extend_error_1.extendError(newError, originalError, props);
}

@@ -34,2 +26,24 @@ ono[Symbol.species] = ErrorConstructor;

}
/**
* Returns an object containing all properties of the given Error object,
* which can be used with `JSON.stringify()`.
*/
Ono.toJSON = function toJSON(error) {
return to_json_1.toJSON.call(error);
};
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces,
* additional properties, and improved support for `JSON.stringify()`.
*/
Ono.extend = function extend(error, originalError, props) {
if (props || originalError instanceof Error) {
return extend_error_1.extendError(error, originalError, props);
}
else if (originalError) {
return extend_error_1.extendError(error, undefined, originalError);
}
else {
return extend_error_1.extendError(error);
}
};
//# sourceMappingURL=constructor.js.map

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

import { ErrorPOJO, OnoError } from "./types";
import { ErrorLike, OnoError } from "./types";
/**

@@ -9,2 +9,2 @@ * Extends the new error with the properties of the original error and the `props` object.

*/
export declare function extendError<T>(newError: OnoError<T>, originalError?: ErrorPOJO, props?: object): void;
export declare function extendError<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P): T & E & P & OnoError<T & E & P>;

@@ -14,14 +14,15 @@ "use strict";

*/
function extendError(newError, originalError, props) {
extendStack(newError, originalError);
function extendError(error, originalError, props) {
let onoError = error;
extendStack(onoError, originalError);
// Copy properties from the original error
if (originalError && typeof originalError === "object") {
mergeErrors(newError, originalError);
mergeErrors(onoError, originalError);
}
// The default `toJSON` method doesn't output props like `name`, `message`, `stack`, etc.
// So replace it with one that outputs every property of the error.
newError.toJSON = to_json_1.toJSON;
onoError.toJSON = to_json_1.toJSON;
// On Node.js, add support for the `util.inspect()` method
if (isomorphic_node_1.addInspectMethod) {
isomorphic_node_1.addInspectMethod(newError);
isomorphic_node_1.addInspectMethod(onoError);
}

@@ -31,4 +32,5 @@ // Finally, copy custom properties that were specified by the user.

if (props && typeof props === "object") {
Object.assign(newError, props);
Object.assign(onoError, props);
}
return onoError;
}

@@ -35,0 +37,0 @@ exports.extendError = extendError;

@@ -26,2 +26,34 @@ /// <reference types="node" />

toJSON<E extends ErrorLike>(error: E): ErrorPOJO & E;
/**
* Extends the given Error object with enhanced Ono functionality, such as improved support for
* `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
*/
extend<T extends ErrorLike>(error: T): T & OnoError<T>;
/**
* Extends the given Error object with enhanced Ono functionality, such as additional properties
* and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param props - An object whose properties will be added to the error
*/
extend<T extends ErrorLike, P extends object>(error: T, props?: P): T & P & OnoError<T & P>;
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces
* and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param originalError - The original error. This error's stack trace will be added to the error's stack trace.
*/
extend<T extends ErrorLike, E extends ErrorLike>(error: T, originalError?: E): T & E & OnoError<T & E>;
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces,
* additional properties, and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param originalError - The original error. This error's stack trace will be added to the error's stack trace.
* @param props - An object whose properties will be added to the error
*/
extend<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P): T & E & P & OnoError<T & E & P>;
}

@@ -28,0 +60,0 @@ /**

@@ -7,9 +7,2 @@ import { extendError } from "./extend-error";

/**
* Returns an object containing all properties of the given Error object,
* which can be used with `JSON.stringify()`.
*/
Ono.toJSON = function toJSON(error) {
return errorToJSON.call(error);
};
/**
* Creates an `Ono` instance for a specifc error type.

@@ -25,4 +18,3 @@ */

// Extend the error with the properties of the original error and the `props` object
extendError(newError, originalError, props);
return newError;
return extendError(newError, originalError, props);
}

@@ -32,2 +24,24 @@ ono[Symbol.species] = ErrorConstructor;

}
/**
* Returns an object containing all properties of the given Error object,
* which can be used with `JSON.stringify()`.
*/
Ono.toJSON = function toJSON(error) {
return errorToJSON.call(error);
};
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces,
* additional properties, and improved support for `JSON.stringify()`.
*/
Ono.extend = function extend(error, originalError, props) {
if (props || originalError instanceof Error) {
return extendError(error, originalError, props);
}
else if (originalError) {
return extendError(error, undefined, originalError);
}
else {
return extendError(error);
}
};
//# sourceMappingURL=constructor.js.map

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

import { ErrorPOJO, OnoError } from "./types";
import { ErrorLike, OnoError } from "./types";
/**

@@ -9,2 +9,2 @@ * Extends the new error with the properties of the original error and the `props` object.

*/
export declare function extendError<T>(newError: OnoError<T>, originalError?: ErrorPOJO, props?: object): void;
export declare function extendError<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P): T & E & P & OnoError<T & E & P>;

@@ -12,14 +12,15 @@ import { addInspectMethod } from "./isomorphic.node";

*/
export function extendError(newError, originalError, props) {
extendStack(newError, originalError);
export function extendError(error, originalError, props) {
let onoError = error;
extendStack(onoError, originalError);
// Copy properties from the original error
if (originalError && typeof originalError === "object") {
mergeErrors(newError, originalError);
mergeErrors(onoError, originalError);
}
// The default `toJSON` method doesn't output props like `name`, `message`, `stack`, etc.
// So replace it with one that outputs every property of the error.
newError.toJSON = toJSON;
onoError.toJSON = toJSON;
// On Node.js, add support for the `util.inspect()` method
if (addInspectMethod) {
addInspectMethod(newError);
addInspectMethod(onoError);
}

@@ -29,4 +30,5 @@ // Finally, copy custom properties that were specified by the user.

if (props && typeof props === "object") {
Object.assign(newError, props);
Object.assign(onoError, props);
}
return onoError;
}

@@ -33,0 +35,0 @@ /**

@@ -26,2 +26,34 @@ /// <reference types="node" />

toJSON<E extends ErrorLike>(error: E): ErrorPOJO & E;
/**
* Extends the given Error object with enhanced Ono functionality, such as improved support for
* `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
*/
extend<T extends ErrorLike>(error: T): T & OnoError<T>;
/**
* Extends the given Error object with enhanced Ono functionality, such as additional properties
* and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param props - An object whose properties will be added to the error
*/
extend<T extends ErrorLike, P extends object>(error: T, props?: P): T & P & OnoError<T & P>;
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces
* and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param originalError - The original error. This error's stack trace will be added to the error's stack trace.
*/
extend<T extends ErrorLike, E extends ErrorLike>(error: T, originalError?: E): T & E & OnoError<T & E>;
/**
* Extends the given Error object with enhanced Ono functionality, such as nested stack traces,
* additional properties, and improved support for `JSON.stringify()`.
*
* @param error - The error object to extend. This object instance will be modified and returned.
* @param originalError - The original error. This error's stack trace will be added to the error's stack trace.
* @param props - An object whose properties will be added to the error
*/
extend<T extends ErrorLike, E extends ErrorLike, P extends object>(error: T, originalError?: E, props?: P): T & E & P & OnoError<T & E & P>;
}

@@ -28,0 +60,0 @@ /**

{
"name": "@jsdevtools/ono",
"version": "7.0.1",
"version": "7.1.0",
"description": "Throw better errors.",

@@ -61,7 +61,7 @@ "keywords": [

"@jsdevtools/eslint-config-modular": "^8.0.0",
"@jsdevtools/host-environment": "^2.0.1",
"@jsdevtools/karma-config": "^3.1.1",
"@jsdevtools/host-environment": "^2.0.2",
"@jsdevtools/karma-config": "^3.1.2",
"@jsdevtools/tslint-modular": "^2.0.1",
"@jsdevtools/version-bump-prompt": "^6.0.0",
"@types/node": "^13.7.1",
"@jsdevtools/version-bump-prompt": "^6.0.1",
"@types/node": "^13.7.7",
"chai": "^4.2.0",

@@ -71,8 +71,8 @@ "eslint": "^6.8.0",

"karma-cli": "^2.0.0",
"mocha": "^7.0.1",
"npm-check": "^5.9.0",
"mocha": "^7.1.0",
"npm-check": "^5.9.2",
"nyc": "^15.0.0",
"shx": "^0.3.2",
"tslint": "^6.0.0",
"typescript": "^3.7.5",
"typescript": "^3.8.3",
"typescript-tslint-plugin": "^0.5.5"

@@ -79,0 +79,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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