Skip to content

Commit 7fb15a7

Browse files
committed
init readme and license
1 parent 6b516a5 commit 7fb15a7

File tree

2 files changed

+114
-2
lines changed

2 files changed

+114
-2
lines changed

LICENSE

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2016 Jeremiah Harlan <[email protected]>
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+106-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
1-
JSON API Errors
2-
===============
1+
# JSON API Errors
2+
3+
Create errors using [JSON API errors format](http://jsonapi.org/format/#errors)
4+
5+
[![npm package](https://nodei.co/npm/json-api-errors.png?downloads=true&downloadRank=true&stars=true)][package]
6+
7+
8+
[![version](https://img.shields.io/npm/v/json-api-errors.svg?style=flat-square)][version]
9+
[![build](https://img.shields.io/travis/theworkflow/json-api-errors/master.svg?style=flat-square)][build]
10+
[![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license]
11+
[![climate](https://img.shields.io/codeclimate/github/theworkflow/json-api-errors.svg?style=flat-square)][climate]
12+
[![coverage](https://img.shields.io/codeclimate/coverage/github/theworkflow/json-api-errors.svg?style=flat-square)][coverage]
13+
14+
### Installation
15+
16+
`$ npm install json-api-errors`
17+
18+
### Usage
19+
20+
#### `Errors.createSingle(id, message, [meta])`
21+
22+
Create a single errors object.
23+
24+
- `id` (String)
25+
- required
26+
- `message` (String)
27+
- required
28+
- `meta` (Object | String)
29+
- optional
30+
31+
```javascript
32+
const Errors = require('json-api-errors')
33+
34+
var errors = new Errors()
35+
var err = errors.createSingle('CUSTOM_ERROR', 'Custom error message')
36+
37+
console.log(err)
38+
// {
39+
// errors: [{ id: 'CUSTOM_ERROR', message: 'Custom error message' }]
40+
// }
41+
```
42+
43+
#### `Errors.add(id, message, [meta])`
44+
45+
Add an error to the errors array
46+
47+
- `id` (String)
48+
- required
49+
- `message` (String)
50+
- required
51+
- `meta` (Object | String)
52+
- optional
53+
54+
```javascript
55+
const Errors = require('json-api-errors')
56+
57+
var errors = new Errors()
58+
errors.add('CUSTOM_ERROR', 'Custom error message')
59+
```
60+
61+
#### `Errors.get()`
62+
63+
Retreive all errors. Errors are returned in a JSON format
64+
65+
```javascript
66+
const Errors = require('json-api-errors')
67+
68+
var errors = new Errors()
69+
errors.add('CUSTOM_ERROR', 'Custom error message')
70+
71+
var errs = errors.get()
72+
// {
73+
// errors: [{ id: 'CUSTOM_ERROR', message: 'Custom error message' }]
74+
// }
75+
```
76+
77+
#### `Errors.clear()`
78+
79+
Remove all errors
80+
81+
```javascript
82+
const Errors = require('json-api-errors')
83+
84+
var errList, errors = new Errors()
85+
86+
errors.add('CUSTOM_ERROR', 'Custom error message')
87+
88+
errList = errors.get()
89+
console.log(errList.errors) // Length is 1
90+
91+
errors.clear()
92+
errList = errors.get()
93+
94+
console.log(errList.errors) // Length is 0
95+
```
96+
97+
### Tests
98+
99+
`$ npm test`
100+
101+
[package]: https://nodei.co/npm/json-api-errors
102+
[version]: https://www.npmjs.com/package/json-api-errors
103+
[build]: https://travis-ci.org/theworkflow/api-util
104+
[license]: https://raw.githubusercontent.com/theworkflow/json-api-errors/master/LICENSE
105+
[climate]: https://codeclimate.com/github/theworkflow/json-api-errors
106+
[coverage]: https://codeclimate.com/github/theworkflow/json-api-errors/coverage

0 commit comments

Comments
 (0)