{"name":"check-error","description":"Error comparison and information related utility for node and the browser","keywords":["check-error","error","chai util"],"license":"MIT","author":{"name":"Jake Luer","email":"jake@alogicalparadox.com","url":"http://alogicalparadox.com"},"contributors":[{"name":"David Losert","url":"https://github.com/davelosert"},{"name":"Keith Cirkel","url":"https://github.com/keithamus"},{"name":"Miroslav Bajtoš","url":"https://github.com/bajtos"},{"name":"Lucas Fernandes da Costa","url":"https://github.com/lucasfcosta"}],"type":"module","main":"./index.js","module":"./index.js","repository":{"type":"git","url":"git+ssh://git@github.com/chaijs/check-error.git"},"scripts":{"lint":"eslint index.js test/","pretest":"npm run lint","test":"npm run test:node && npm run test:browser","test:browser":"web-test-runner","test:node":"mocha"},"devDependencies":{"@eslint/js":"^9.31.0","@web/test-runner":"^0.20.2","eslint":"^9.31.0","mocha":"^11.7.1","simple-assert":"^2.0.0"},"engines":{"node":">= 16"},"version":"2.1.3","gitHead":"fc30ec40ec6e0702935cecbdf68d4f3fd2a657eb","_id":"check-error@2.1.3","bugs":{"url":"https://github.com/chaijs/check-error/issues"},"homepage":"https://github.com/chaijs/check-error#readme","_nodeVersion":"22.21.1","_npmVersion":"11.7.0","dist":{"integrity":"sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA==","shasum":"2427361117b70cca8dc89680ead32b157019caf5","tarball":"http://registry-npm.ywwl.com/check-error/download/check-error-2.1.3.tgz","fileCount":4,"unpackedSize":10615,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/check-error@2.1.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC7SNHqfnflWp9VreCnvCj2Qf5de3C+bwqnNRuDH4mBzwIhAOZtNVDVQG+d3sNV22RLo9aR/V2snXFjJBRBPgHVGnkW"}],"size":3446,"noattachment":false,"key":"/check-error/-/check-error-2.1.3.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:ab333f9d-b74e-45f1-b36f-f49b4902618c"}},"directories":{},"maintainers":[{"name":"chaijs","email":"chaijs@keithcirkel.co.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/check-error_2.1.3_1767454609281_0.977477258168385"},"_hasShrinkwrap":false,"readme":"<h1 align=center>\n  <a href=\"http://chaijs.com\" title=\"Chai Documentation\">\n    <img alt=\"ChaiJS\" src=\"http://chaijs.com/img/chai-logo.png\">\n  </a>\n  <br>\n  check-error\n</h1>\n\n<p align=center>\n  Error comparison and information related utility for <a href=\"http://nodejs.org\">node</a> and the browser.\n</p>\n\n## What is Check-Error?\n\nCheck-Error is a module which you can use to retrieve an Error's information such as its `message` or `constructor` name and also to check whether two Errors are compatible based on their messages, constructors or even instances.\n\n## Installation\n\n### Node.js\n\n`check-error` is available on [npm](http://npmjs.org). To install it, type:\n\n    $ npm install check-error\n\n### Browsers\n\nYou can also use it within the browser; install via npm and use the `check-error.js` file found within the download. For example:\n\n```html\n<script src=\"./node_modules/check-error/check-error.js\"></script>\n```\n\n## Usage\n\nThe primary export of `check-error` is an object which has the following methods:\n\n* `compatibleInstance(err, errorLike)` - Checks if an error is compatible with another `errorLike` object. If `errorLike` is an error instance we do a strict comparison, otherwise we return `false` by default, because instances of objects can only be compatible if they're both error instances.\n* `compatibleConstructor(err, errorLike)` - Checks if an error's constructor is compatible with another `errorLike` object. If `err` has the same constructor as `errorLike` or if `err` is an instance of `errorLike`.\n* `compatibleMessage(err, errMatcher)` - Checks if an error message is compatible with an `errMatcher` RegExp or String (we check if the message contains the String).\n* `getConstructorName(errorLike)` - Retrieves the name of a constructor, an error's constructor or `errorLike` itself if it's not an error instance or constructor.\n* `getMessage(err)` - Retrieves the message of an error or `err` itself if it's a String. If `err` or `err.message` is undefined we return an empty String.\n\n```js\nimport * as checkError 'check-error';\n```\n\n#### .compatibleInstance(err, errorLike)\n\n```js\nimport * as checkError 'check-error';\n\nconst funcThatThrows = function() { throw new TypeError('I am a TypeError') };\nlet caughtErr;\n\ntry {\n  funcThatThrows();\n} catch(e) {\n  caughtErr = e;\n}\n\nconst sameInstance = caughtErr;\n\ncheckError.compatibleInstance(caughtErr, sameInstance); // true\ncheckError.compatibleInstance(caughtErr, new TypeError('Another error')); // false\n```\n\n#### .compatibleConstructor(err, errorLike)\n\n```js\nimport * as checkError 'check-error';\n\nconst funcThatThrows = function() { throw new TypeError('I am a TypeError') };\nlet caughtErr;\n\ntry {\n  funcThatThrows();\n} catch(e) {\n  caughtErr = e;\n}\n\ncheckError.compatibleConstructor(caughtErr, Error); // true\ncheckError.compatibleConstructor(caughtErr, TypeError); // true\ncheckError.compatibleConstructor(caughtErr, RangeError); // false\n```\n\n#### .compatibleMessage(err, errMatcher)\n\n```js\nimport * as checkError 'check-error';\n\nconst funcThatThrows = function() { throw new TypeError('I am a TypeError') };\nlet caughtErr;\n\ntry {\n  funcThatThrows();\n} catch(e) {\n  caughtErr = e;\n}\n\nconst sameInstance = caughtErr;\n\ncheckError.compatibleMessage(caughtErr, /TypeError$/); // true\ncheckError.compatibleMessage(caughtErr, 'I am a'); // true\ncheckError.compatibleMessage(caughtErr, /unicorn/); // false\ncheckError.compatibleMessage(caughtErr, 'I do not exist'); // false\n```\n\n#### .getConstructorName(errorLike)\n\n```js\nimport * as checkError 'check-error';\n\nconst funcThatThrows = function() { throw new TypeError('I am a TypeError') };\nlet caughtErr;\n\ntry {\n  funcThatThrows();\n} catch(e) {\n  caughtErr = e;\n}\n\nconst sameInstance = caughtErr;\n\ncheckError.getConstructorName(caughtErr) // 'TypeError'\n```\n\n#### .getMessage(err)\n\n```js\nimport * as checkError 'check-error';\n\nconst funcThatThrows = function() { throw new TypeError('I am a TypeError') };\nlet caughtErr;\n\ntry {\n  funcThatThrows();\n} catch(e) {\n  caughtErr = e;\n}\n\nconst sameInstance = caughtErr;\n\ncheckError.getMessage(caughtErr) // 'I am a TypeError'\n```\n","publish_time":1767454609438,"_cnpm_publish_time":1767454609438,"dist-tags":{"latest":"2.1.3"}}