@khgame/err
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

@khgame/err

another node.js error library, which supports error code

usage

CError

import {CError} from "@khgame/err"
// ...
throw new CError(ERROR_CODE.ValidateError, "Oops") // ERROR_CODE can be enum type of string or number
// ...

CAssert

import {CAssert} from "@khgame/err"

const assert = new CAssert({
  fnLog: console.error // optional, log msg will be send to the logger function if given
})
// ...
CAssert.cThrow(ERROR_CODE.ValidateError, "Oops"); // ERROR_CODE can be enum type of string or number
CAssert.cok(true, ERROR_CODE.ValidateError, () => `you can use this string function to avoid string concat.`);
CAssert.cOk(true, ERROR_CODE.ValidateError, () => `you can also insert an existed error.` );
CAssert.cNotNullAndUndefined(undefined, ERROR_CODE.ValidateError, "there are some more APIs");
CAssert.cStrictEqual(1, 2, ERROR_CODE.ValidateError, "this case will go error");
CAssert.cNotStrictEqual("1", 1, ERROR_CODE.ValidateError, "nothing happend");
// ...

Readme

Keywords

Package Sidebar

Install

npm i @khgame/err

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

14.7 kB

Total Files

16

Last publish

Collaborators

  • kinghand