0.1.5 • Published 6 years ago
code-added-error v0.1.5
code-added-error
Emulation of basic Error class, with new "code" argument and "file" & "line" static methods
Installation
$ npm install code-added-errorFeatures
Supported
- Error
- prototype
- fileName
- lineNumber
- message
- name
- stack
- toString
Supported, non-official
- toJSON
- static file
- static line
Not supported
- columnNumber
- toSource
Doc
-- Attributes --
name: stringplugins' directory pathmessage: stringplugins' directory pathfileName: stringplugins' directory pathlineNumber: numberplugins' directory pathstack: stringplugins' directory path-- Constructor --
constructor(message: string, code?: string, fileName?: string, lineNumber?: string)-- Methods --
toString(codeAndMessageOnly?: boolean): stringreturn string-formated errortoJSON(codeAndMessageOnly?: boolean): objectreturn JSON-formated errorstatic file(): stringreturn current filestatic line(): numberreturn current line
Examples
"use strict";
const CodeAddedError = require('code-added-error');
const err = new CodeAddedError("This is a test", "TEST", CodeAddedError.file(), CodeAddedError.line());
console.log(err.name);
console.log(err.message);
console.log(err.toString());
console.log(err.toJSON());Typescript
"use strict";
import CodeAddedError = require('code-added-error');
const manager = new CodeAddedError("This is a test", "TEST");
console.log(err.name);
console.log(err.message);
console.log(err.toString());
console.log(err.toJSON());Tests
$ npm run-script tests