-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [x] added test coverage * [x] added coverage reporter
- Loading branch information
Showing
10 changed files
with
4,037 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: # CircleCI tags: https://circleci.com/docs/2.0/docker-image-tags.json | ||
- image: circleci/node:10-browsers # Node tags: https://nodejs.org/en/download/releases/ | ||
steps: | ||
- checkout | ||
|
||
# Download and cache dependencies | ||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "package.json" }} | ||
# fallback to using the latest cache if no exact match is found | ||
- v1-dependencies- | ||
|
||
- run: yarn | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
key: v1-dependencies-{{ checksum "yarn.lock" }} | ||
|
||
- run: | ||
name: Lint | ||
command: yarn lint | ||
- run: | ||
name: Test | ||
command: yarn test && yarn coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module.exports = { | ||
root: true, | ||
parserOptions: { | ||
ecmaVersion: 2015, | ||
sourceType: 'module' | ||
}, | ||
plugins: ['prettier'], | ||
extends: ['eslint:recommended', 'plugin:prettier/recommended'], | ||
env: { | ||
browser: true, | ||
node: true | ||
}, | ||
overrides: [ | ||
{ | ||
parserOptions: { | ||
sourceType: 'module', | ||
ecmaVersion: 2017 | ||
}, | ||
env: { | ||
browser: false, | ||
node: true | ||
}, | ||
files: ['test*.js', 'tests/**/*.js'] | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# See https://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
|
||
# misc | ||
.env | ||
.tool-versions | ||
.nyc_output/ | ||
coverage/ | ||
npm-debug.log* | ||
package-lock.json | ||
yarn-error.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
registry=https://npm.pkg.github.com/0xadada |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# @0xadada/random-emoji | ||
|
||
[![CircleCI](https://img.shields.io/circleci/project/github/0xadada/random-emoji/master.svg?style=flat-square)](https://circleci.com/gh/0xadada/random-emoji) | ||
[![Coveralls branch](https://img.shields.io/coveralls/0xadada/random-emoji/master.svg?style=flat-square)](https://coveralls.io/github/0xadada/random-emoji?branch=master) | ||
|
||
_random emoji function with zero dependencies_ | ||
|
||
## Benefits | ||
|
||
* zero dependencies | ||
* doesn't define a range of emoji, just uses math | ||
|
||
|
||
## Usage | ||
|
||
```bash | ||
$ yarn add @0xadada/random-emoji | ||
$ node | ||
> const random = require('@0xadada/random-emoji'); | ||
> random() | ||
'😁' | ||
let a = random(); // defaults to 'emoticons' | ||
let b = random('emoticons'); | ||
let c = random('food'); | ||
let d = random('animals'); | ||
let e = random('expressions'); | ||
console.log(a, b, c, d, e); | ||
// 😍 🙄 🍗 🐥 🤢 | ||
``` | ||
|
||
|
||
## Arguments | ||
|
||
Invoked without arguments, the function will return an emoji character within | ||
the `'emoticons'` range of unicode characters. | ||
|
||
**Range** | ||
|
||
`random` accepts an optional `String` argument. This string describes the | ||
characters within a subset of the unicode block that `random` will be limited | ||
to. Current options are: | ||
|
||
* `'emoticons'` [1F600-1F64F](https://apps.timwhitlock.info/unicode/inspect/hex/1F600-1F64F) | ||
* `'food'` [1F32D-1F37F](https://apps.timwhitlock.info/unicode/inspect/hex/1F32D-1F37F) | ||
* `'animals'` [1F400-1F4D3](https://apps.timwhitlock.info/unicode/inspect/hex/1F400-1F4D3) | ||
* `'expressions'` [1F910-1F92F](https://apps.timwhitlock.info/unicode/inspect/hex/1F910-1F92F) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@0xadada/random-emoji", | ||
"version": "1.0.0", | ||
"description": "random emoji function with zero dependencies", | ||
"main": "random-emoji.js", | ||
"repository": "git@github.com:0xadada/random-emoji.git", | ||
"author": "0xADADA <0xadada.pub@0xadada.pub>", | ||
"license": "MIT", | ||
"private": false, | ||
"publishConfig": { | ||
"registry": "https://npm.pkg.github.com/" | ||
}, | ||
"scripts": { | ||
"coverage": "yarn nyc report --reporter=text-lcov | yarn coveralls", | ||
"lint": "yarn eslint .", | ||
"lint:fix": "yarn eslint . --fix", | ||
"test": "yarn nyc ava" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"coveralls": "^3.0.6", | ||
"eslint": "^6.5.1", | ||
"eslint-config-prettier": "^6.3.0", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"nyc": "^14.1.1", | ||
"prettier": "^1.18.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const CHAR_RANGE = { | ||
emoticons: [0x1f600, 0x1f64f], | ||
food: [0x1f32d, 0x1f37f], | ||
animals: [0x1f400, 0x1f4d3], | ||
expressions: [0x1f910, 0x1f92f] | ||
}; | ||
|
||
function random(range = 'emoticons') { | ||
let [max, min] = CHAR_RANGE[range]; | ||
let codePoint = Math.floor(Math.random() * (max - min) + min); | ||
return String.fromCodePoint(codePoint); | ||
} | ||
|
||
module.exports = random; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import test from 'ava'; | ||
import random from './random-emoji'; | ||
|
||
test('without arguments it shows an emoticon', t => { | ||
const a = random(); | ||
const cp = a.codePointAt(); | ||
t.assert(cp >= 0x1f600, 'greater than min'); | ||
t.assert(cp <= 0x1f64f, 'less than max'); | ||
}); | ||
|
||
test('with argument "emoticons" it shows an emoticon', t => { | ||
const a = random('emoticons'); | ||
const cp = a.codePointAt(); | ||
t.assert(cp >= 0x1f600, 'greater than min'); | ||
t.assert(cp <= 0x1f64f, 'less than max'); | ||
}); | ||
|
||
test('with argument "food" it shows a food emoji', t => { | ||
const a = random('food'); | ||
const cp = a.codePointAt(); | ||
t.assert(cp >= 0x1f32d, 'greater than min'); | ||
t.assert(cp <= 0x1f37f, 'less than max'); | ||
}); | ||
|
||
test('with argument "animals" it shows an animal friend emoji', t => { | ||
const a = random('animals'); | ||
const cp = a.codePointAt(); | ||
t.assert(cp >= 0x1f400, 'greater than min'); | ||
t.assert(cp <= 0x1f4d3, 'less than max'); | ||
}); | ||
|
||
test('with argument "expressions" it shows an facial expression emoji', t => { | ||
const a = random('expressions'); | ||
const cp = a.codePointAt(); | ||
t.assert(cp >= 0x1f910, 'greater than min'); | ||
t.assert(cp <= 0x1f92f, 'less than max'); | ||
}); |
Oops, something went wrong.