New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

errorable

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

errorable

errorable

latest
npmnpm
Version
0.6.0
Version published
Maintainers
2
Created
Source

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

Keywords

error

FAQs

Package last updated on 20 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts