Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Commit

Permalink
✨ Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vutran committed Oct 9, 2016
0 parents commit ed4cec5
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["transform-async-to-generator"]
}
10 changes: 10 additions & 0 deletions .editorconfig
@@ -0,0 +1,10 @@
root = true

# default
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions .eslintrc
@@ -0,0 +1,3 @@
{
"extends": ["airbnb-base"]
}
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
node_modules/
coverage/
npm-debug.log
.DS_Store
7 changes: 7 additions & 0 deletions .travis.yml
@@ -0,0 +1,7 @@
sudo: false
language: node_js
node_js:
- '4'
- '5'
- '6'
after_script: "cat ./coverage/lcov.info | coveralls"
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Vu Tran <vu@vu-tran.com>

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:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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.
37 changes: 37 additions & 0 deletions README.md
@@ -0,0 +1,37 @@
# dango

[![Travis](https://img.shields.io/travis/vutran/dango/develop.svg?maxAge=2592000&style=flat-square)](https://travis-ci.org/vutran/dango) [![Coveralls branch](https://img.shields.io/coveralls/vutran/dango/develop.svg?maxAge=2592000&style=flat-square)](https://coveralls.io/github/vutran/dango) [![license](https://img.shields.io/github/license/vutran/dango.svg?maxAge=2592000&style=flat-square)](LICENSE)

> Search for emojis 🍕😋😍🐷.
## Install

```bash
$ npm install --save dango
```

## Usage

```js
import dango from 'dango';

dango('pizza').then(items => {
console.log(items);
});
```

## API

### dango(q)

Returns a `Promise` that resolves an array of items.

#### q

Type: `String`

A query to search for.

## License

MIT © [Vu Tran](https://github.com/vutran/)
39 changes: 39 additions & 0 deletions __mocks__/got.js
@@ -0,0 +1,39 @@
let mockData = null;
let mockReject = false;

/**
* Mocks the `got()`` function
*/
const got = () => new Promise((resolve, reject) => {
if (mockReject) {
reject(mockReject);
return;
}
resolve({ body: mockData });
});

/**
* Set fake data for the list endpoint
*
* Example: https://api.github.com/emojis
*
* @param {String|Array|Object} data
*/
// eslint-disable-next-line no-underscore-dangle
got.__setFakeData = (data) => {
mockData = data;
};

/**
* Make the got() return a rejected Promise
*
* Example: https://api.github.com/emojis
*
* @param {Object} data
*/
// eslint-disable-next-line no-underscore-dangle
got.__setReject = (flag) => {
mockReject = flag;
};

module.exports = got;
5 changes: 5 additions & 0 deletions __tests__/.eslintrc
@@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}
66 changes: 66 additions & 0 deletions __tests__/index.js
@@ -0,0 +1,66 @@
import m from '../';

describe('dango', () => {
it('should return some emojis', async () => {
// eslint-disable-next-line global-require, no-underscore-dangle
require('got').__setFakeData({
results: [
{
text: '🍕',
score: 0.6858612895,
},
{
text: '😋',
score: 0.02997607924,
},
{
text: '😍',
score: 0.02023460716,
},
{
text: '🐷',
score: 0.010817755945,
},
{
text: '👅',
score: 0.0093791456893,
},
{
text: '🙌',
score: 0.0077837170102,
},
{
text: '😛',
score: 0.007717252709,
},
{
text: '👌',
score: 0.0075424523093,
},
{
text: '❤',
score: 0.0074847843498,
},
{
text: '🍴',
score: 0.0063261617906,
},
],
});
const results = await m('pizza');
expect(results).toContainEqual({
text: '🍕',
score: 0.6858612895,
});
});

it('should handle errors', async () => {
// eslint-disable-next-line global-require, no-underscore-dangle
require('got').__setReject(true);
try {
await m('PRODUCES_AN_ERROR');
} catch (err) {
expect(err).toBeTruthy();
}
});
});
15 changes: 15 additions & 0 deletions index.js
@@ -0,0 +1,15 @@
const got = require('got');

const ENDPOINT = 'https://api.getdango.com/api/emoji';

/**
* Searches for emojis
*
* @param {String} q - The search query
* @return {Promise} - An array of results
*/
module.exports = q => new Promise((resolve, reject) => {
got(ENDPOINT, { query: { q }, json: true })
.then(response => resolve(response.body.results))
.catch(reject);
});
44 changes: 44 additions & 0 deletions package.json
@@ -0,0 +1,44 @@
{
"name": "dango",
"version": "0.0.0",
"description": "Search for emojis",
"keywords": [
"dango",
"getdango",
"emoj",
"emoji",
"emojis",
"emote",
"emoticon",
"sticker",
"stickers"
],
"main": "index.js",
"files": [
"index.js"
],
"scripts": {
"lint": "eslint __mocks __tests__ index.js",
"test": "jest --coverage"
},
"author": "Vu Tran <vu@vu-tran.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/vutran/dango.git"
},
"dependencies": {
"got": "^6.5.0"
},
"devDependencies": {
"babel-jest": "^16.0.0",
"babel-plugin-transform-async-to-generator": "^6.16.0",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.16.0",
"coveralls": "^2.11.14",
"eslint": "^3.7.1",
"eslint-config-airbnb-base": "^8.0.0",
"eslint-plugin-import": "^1.16.0",
"jest": "^16.0.1"
}
}

0 comments on commit ed4cec5

Please sign in to comment.