code-added-error
v0.1.5
Published
Emulation of basic Error class, with new "code" argument and "file" & "line" static methods
Downloads
6
Maintainers
Readme
code-added-error
Emulation of basic Error class, with new "code" argument and "file" & "line" static methods
Installation
$ npm install code-added-error
Features
Supported
- Error
- prototype
- fileName
- lineNumber
- message
- name
- stack
- toString
Supported, non-official
- toJSON
- static file
- static line
Not supported
- columnNumber
- toSource
Doc
-- Attributes --
name: string
plugins' directory pathmessage: string
plugins' directory pathfileName: string
plugins' directory pathlineNumber: number
plugins' directory pathstack: string
plugins' directory path
-- Constructor --
constructor(message: string, code?: string, fileName?: string, lineNumber?: string)
-- Methods --
toString(codeAndMessageOnly?: boolean): string
return string-formated errortoJSON(codeAndMessageOnly?: boolean): object
return JSON-formated errorstatic file(): string
return current filestatic line(): number
return 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