# err1st

> Custom error object

Latest version **0.2.7** (published 2016-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install err1st
pnpm add err1st
yarn add err1st
bun add err1st
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.7 |
| Published | 2016-11-18 |
| First published | 2013-12-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | sailxjx |
| Maintainers | sailxjx |
| Keywords | error |

## Links

- npm: https://www.npmjs.com/package/err1st
- Repository: https://github.com/sailxjx/err1st
- Homepage: https://github.com/sailxjx/err1st#readme
- Issues: https://github.com/sailxjx/err1st/issues
- npm.io page: https://npm.io/package/err1st

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.2.7 (latest) — 2016-11-18
- 0.2.6 — 2016-06-27
- 0.2.5 — 2015-11-27
- 0.2.4 — 2015-10-19
- 0.2.3 — 2015-05-05
- 0.2.2 — 2015-04-30
- 0.2.1 — 2015-04-29
- 0.2.0 — 2015-04-27
- 0.1.3 — 2014-11-03
- 0.1.2 — 2014-08-07
- 0.1.1 — 2014-07-09
- 0.1.0 — 2014-05-14
- 0.0.18 — 2014-02-19
- 0.0.17 — 2014-02-19
- 0.0.16 — 2014-02-15
- … 13 more at https://npm.io/package/err1st/versions

## README

Err1st
======

Custom `Error` object

[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]

We hate errors, but we can not live without them.

# Example

Use err1st as an standard error object

```coffeescript
Err = require 'err1st'
err = new Err('SOMETHING_WRONG')
throw err
```

Customize the error message

```coffeescript
Err.meta
  SOMETHING_WRONG:
    status: 400
    code: 100
    message: (name) -> "something wrong, #{name}"

err = new Err 'SOMETHING_WRONG', 'Alice'
throw err  ==>  Err1st: "something wrong, Alice" ....

# With i18n locales
Err.localeMeta 'emoji',
  SOMETHING_WRONG: (name) -> "🙅, #{name}"
  ...

Err.localeMeta 'en',
  SOMETHING_WRONG: (name) -> "something wrong, #{name}"

err = new Err 'SOMETHING_WRONG', 'Bob'
console.log err.message  ==>  "🙅, Bob"
console.log err.locale('en').message  ==>  "something wrong, #{name}"
```

Combine meta and locales together

```coffeescript
Err.meta
  completed:
    status: 400
    code: 100
    locales:
      en: 'English'
      zh: '中文'
  flatten: [400100, {  # Treat keys of object as language, except 'code', 'status', 'locales'
    en: 'English',
    zh: '中文'
  }]
  useFunction: [400100, {
    en: -> 'English'
    zh: -> '中文'
  }]
```

# ChangeLog

## 0.2.7
* Support provide customized properties on meta [#4](https://github.com/sailxjx/err1st/issues/4)

## 0.2.6
* Support auto detect locale keys when use `meta` function

## 0.2.0
* Remove handler, parse the messages by the Err object itself.

## 0.1.3
* keep the status and code of original error object

## 0.1.2
* use 'DNA' to identify the same error instance

## 0.1.1
* err.code is equal to err.toCode() now
* handler.validate now support directly set a i18n dict.

# Licence
MIT

[npm-url]: https://npmjs.org/package/err1st
[npm-image]: http://img.shields.io/npm/v/err1st.svg

[travis-url]: https://travis-ci.org/sailxjx/err1st
[travis-image]: http://img.shields.io/travis/sailxjx/err1st.svg

---
_Source: https://npm.io/package/err1st · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
