Skip to content

Commit

Permalink
feat: first version (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuong Tran committed Oct 8, 2020
1 parent f9bdf8b commit 1bde679
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 212 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# ts-npm-template
# xuka

[![Build Status](https://travis-ci.org/103cuong/ts-npm-template.svg?branch=master)](https://travis-ci.org/103cuong/ts-npm-template)
[![Build Status](https://travis-ci.org/103cuong/xuka.svg?branch=master)](https://travis-ci.org/103cuong/xuka)

A TypeScript template 🌼 for npm package
A simple 👰🏻 HTTP client

## License
## usage

```typescript
import { request } from 'xuka';

const { data } = await request('https://jsonplaceholder.typicode.com/todos/1');
```

## license

MIT © [103cuong](https://github.com/103cuong)
8 changes: 7 additions & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { request } from '../src';

it('test', async() => {
expect(true).toEqual(true);
const { data } = await request('https://jsonplaceholder.typicode.com/todos/1');
expect(data.userId).toEqual(1);
expect(data.id).toEqual(1);
expect(data.title).toEqual('delectus aut autem');
expect(data.completed).toEqual(false);
});
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "typescript-npm-template",
"version": "0.0.1",
"description": "A TypeScript template 🌼 for npm package",
"name": "xuka",
"version": "0.1.0",
"description": "A simple 👰🏻 HTTP client",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"repository": "https://github.com/103cuong/ts-npm-template",
"author": "Nguyen Duy Cuong <103cuong@gmail.com>",
"repository": "https://github.com/103cuong/xuka",
"author": "Cuong Tran <103cuong@gmail.com>",
"keywords": [
"npm",
"typescript",
Expand Down Expand Up @@ -53,8 +53,6 @@
"typescript": "^3.8.3"
},
"dependencies": {
"diana-js": "^0.6.0",
"hera-js": "^0.2.0",
"juno-js": "^0.0.2"
"axios": "^0.20.0"
}
}
24 changes: 22 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import { logger } from 'juno-js';
import axios, { AxiosRequestConfig } from 'axios';

logger().info('Chao xìn 🇻🇳');
/**
* An HTTP client is implemented from the Axios package.
*
* @param {string} url A url from a network.
* @param {object} options Options to config request.
* See more option here: https://github.com/axios/axios
*/
const request = (url = '', options: AxiosRequestConfig = {}) => {
const {
method = 'get', responseType = 'json', data = {}, ...config
} = options;
return axios({
method,
url,
responseType,
data,
...config,
});
};

export { request };
Loading

0 comments on commit 1bde679

Please sign in to comment.