Skip to content

Commit 046e0be

Browse files
🎉 Initial Code
0 parents  commit 046e0be

File tree

12 files changed

+6853
-0
lines changed

12 files changed

+6853
-0
lines changed

.github/workflows/nodejs.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: NodeJS
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
node: ["10"]
11+
name: Node ${{ matrix.node }}
12+
steps:
13+
- uses: actions/checkout@v1
14+
- name: Setup node
15+
uses: actions/setup-node@v1
16+
with:
17+
node-version: ${{ matrix.node }}
18+
19+
- name: Setup Yarn
20+
run: npm install -g yarn
21+
22+
- name: Install
23+
run: yarn install
24+
25+
- name: Build
26+
run: yarn build
27+
28+
- name: Test
29+
run: yarn test
30+
31+
- name: Coverage
32+
run: yarn coverage
33+
34+
- name: Publish
35+
if: startsWith(github.ref, 'refs/tags/')
36+
run: echo "//registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN" > ~/.npmrc && npm publish --access public
37+
env:
38+
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
node_modules
2+
yarn-error.log
3+
coverage
4+
dist
5+
6+
.rts2_cache_cjs
7+
.rts2_cache_es
8+
.rts2_cache_umd
9+
.vscode

LICENSE

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

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Friendly Http Status
2+
3+
Translates http status code to minimal friendly object containing description and emoji 😃
4+
5+
## 🔧 Installation
6+
7+
```sh
8+
npm i friendly-http-status
9+
```
10+
11+
## 📦 Usage
12+
13+
```javascript
14+
import { getFriendlyError } from "friendly-http-status";
15+
16+
console.log(getFriendlyError(404));
17+
```
18+
19+
## 👀 Response
20+
21+
`getFriendlyError` always returns json object with following property even if code unknown it will return unknown error object
22+
23+
```json
24+
{
25+
"emoji": "",
26+
"message": "Not Found",
27+
"description": "The requested page could not be found but may be available again in the future."
28+
}
29+
```
30+
31+
## 🤠 Credits
32+
33+
- Emoji dataset is taken from [http-status-extra](https://github.com/aasaam/http-status-extra) and stripped to minimal
34+
- [microbundle](https://github.com/developit/microbundle) for packaging
35+
- [TypeScript](https://github.com/microsoft/TypeScript)

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { getFriendlyError } from "./src/";

jest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"roots": ["<rootDir>/src"],
3+
"transform": {
4+
"^.+\\.tsx?$": "ts-jest"
5+
},
6+
"testMatch": ["**/__tests__/**/*-spec.ts"]
7+
}

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "friendly-http-status",
3+
"version": "1.0.0",
4+
"description": "Translates http status code to friendly object containing description and emoji",
5+
"main": "dist/index.js",
6+
"typings": "dist/index.d.ts",
7+
"repository": "harshzalavadiya/friendly-http-status",
8+
"files": [
9+
"dist"
10+
],
11+
"scripts": {
12+
"test": "jest --config=jest.json",
13+
"coverage": "jest --coverage --config=jest.json",
14+
"dev": "microbundle watch",
15+
"build": "microbundle"
16+
},
17+
"author": "Harsh Zalavadiya <harsh@foobars.in> (twitter: @zhnebula)",
18+
"license": "MIT",
19+
"devDependencies": {
20+
"@types/jest": "^24.0.18",
21+
"jest": "^24.9.0",
22+
"microbundle": "^0.11.0",
23+
"ts-jest": "^24.1.0"
24+
},
25+
"dependencies": {}
26+
}

src/__tests__/index-spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getFriendlyError } from "..";
2+
import { defaultErrorCode, errorData } from "../error-data";
3+
4+
const errorCodes = Object.keys(errorData);
5+
6+
for (const errorCode of errorCodes) {
7+
test(`should return proper ${errorCode} response`, () => {
8+
const errorResponseObject = getFriendlyError(parseInt(errorCode));
9+
expect(errorResponseObject).toEqual(errorData[errorCode]);
10+
});
11+
}
12+
13+
test("should return unknown error object on not found", () => {
14+
const messageObject = getFriendlyError(1001);
15+
expect(messageObject).toEqual(defaultErrorCode);
16+
});

0 commit comments

Comments
 (0)