Skip to content

Commit c135257

Browse files
committed
init project
1 parent 3409581 commit c135257

29 files changed

+5509
-1
lines changed

.babelrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"plugins": ["@babel/plugin-proposal-class-properties"],
3+
"presets": ["@babel/preset-typescript"]
4+
}

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/*
2+
/node_modules/

.eslintrc.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
extends: [
4+
'plugin:@typescript-eslint/recommended',
5+
'prettier/@typescript-eslint',
6+
'plugin:prettier/recommended',
7+
],
8+
parserOptions: {
9+
ecmaVersion: 2018,
10+
sourceType: 'module',
11+
ecmaFeatures: {
12+
jsx: false,
13+
},
14+
},
15+
rules: {},
16+
settings: {},
17+
};

.github/PULL_REQUEST_TEMPLATE.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# PR Description
2+
3+
## 📝 Updated Content
4+
5+
- 🐛 Bug Fix
6+
-
7+
-
8+
- ⚙️ New Feature
9+
-
10+
-
11+
- 📦 New Release
12+
-
13+
- 🛠 Refactoring
14+
-
15+
-

.huskyrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
hooks: {
3+
'pre-commit': 'lint-staged',
4+
},
5+
};

.npmignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests/
2+
rollup.config.js
3+
jest.config.js
4+
.huskryrc.js
5+
.prettier.js
6+
.prettierignore
7+
.eslintrc.js
8+
.eslintignore
9+
.babelrc.json
10+
.vscode/

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
package.json
3+
package-lock.json
4+
yarn.lock

.prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: true,
3+
trailingComma: 'all',
4+
singleQuote: true,
5+
printWidth: 80,
6+
tabWidth: 4,
7+
};

.vscode/settings.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"editor.formatOnSave": false,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"[javascript]": {
5+
"editor.formatOnSave": true,
6+
"editor.defaultFormatter": "esbenp.prettier-vscode"
7+
},
8+
"[typescript]": {
9+
"editor.formatOnSave": true,
10+
"editor.defaultFormatter": "esbenp.prettier-vscode"
11+
},
12+
"editor.codeActionsOnSave": {
13+
"source.fixAll.eslint": true
14+
},
15+
"eslint.validate": ["javascript", "typescript"]
16+
}

README.md

+88-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,89 @@
11
# Router
2-
API Router for Readable Code
2+
3+
API Router for Readable Code.
4+
## Table of Contents
5+
6+
- [Features](#features)
7+
- [Browser Support](#browser-support)
8+
- [Installing](#installing)
9+
- [Example](#example)
10+
11+
## Features
12+
- mostly covered basic HTTP method
13+
- provide method which make payload resource for HTTP client
14+
- easily set and override HTTP client configuration with less code
15+
- modify partially basic routing configuration with builder pattern
16+
17+
## Browser Support
18+
19+
![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) |
20+
--- | --- | --- | --- | --- | --- |
21+
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
22+
23+
## Installing
24+
25+
Using npm:
26+
27+
```bash
28+
$ npm install @coldbrew/router
29+
```
30+
31+
Using yarn:
32+
33+
```bash
34+
$ yarn add @coldbrew/router
35+
```
36+
37+
## Example
38+
39+
Performing a `GET` request
40+
41+
```typescript
42+
import { Router } from '@coldbrew/router';
43+
44+
const router = new Router();
45+
46+
// Make a request with callback pattern
47+
router.uri('/user?id=12345')
48+
.get((err: RouterError, response: RouterResponse) => {
49+
if (err) {
50+
console.log('err:', err.response);
51+
}
52+
53+
console.log(response.data);
54+
});
55+
56+
// Make a request with promise pattern
57+
router.uri('/user?id=12345')
58+
.get()
59+
.then((response: RouterResponse) => {
60+
console.log(response.data.length);
61+
})
62+
.catch((err: RouterError) => {
63+
console.log(err.response);
64+
});
65+
66+
// Make a request with async/await pattern
67+
async function getUser() {
68+
try {
69+
const results: RouterResponse = await router.uri('/user?id=12345').get();
70+
} catch (e) {
71+
console.log(e.response.data);
72+
}
73+
}
74+
```
75+
76+
> **NOTE:** `async/await` is part of ECMAScript 2017 and is not supported in Internet
77+
> Explorer and older browsers, so use with caution.
78+
79+
Performing a `POST` request
80+
81+
```typescript
82+
83+
```
84+
85+
Performing multiple concurrent requests
86+
87+
```typescript
88+
89+
```

jest.config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
roots: ['<rootDir>'],
3+
verbose: true,
4+
moduleFileExtensions: ['js', 'json', 'ts', 'json'],
5+
transform: {
6+
'^.+\\.ts?$': 'ts-jest',
7+
},
8+
testEnvironment: 'node',
9+
moduleNameMapper: {
10+
'^@/(.*)$': '<rootDir>/$1',
11+
},
12+
testMatch: ['<rootDir>/src/**/*.test.ts', '<rootDir>/tests/**/*.test.ts'],
13+
transformIgnorePatterns: ['<rootDir>/node_modules/'],
14+
};

package.json

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"name": "@coldbrew/router",
3+
"description": "API Router for Readable Code",
4+
"version": "0.1.0",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"module": "dist/index.es.js",
8+
"sideEffect": false,
9+
"engines": {
10+
"node": ">=10",
11+
"npm": ">=5",
12+
"yarn": ">=1.4.0"
13+
},
14+
"scripts": {
15+
"prebuild": "tsc --emitDeclarationOnly",
16+
"build": "rollup -c",
17+
"test": "jest",
18+
"test:w": "jest --watch",
19+
"test:c": "jest --coverage"
20+
},
21+
"publishConfig": {
22+
"access": "public"
23+
},
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/coldbrewjs/router.git"
27+
},
28+
"keywords": [
29+
"xhr",
30+
"http",
31+
"ajax",
32+
"promise",
33+
"node"
34+
],
35+
"author": {
36+
"name": "Kevin You",
37+
"email": "eilgwon88@gmail.com"
38+
},
39+
"license": "MIT",
40+
"bugs": {
41+
"url": "https://github.com/coldbrewjs/Router/issues",
42+
"email": "eilgwon88@gmail.com"
43+
},
44+
"homepage": "https://github.com/coldbrewjs/Router.git",
45+
"files": [
46+
"dist/**/*"
47+
],
48+
"lint-staged": {
49+
"*.ts": [
50+
"eslint . --fix",
51+
"prettier --write"
52+
]
53+
},
54+
"peerDependencies": {
55+
"axios": "^0.21.1"
56+
},
57+
"dependencies": {
58+
"axios": "^0.21.1"
59+
},
60+
"devDependencies": {
61+
"@babel/plugin-proposal-class-properties": "^7.12.1",
62+
"@babel/preset-typescript": "^7.12.7",
63+
"@rollup/plugin-babel": "^5.2.2",
64+
"@types/jest": "^26.0.20",
65+
"@typescript-eslint/eslint-plugin": "^4.14.0",
66+
"@typescript-eslint/parser": "^4.14.0",
67+
"eslint": "^7.18.0",
68+
"eslint-config-prettier": "^7.2.0",
69+
"eslint-plugin-prettier": "^3.3.1",
70+
"husky": "^4.3.8",
71+
"jest": "^26.6.3",
72+
"lint-staged": "^10.5.3",
73+
"prettier": "^2.2.1",
74+
"rollup": "^2.37.1",
75+
"rollup-plugin-commonjs": "^10.1.0",
76+
"rollup-plugin-node-resolve": "^5.2.0",
77+
"rollup-plugin-peer-deps-external": "^2.2.4",
78+
"rollup-plugin-terser": "^7.0.2",
79+
"ts-jest": "^26.4.4",
80+
"typescript": "^4.1.3"
81+
}
82+
}

rollup.config.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
2+
import resolve from 'rollup-plugin-node-resolve';
3+
import commonjs from 'rollup-plugin-commonjs';
4+
import babel from '@rollup/plugin-babel';
5+
import { terser } from 'rollup-plugin-terser';
6+
import pkg from './package.json';
7+
8+
const extensions = ['.js', '.ts'];
9+
10+
const getPlugins = () => [
11+
peerDepsExternal({
12+
includeDependencies: true,
13+
}),
14+
resolve({ extensions }),
15+
commonjs({
16+
include: 'node_modules/**',
17+
exclude: ['**/*.test.tsx'],
18+
extensions,
19+
}),
20+
babel({
21+
babelrc: true,
22+
extensions,
23+
include: ['src/**/*'],
24+
babelHelpers: 'bundled',
25+
}),
26+
terser(),
27+
];
28+
29+
export default {
30+
input: 'src/index.ts',
31+
output: [
32+
{
33+
file: pkg.main,
34+
format: 'cjs',
35+
sourcemap: false,
36+
},
37+
],
38+
plugins: getPlugins(),
39+
};

src/configure/configure.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { UriStore, KeyStore } from '../stores';
2+
3+
export class Configure {
4+
private static instance: Configure;
5+
6+
private constructor() {
7+
if (Configure.instance) {
8+
return Configure.instance;
9+
}
10+
}
11+
12+
static get getInstance(): typeof Configure.instance {
13+
if (!Configure.instance) {
14+
Configure.instance = new Configure();
15+
}
16+
17+
return Configure.instance;
18+
}
19+
20+
public header(headers: Record<string, unknown>): Configure {
21+
KeyStore.getInstance.setData('header', headers);
22+
return this;
23+
}
24+
25+
public getHeader(): Record<string, unknown> {
26+
return KeyStore.getInstance.getData('header');
27+
}
28+
29+
public baseUri(uri: string): Configure {
30+
UriStore.getInstance.setData(uri.replace(/ /g, ''));
31+
return this;
32+
}
33+
34+
public getBaseUri(): string | undefined {
35+
return UriStore.getInstance.getData();
36+
}
37+
}

src/configure/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './configure';

src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './configure';
2+
export * from './router';
3+
export * from './types';

src/router/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './router';

0 commit comments

Comments
 (0)