check-error
Advanced tools
Comparing version 1.0.2 to 2.0.0
67
index.js
@@ -1,18 +0,2 @@ | ||
'use strict'; | ||
/* ! | ||
* Chai - checkError utility | ||
* Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
/** | ||
* ### .checkError | ||
* | ||
* Checks that an error conforms to a given set of criteria and/or retrieves information about it. | ||
* | ||
* @api public | ||
*/ | ||
/** | ||
* ### .compatibleInstance(thrown, errorLike) | ||
@@ -78,3 +62,3 @@ * | ||
function compatibleMessage(thrown, errMatcher) { | ||
var comparisonString = typeof thrown === 'string' ? thrown : thrown.message; | ||
const comparisonString = typeof thrown === 'string' ? thrown : thrown.message; | ||
if (errMatcher instanceof RegExp) { | ||
@@ -90,30 +74,2 @@ return errMatcher.test(comparisonString); | ||
/** | ||
* ### .getFunctionName(constructorFn) | ||
* | ||
* Returns the name of a function. | ||
* This also includes a polyfill function if `constructorFn.name` is not defined. | ||
* | ||
* @name getFunctionName | ||
* @param {Function} constructorFn | ||
* @namespace Utils | ||
* @api private | ||
*/ | ||
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\(\/]+)/; | ||
function getFunctionName(constructorFn) { | ||
var name = ''; | ||
if (typeof constructorFn.name === 'undefined') { | ||
// Here we run a polyfill if constructorFn.name is not defined | ||
var match = String(constructorFn).match(functionNameMatch); | ||
if (match) { | ||
name = match[1]; | ||
} | ||
} else { | ||
name = constructorFn.name; | ||
} | ||
return name; | ||
} | ||
/** | ||
* ### .getConstructorName(errorLike) | ||
@@ -130,5 +86,5 @@ * | ||
function getConstructorName(errorLike) { | ||
var constructorName = errorLike; | ||
let constructorName = errorLike; | ||
if (errorLike instanceof Error) { | ||
constructorName = getFunctionName(errorLike.constructor); | ||
constructorName = errorLike.constructor.name; | ||
} else if (typeof errorLike === 'function') { | ||
@@ -138,4 +94,7 @@ // If `err` is not an instance of Error it is an error constructor itself or another function. | ||
// of the error just in case it's a poorly-constructed error. Please see chaijs/chai/issues/45 to know more. | ||
constructorName = getFunctionName(errorLike).trim() || | ||
getFunctionName(new errorLike()); // eslint-disable-line new-cap | ||
constructorName = errorLike.name; | ||
if (constructorName === '') { | ||
const newConstructorName = (new errorLike().name); // eslint-disable-line new-cap | ||
constructorName = newConstructorName || constructorName; | ||
} | ||
} | ||
@@ -160,3 +119,3 @@ | ||
function getMessage(errorLike) { | ||
var msg = ''; | ||
let msg = ''; | ||
if (errorLike && errorLike.message) { | ||
@@ -171,8 +130,2 @@ msg = errorLike.message; | ||
module.exports = { | ||
compatibleInstance: compatibleInstance, | ||
compatibleConstructor: compatibleConstructor, | ||
compatibleMessage: compatibleMessage, | ||
getMessage: getMessage, | ||
getConstructorName: getConstructorName, | ||
}; | ||
export { compatibleInstance, compatibleConstructor, compatibleMessage, getMessage, getConstructorName }; |
@@ -21,3 +21,5 @@ { | ||
], | ||
"type": "module", | ||
"main": "./index.js", | ||
"module": "./index.js", | ||
"repository": { | ||
@@ -28,11 +30,10 @@ "type": "git", | ||
"scripts": { | ||
"build": "browserify --bare $npm_package_main --standalone checkError -o check-error.js", | ||
"lint": "eslint --ignore-path .gitignore .", | ||
"build": "rollup -c rollup.config.js", | ||
"lint": "eslint --ignore-path .gitignore index.js test/", | ||
"prepublish": "npm run build", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post", | ||
"pretest": "npm run lint", | ||
"test": "npm run test:node && npm run test:browser && npm run upload-coverage", | ||
"test:browser": "karma start --singleRun=true", | ||
"test:node": "istanbul cover _mocha", | ||
"upload-coverage": "lcov-result-merger 'coverage/**/lcov.info' | coveralls; exit 0" | ||
"pretest": "npm run lint && npm run build", | ||
"test": "npm run test:node && npm run test:browser", | ||
"test:browser": "web-test-runner --node-resolve test/", | ||
"test:node": "mocha" | ||
}, | ||
@@ -46,3 +47,3 @@ "config": { | ||
"extends": [ | ||
"strict/es5" | ||
"strict/es6" | ||
], | ||
@@ -56,11 +57,13 @@ "env": { | ||
"rules": { | ||
"complexity": 0, | ||
"max-statements": 0 | ||
"complexity": "off", | ||
"max-statements": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^21.0.0", | ||
"@rollup/plugin-node-resolve": "^13.0.5", | ||
"@web/test-runner": "^0.17.0", | ||
"browserify": "^13.0.0", | ||
"browserify-istanbul": "^1.0.0", | ||
"coveralls": "2.11.9", | ||
"eslint": "^2.4.0", | ||
@@ -70,21 +73,12 @@ "eslint-config-strict": "^8.5.0", | ||
"ghooks": "^1.0.1", | ||
"istanbul": "^0.4.2", | ||
"karma": "^0.13.22", | ||
"karma-browserify": "^5.0.2", | ||
"karma-coverage": "^0.5.5", | ||
"karma-mocha": "^0.2.2", | ||
"karma-phantomjs-launcher": "^1.0.0", | ||
"karma-sauce-launcher": "^0.3.1", | ||
"lcov-result-merger": "^1.0.2", | ||
"mocha": "^2.4.5", | ||
"phantomjs-prebuilt": "^2.1.5", | ||
"mocha": "^9.1.2", | ||
"rollup": "^2.58.0", | ||
"semantic-release": "^4.3.5", | ||
"simple-assert": "^1.0.0", | ||
"travis-after-all": "^1.4.4", | ||
"simple-assert": "^2.0.0", | ||
"validate-commit-msg": "^2.3.1" | ||
}, | ||
"engines": { | ||
"node": "*" | ||
"node": ">= 16" | ||
}, | ||
"version": "1.0.2" | ||
} | ||
"version": "2.0.0" | ||
} |
@@ -24,8 +24,5 @@ <h1 align=center> | ||
</a> | ||
<a href="https://travis-ci.org/chaijs/check-error"> | ||
<img | ||
alt="build:?" | ||
src="https://img.shields.io/travis/chaijs/check-error/master.svg?style=flat-square" | ||
/> | ||
</a> | ||
![example workflow](https://github.com/chaijs/check-error/actions/workflows/nodejs.yml/badge.svg) | ||
<a href="https://coveralls.io/r/chaijs/check-error"> | ||
@@ -32,0 +29,0 @@ <img |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
14
0
Yes
13017
4
111
205
1