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

eraro

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eraro - npm Package Compare versions

Comparing version 2.1.0 to 3.0.1

128

eraro.js

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

/* Copyright (c) 2014-2018 Richard Rodger, MIT License */
/* Copyright (c) 2014-2023 Richard Rodger, MIT License */
/* jshint node:true, asi:true, eqnull:true */

@@ -11,5 +11,2 @@

// #### External modules
var Template = require('lodash.template')
// #### Exports

@@ -49,3 +46,3 @@ module.exports = eraro

var msgprefix =
const msgprefix =
false === options.prefix

@@ -59,15 +56,19 @@ ? ''

var packaje = options.package || 'unknown'
var callmodule = options.module || module
var msgmap = options.msgmap || {}
var inspect = null == options.inspect ? true : !!options.inspect
const pkg = options.package || 'unknown'
const callmodule = options.module || module
const msgmap = options.msgmap || {}
const inspect = null == options.inspect ? true : !!options.inspect
var markers = [module.filename]
const markers = [module.filename]
var filename = callmodule.filename
if (filename) markers.push(filename)
const filename = callmodule.filename
if (filename) {
markers.push(filename)
}
var errormaker = function(ex, code, msg, details) {
const errormaker = function (ex, code, msg, details) {
if (Util.isError(ex)) {
if (ex.eraro && !options.override) return ex
if (ex.eraro && !options.override) {
return ex
}
} else {

@@ -92,7 +93,3 @@ ex = null

details =
'object' === typeof details
? details
: 'object' === typeof msg && 'string' !== typeof msg
? msg
: {}
'object' === typeof details ? details : 'object' === typeof msg ? msg : {}

@@ -113,6 +110,6 @@ if (ex) {

details,
ex
ex,
)
var err = new Error(msg)
const err = new Error(msg)

@@ -125,3 +122,3 @@ if (ex) {

// drag along properties from original exception
for (var p in ex) {
for (const p in ex) {
err[p] = ex[p]

@@ -135,4 +132,4 @@ }

err.code = code
err[packaje] = true
err.package = packaje
err[pkg] = true
err.package = pkg
err.msg = msg

@@ -149,3 +146,3 @@ err.details = details

errormaker.has = function(code) {
errormaker.has = function (code) {
return !!msgmap[code]

@@ -167,14 +164,14 @@ }

var stack = error ? error.stack : null
var out = ''
const stack = error ? error.stack : null
let out = ''
if (stack) {
var lines = stack.split('\n')
var i
const lines = stack.split('\n')
let i = 0
line_loop: for (i = 1; i < lines.length; i++) {
var line = lines[i]
const line = lines[i]
var found = false
for (var j = 0; j < markers.length; j++) {
let found = false
for (let j = 0; j < markers.length; j++) {
if ('string' === typeof markers[j]) {

@@ -216,8 +213,8 @@ found = -1 != line.indexOf(markers[j])

msgprefix,
inspect,
_inspect,
code,
details,
ex
ex,
) {
var message =
let message =
msgprefix +

@@ -233,55 +230,22 @@ ('string' === typeof msg

// These are the inserts.
var valmap = Object.assign({}, details, { code: code })
let valmap = Object.assign({}, details, { code: code })
// TODO: is this needed anymore with _ removed?
// Workaround to prevent underscore blowing up if properties are not
// found. Reserved words and undefined need to be suffixed with $
// in the template interpolates.
message = message.replace(/<%=\s*(.*?)\s*%>/g, (m, p1) => {
let val = valmap[p1]
val = 'object' === typeof val && null != val ? stringify(val) : val
var valstrmap = { util: Util }
Object.entries(valmap).forEach(function(entry) {
var key = entry[0]
var val = entry[1]
try {
eval('var ' + key + ';')
} catch (e) {
key = key + '$'
}
if ({ undefined: 1, NaN: 1 }[key]) {
key = key + '$'
}
valstrmap[key] =
inspect && 'string' !== typeof val ? Util.inspect(val) : val
return val
})
var done = false
while (!done) {
try {
var tm = Template(message)
message = tm(valstrmap)
done = true
} catch (e) {
if (e instanceof ReferenceError) {
var m = /ReferenceError:\s+(.*?)\s+/.exec(e.toString())
if (m && m[1]) {
valstrmap[m[1]] = '[' + m[1] + '?]'
} else done = true
}
return message
}
// Some other error - give up and just dump the properties at
// the end of the template.
else {
done = true
message =
message +
' VALUES:' +
Util.inspect(valmap, { depth: 2 }) +
' TEMPLATE ERROR: ' +
e
}
}
function stringify(val) {
try {
return JSON.stringify(val)
.substring(0, 111)
.replace(/([^\\])"/g, '$1')
} catch (e) {
return '' + val
}
return message
}

@@ -288,0 +252,0 @@

{
"name": "eraro",
"version": "2.1.0",
"version": "3.0.1",
"description": "Create JavaScript Error objects with code strings, context details, and templated messages.",
"main": "eraro.js",
"scripts": {
"test": "lab -L -v -P test -t 80",
"coveralls": "lab -s -P test -r lcov -I URL,URLSearchParams | coveralls",
"prettier": "prettier --write --no-semi --single-quote *.js lib/*.js test/*.js",
"test": "jest --coverage",
"test-some": "jest -t",
"test-watch": "jest --coverage --watchAll",
"prettier": "prettier --write --no-semi --single-quote *.js test/*.js",
"clean": "rm -rf node_modules package-lock.json yarn.lock",
"reset": "npm run clean && npm i && npm test",
"reset": "npm run clean && npm i && npm test && npm audit --production",
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
"repo-publish": "npm run prettier && npm test && npm run repo-tag --registry http://registry.npmjs.org && npm publish --registry http://registry.npmjs.org "
"repo-publish": "npm run reset && npm run repo-publish-quick",
"repo-publish-quick": "npm run prettier && npm test && npm run repo-tag --registry http://registry.npmjs.org && npm publish --registry https://registry.npmjs.org "
},

@@ -33,5 +35,2 @@ "repository": {

"homepage": "https://github.com/rjrodger/eraro",
"dependencies": {
"lodash.template": "^4.5.0"
},
"files": [

@@ -43,7 +42,6 @@ "README.md",

"devDependencies": {
"@hapi/lab": "^21.0.0",
"@hapi/code": "^8.0.1",
"coveralls": "^3.0.9",
"prettier": "^1.19.1"
"jest": "^29.7.0",
"coveralls": "^3.1.1",
"prettier": "^3.0.3"
}
}

@@ -5,6 +5,9 @@ eraro

[![npm version][npm-badge]][npm-url]
[![Build Status][travis-badge]][travis-url]
[![build](https://github.com/rjrodger/eraro/actions/workflows/build.yml/badge.svg)](https://github.com/rjrodger/eraro/actions/workflows/build.yml)
[![Coverage Status][coveralls-badge]][coveralls-url]
[![Dependency Status][david-badge]][david-url]
[![DeepScan grade](https://deepscan.io/api/teams/5016/projects/25452/branches/796922/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5016&pid=25452&bid=796922)
[![Maintainability](https://api.codeclimate.com/v1/badges/d07c5eb44d302778bc18/maintainability)](https://codeclimate.com/github/rjrodger/eraro/maintainability)
#### Create JavaScript Error objects with code strings, context details, and templated messages.

@@ -11,0 +14,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