Comparing version 3.1.1 to 4.0.0
@@ -6,2 +6,11 @@ # Change Log | ||
## [v4.0.0](https://github.com/BigstickCarpet/ono/tree/v4.0.0) (2017-07-07) | ||
The `err` parameter (see [the API docs](https://github.com/BigstickCarpet/ono#api)) can now be any type of object, not just an `instanceof Error`. This allows for errors that don't extend from the `Error` class, such as [`DOMError`](https://developer.mozilla.org/en-US/docs/Web/API/DOMError), [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException), and custom error types. | ||
> **NOTE:** This should **not** be a breaking change, but I'm bumping the major version number out of an abundance of caution. | ||
[Full Changelog](https://github.com/BigstickCarpet/ono/compare/v3.1.0...v4.0.0) | ||
## [v3.1.0](https://github.com/BigstickCarpet/ono/tree/v3.0.0) (2017-06-01) | ||
@@ -8,0 +17,0 @@ |
/*! | ||
* Ono v3.1.1 (June 13th 2017) | ||
* Ono v4.0.0 (July 7th 2017) | ||
* | ||
@@ -14,4 +14,5 @@ * https://github.com/bigstickcarpet/ono | ||
var slice = Array.prototype.slice; | ||
var vendorSpecificErrorProperties = [ | ||
'name', 'message', 'description', 'number', 'fileName', 'lineNumber', 'columnNumber', | ||
var protectedProperties = ['name', 'message', 'stack']; | ||
var errorPrototypeProperties = [ | ||
'name', 'message', 'description', 'number', 'code', 'fileName', 'lineNumber', 'columnNumber', | ||
'sourceURL', 'line', 'column', 'stack' | ||
@@ -45,24 +46,25 @@ ]; | ||
return function onoFactory (err, props, message, params) { // eslint-disable-line no-unused-vars | ||
var formattedMessage; | ||
var args = slice.call(arguments); | ||
var formatArgs = []; | ||
var formattedMessage = ''; | ||
// Separate the format arguments (message + props) from the rest of the arguments | ||
if (typeof err === 'string') { | ||
formattedMessage = module.exports.formatter.apply(null, arguments); | ||
formatArgs = args.splice(0, args.length); | ||
err = props = undefined; | ||
} | ||
else if (typeof props === 'string') { | ||
formattedMessage = module.exports.formatter.apply(null, slice.call(arguments, 1)); | ||
formatArgs = args.splice(1, args.length - 1); | ||
props = undefined; | ||
} | ||
else if (typeof message === 'string') { | ||
formattedMessage = module.exports.formatter.apply(null, slice.call(arguments, 2)); | ||
formatArgs = args.splice(2, args.length - 2); | ||
} | ||
else { | ||
formattedMessage = ''; | ||
} | ||
if (!(err instanceof Error)) { | ||
props = err; | ||
err = undefined; | ||
// If there are any format arguments, then format the error message | ||
if (formatArgs.length > 0) { | ||
formattedMessage = module.exports.formatter.apply(null, formatArgs); | ||
} | ||
if (err) { | ||
if (err && err.message) { | ||
// The inner-error's message will be added to the new message | ||
@@ -93,3 +95,3 @@ formattedMessage += (formattedMessage ? ' \n' : '') + err.message; | ||
extendStack(targetError, sourceError); | ||
extend(targetError, sourceError, true); | ||
extend(targetError, sourceError); | ||
} | ||
@@ -114,5 +116,4 @@ | ||
* @param {?source} source - The object whose properties are copied | ||
* @param {boolean} omitVendorSpecificProperties - Skip vendor-specific Error properties | ||
*/ | ||
function extend (target, source, omitVendorSpecificProperties) { | ||
function extend (target, source) { | ||
if (source && typeof source === 'object') { | ||
@@ -123,4 +124,5 @@ var keys = Object.keys(source); | ||
// Don't bother trying to copy read-only vendor-specific Error properties | ||
if (omitVendorSpecificProperties && vendorSpecificErrorProperties.indexOf(key) >= 0) { | ||
// Don't copy "protected" properties, since they have special meaning/behavior | ||
// and are set by the onoFactory function | ||
if (protectedProperties.indexOf(key) >= 0) { | ||
continue; | ||
@@ -151,4 +153,4 @@ } | ||
// Also include vendor-specific properties from the prototype | ||
keys = keys.concat(vendorSpecificErrorProperties); | ||
// Also include properties from the Error prototype | ||
keys = keys.concat(errorPrototypeProperties); | ||
@@ -155,0 +157,0 @@ for (var i = 0; i < keys.length; i++) { |
/*! | ||
* Ono v3.1.1 (June 13th 2017) | ||
* Ono v4.0.0 (July 7th 2017) | ||
* | ||
@@ -9,3 +9,3 @@ * https://github.com/bigstickcarpet/ono | ||
*/ | ||
(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.ono=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";function create(e){return function(r,t,o,n){var a;"string"==typeof r?(a=module.exports.formatter.apply(null,arguments),r=t=void 0):a="string"==typeof t?module.exports.formatter.apply(null,slice.call(arguments,1)):"string"==typeof o?module.exports.formatter.apply(null,slice.call(arguments,2)):"",r instanceof Error||(t=r,r=void 0),r&&(a+=(a?" \n":"")+r.message);var c=new e(a);return extendError(c,r),extendToJSON(c),extend(c,t),c}}function extendError(e,r){extendStack(e,r),extend(e,r,!0)}function extendToJSON(e){e.toJSON=errorToJSON,e.inspect=errorToString}function extend(e,r,t){if(r&&"object"==typeof r)for(var o=Object.keys(r),n=0;n<o.length;n++){var a=o[n];if(!(t&&vendorSpecificErrorProperties.indexOf(a)>=0))try{e[a]=r[a]}catch(e){}}}function errorToJSON(){var e={},r=Object.keys(this);r=r.concat(vendorSpecificErrorProperties);for(var t=0;t<r.length;t++){var o=r[t],n=this[o],a=typeof n;"undefined"!==a&&"function"!==a&&(e[o]=n)}return e}function errorToString(){return JSON.stringify(this,null,2).replace(/\\n/g,"\n")}function extendStack(e,r){hasLazyStack(e)?r?lazyJoinStacks(e,r):lazyPopStack(e):e.stack=r?joinStacks(e.stack,r.stack):popStack(e.stack)}function joinStacks(e,r){return e=popStack(e),e&&r?e+"\n\n"+r:e||r}function popStack(e){if(e){var r=e.split("\n");if(r.length<2)return e;for(var t=0;t<r.length;t++){if(r[t].indexOf("onoFactory")>=0)return r.splice(t,1),r.join("\n")}return e}}function hasLazyStack(e){if(!supportsLazyStack)return!1;var r=Object.getOwnPropertyDescriptor(e,"stack");return!!r&&"function"==typeof r.get}function lazyJoinStacks(e,r){var t=Object.getOwnPropertyDescriptor(e,"stack");Object.defineProperty(e,"stack",{get:function(){return joinStacks(t.get.apply(e),r.stack)},enumerable:!1,configurable:!0})}function lazyPopStack(e){var r=Object.getOwnPropertyDescriptor(e,"stack");Object.defineProperty(e,"stack",{get:function(){return popStack(r.get.apply(e))},enumerable:!1,configurable:!0})}var format=require("format-util"),slice=Array.prototype.slice,vendorSpecificErrorProperties=["name","message","description","number","fileName","lineNumber","columnNumber","sourceURL","line","column","stack"];module.exports=create(Error),module.exports.error=create(Error),module.exports.eval=create(EvalError),module.exports.range=create(RangeError),module.exports.reference=create(ReferenceError),module.exports.syntax=create(SyntaxError),module.exports.type=create(TypeError),module.exports.uri=create(URIError),module.exports.formatter=format;var supportsLazyStack=function(){return!(!Object.getOwnPropertyDescriptor||!Object.defineProperty||"undefined"!=typeof navigator&&/Android/.test(navigator.userAgent))}()},{"format-util":2}],2:[function(require,module,exports){function format(e){var r=/(%?)(%([jds]))/g,t=Array.prototype.slice.call(arguments,1);return t.length&&(e=e.replace(r,function(e,r,a,n){var s=t.shift();switch(n){case"s":s=""+s;break;case"d":s=Number(s);break;case"j":s=JSON.stringify(s)}return r?(t.unshift(s),e):s})),t.length&&(e+=" "+t.join(" ")),""+(e=e.replace(/%{2,2}/g,"%"))}module.exports=format},{}]},{},[1])(1)}); | ||
(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.ono=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";function create(e){return function(r,t,o,n){var a=slice.call(arguments),c=[],i="";"string"==typeof r?(c=a.splice(0,a.length),r=t=void 0):"string"==typeof t?(c=a.splice(1,a.length-1),t=void 0):"string"==typeof o&&(c=a.splice(2,a.length-2)),c.length>0&&(i=module.exports.formatter.apply(null,c)),r&&r.message&&(i+=(i?" \n":"")+r.message);var s=new e(i);return extendError(s,r),extendToJSON(s),extend(s,t),s}}function extendError(e,r){extendStack(e,r),extend(e,r)}function extendToJSON(e){e.toJSON=errorToJSON,e.inspect=errorToString}function extend(e,r){if(r&&"object"==typeof r)for(var t=Object.keys(r),o=0;o<t.length;o++){var n=t[o];if(!(protectedProperties.indexOf(n)>=0))try{e[n]=r[n]}catch(e){}}}function errorToJSON(){var e={},r=Object.keys(this);r=r.concat(errorPrototypeProperties);for(var t=0;t<r.length;t++){var o=r[t],n=this[o],a=typeof n;"undefined"!==a&&"function"!==a&&(e[o]=n)}return e}function errorToString(){return JSON.stringify(this,null,2).replace(/\\n/g,"\n")}function extendStack(e,r){hasLazyStack(e)?r?lazyJoinStacks(e,r):lazyPopStack(e):e.stack=r?joinStacks(e.stack,r.stack):popStack(e.stack)}function joinStacks(e,r){return e=popStack(e),e&&r?e+"\n\n"+r:e||r}function popStack(e){if(e){var r=e.split("\n");if(r.length<2)return e;for(var t=0;t<r.length;t++){if(r[t].indexOf("onoFactory")>=0)return r.splice(t,1),r.join("\n")}return e}}function hasLazyStack(e){if(!supportsLazyStack)return!1;var r=Object.getOwnPropertyDescriptor(e,"stack");return!!r&&"function"==typeof r.get}function lazyJoinStacks(e,r){var t=Object.getOwnPropertyDescriptor(e,"stack");Object.defineProperty(e,"stack",{get:function(){return joinStacks(t.get.apply(e),r.stack)},enumerable:!1,configurable:!0})}function lazyPopStack(e){var r=Object.getOwnPropertyDescriptor(e,"stack");Object.defineProperty(e,"stack",{get:function(){return popStack(r.get.apply(e))},enumerable:!1,configurable:!0})}var format=require("format-util"),slice=Array.prototype.slice,protectedProperties=["name","message","stack"],errorPrototypeProperties=["name","message","description","number","code","fileName","lineNumber","columnNumber","sourceURL","line","column","stack"];module.exports=create(Error),module.exports.error=create(Error),module.exports.eval=create(EvalError),module.exports.range=create(RangeError),module.exports.reference=create(ReferenceError),module.exports.syntax=create(SyntaxError),module.exports.type=create(TypeError),module.exports.uri=create(URIError),module.exports.formatter=format;var supportsLazyStack=function(){return!(!Object.getOwnPropertyDescriptor||!Object.defineProperty||"undefined"!=typeof navigator&&/Android/.test(navigator.userAgent))}()},{"format-util":2}],2:[function(require,module,exports){function format(e){var r=/(%?)(%([jds]))/g,t=Array.prototype.slice.call(arguments,1);return t.length&&(e=e.replace(r,function(e,r,a,n){var s=t.shift();switch(n){case"s":s=""+s;break;case"d":s=Number(s);break;case"j":s=JSON.stringify(s)}return r?(t.unshift(s),e):s})),t.length&&(e+=" "+t.join(" ")),""+(e=e.replace(/%{2,2}/g,"%"))}module.exports=format},{}]},{},[1])(1)}); | ||
//# sourceMappingURL=ono.min.js.map |
@@ -5,4 +5,5 @@ 'use strict'; | ||
var slice = Array.prototype.slice; | ||
var vendorSpecificErrorProperties = [ | ||
'name', 'message', 'description', 'number', 'fileName', 'lineNumber', 'columnNumber', | ||
var protectedProperties = ['name', 'message', 'stack']; | ||
var errorPrototypeProperties = [ | ||
'name', 'message', 'description', 'number', 'code', 'fileName', 'lineNumber', 'columnNumber', | ||
'sourceURL', 'line', 'column', 'stack' | ||
@@ -36,24 +37,25 @@ ]; | ||
return function onoFactory (err, props, message, params) { // eslint-disable-line no-unused-vars | ||
var formattedMessage; | ||
var args = slice.call(arguments); | ||
var formatArgs = []; | ||
var formattedMessage = ''; | ||
// Separate the format arguments (message + props) from the rest of the arguments | ||
if (typeof err === 'string') { | ||
formattedMessage = module.exports.formatter.apply(null, arguments); | ||
formatArgs = args.splice(0, args.length); | ||
err = props = undefined; | ||
} | ||
else if (typeof props === 'string') { | ||
formattedMessage = module.exports.formatter.apply(null, slice.call(arguments, 1)); | ||
formatArgs = args.splice(1, args.length - 1); | ||
props = undefined; | ||
} | ||
else if (typeof message === 'string') { | ||
formattedMessage = module.exports.formatter.apply(null, slice.call(arguments, 2)); | ||
formatArgs = args.splice(2, args.length - 2); | ||
} | ||
else { | ||
formattedMessage = ''; | ||
} | ||
if (!(err instanceof Error)) { | ||
props = err; | ||
err = undefined; | ||
// If there are any format arguments, then format the error message | ||
if (formatArgs.length > 0) { | ||
formattedMessage = module.exports.formatter.apply(null, formatArgs); | ||
} | ||
if (err) { | ||
if (err && err.message) { | ||
// The inner-error's message will be added to the new message | ||
@@ -84,3 +86,3 @@ formattedMessage += (formattedMessage ? ' \n' : '') + err.message; | ||
extendStack(targetError, sourceError); | ||
extend(targetError, sourceError, true); | ||
extend(targetError, sourceError); | ||
} | ||
@@ -105,5 +107,4 @@ | ||
* @param {?source} source - The object whose properties are copied | ||
* @param {boolean} omitVendorSpecificProperties - Skip vendor-specific Error properties | ||
*/ | ||
function extend (target, source, omitVendorSpecificProperties) { | ||
function extend (target, source) { | ||
if (source && typeof source === 'object') { | ||
@@ -114,4 +115,5 @@ var keys = Object.keys(source); | ||
// Don't bother trying to copy read-only vendor-specific Error properties | ||
if (omitVendorSpecificProperties && vendorSpecificErrorProperties.indexOf(key) >= 0) { | ||
// Don't copy "protected" properties, since they have special meaning/behavior | ||
// and are set by the onoFactory function | ||
if (protectedProperties.indexOf(key) >= 0) { | ||
continue; | ||
@@ -142,4 +144,4 @@ } | ||
// Also include vendor-specific properties from the prototype | ||
keys = keys.concat(vendorSpecificErrorProperties); | ||
// Also include properties from the Error prototype | ||
keys = keys.concat(errorPrototypeProperties); | ||
@@ -146,0 +148,0 @@ for (var i = 0; i < keys.length; i++) { |
{ | ||
"name": "ono", | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"description": "Throw better errors.", | ||
@@ -48,3 +48,3 @@ "keywords": [ | ||
"coveralls": "^2.13.1", | ||
"eslint": "^4.0.0", | ||
"eslint": "^4.1.1", | ||
"eslint-config-modular": "^4.1.0", | ||
@@ -54,3 +54,3 @@ "istanbul": "^0.4.2", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^2.1.1", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-cli": "^1.0.1", | ||
@@ -57,0 +57,0 @@ "karma-coverage": "^1.1.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62837
605