diff --git a/eraro.js b/eraro.js index 6c0fd8d..a47e4b6 100644 --- a/eraro.js +++ b/eraro.js @@ -48,9 +48,9 @@ function eraro(options) { var msgprefix = false === options.prefix ? '' - : 'string' === typeof(options.prefix) + : 'string' === typeof options.prefix ? options.prefix - : 'string' === typeof(options.package) + : 'string' === typeof options.package ? options.package + ': ' : '' @@ -77,23 +77,25 @@ function eraro(options) { details = arguments[2] } - code = 'string' === typeof(code) - ? code - : ex - ? ex.code + code = + 'string' === typeof code + ? code + : ex ? ex.code - : ex.message - ? ex.message + ? ex.code + : ex.message + ? ex.message + : 'unknown' : 'unknown' - : 'unknown' - details = 'object' === typeof(details) - ? details - : 'object' === typeof(msg) && 'string' !== typeof(msg) - ? msg - : {} + details = + 'object' === typeof details + ? details + : 'object' === typeof msg && 'string' !== typeof msg + ? msg + : {} - msg = 'string' === typeof(msg) ? msg : null + msg = 'string' === typeof msg ? msg : null msg = buildmessage( options, msg, @@ -165,7 +167,7 @@ function callpoint(error, markers) { var found = false for (var j = 0; j < markers.length; j++) { - if ('string' === typeof(markers[j])) { + if ('string' === typeof markers[j]) { found = -1 != line.indexOf(markers[j]) if (found) break } @@ -174,7 +176,7 @@ function callpoint(error, markers) { if (!found) break line_loop } - out = 'string' === typeof(lines[i]) ? lines[i].substring(4) : out + out = 'string' === typeof lines[i] ? lines[i].substring(4) : out } return out @@ -208,9 +210,9 @@ function buildmessage( ) { var message = msgprefix + - ('string' === typeof(msg) + ('string' === typeof msg ? msg - : 'string' === typeof(msgmap[code]) + : 'string' === typeof msgmap[code] ? msgmap[code] : ex ? originalmsg(options.override, ex) @@ -237,7 +239,8 @@ function buildmessage( if ({ undefined: 1, NaN: 1 }[key]) { key = key + '$' } - valstrmap[key] = inspect && 'string' !== typeof(val) ? Util.inspect(val) : val + valstrmap[key] = + inspect && 'string' !== typeof val ? Util.inspect(val) : val }) var done = false diff --git a/package.json b/package.json index cb4ac7d..f4c9251 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eraro", - "version": "1.1.0", + "version": "2.0.0", "description": "Create JavaScript Error objects with code strings, context details, and templated messages.", "main": "eraro.js", "scripts": { diff --git a/test/eraro.test.js b/test/eraro.test.js index 12a78ba..5410a78 100644 --- a/test/eraro.test.js +++ b/test/eraro.test.js @@ -36,7 +36,6 @@ describe('eraro', function() { expect(e1.foo).to.be.true() expect(e1.code).to.equal('c1') expect(e1.details.a).to.equal(1) - }) it('has', async () => { @@ -130,7 +129,6 @@ describe('eraro', function() { details: { orig$: err, message$: 'x11' } }) expect(erraror.orig).to.equal(err) - }) it('defined prefix', async () => { @@ -144,7 +142,6 @@ describe('eraro', function() { msg: 'foo: x2', details: { a: 3, orig$: err, message$: 'x2' } }) // [Error: x2] - }) }) @@ -157,7 +154,6 @@ describe('eraro', function() { var templatedError = eraro('i0', '<%=a%>', { a: { b: 99 } }) expect(templatedError.message).to.equal('foo: { b: 99 }') - }) it('handle different erraros', async () => { @@ -166,6 +162,5 @@ describe('eraro', function() { var barEraro = Eraro({ package: 'bar', prefix: false }) expect(barEraro('code1').message).to.equal('code1') - }) })