0.6.0 • Published 6 years ago

errorable v0.6.0

Weekly downloads
8
License
MIT
Repository
-
Last release
6 years ago

Errorable

NPM version Build Status Dependency Status Coverage percentage

Create javascript errors in a smart & simple way.

Usage

Defines an IErrorOptions object

JSON files are totally ok for ease of maintance.

import { IErrorOptions } from "errorable";

const json: IErrorOptions = {
  Hello: {
    code: 100,
    messages: {}
  },
  I: {
    Love: {
      You: {
        code: 1,
        messages: {
          "en-US": "I Love U!",
          "zh-CN": "我爱你!"
        }
      }
    }
  },
  Me: {
    alias: "I"
  }
};

Generate errors

import { Generator } from "errorable";

const errors: any = Generator.generate(json);

// Got three errors:
// errors.ILoveYou
// errors.MeLoveYou
// errors.Hello

or

import { Generator } from "errorable";
const errors: any = Generator.generate(json, true);

// Got three errors:
// errors.I_LOVE_YOU
// errors.ME_LOVE_YOU
// errors.HELLO

Create and throw localized errors

const { ILoveYou, Hello } = errors;
throw new ILoveYou("zh-CN");
throw new Hello("en-US");

Load from or save to files

const jsonFilename = path.resolve(__dirname, "./tmp.json");

// Saving json to files
Generator.save(jsonFilename, json);

// Loading json from files
const newJson = Generator.load(jsonFilename);

// json equals newJson
expect(json).toEqual(newJson);

License

MIT © calidion

0.6.0

6 years ago

0.5.0

6 years ago

0.5.1

6 years ago

0.4.0

9 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago