Skip to content

Commit

Permalink
thanks Katryn
Browse files Browse the repository at this point in the history
  • Loading branch information
0xadada committed Nov 22, 2019
1 parent 96d6002 commit 1953c19
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ module.exports = {
},
plugins: ['@typescript-eslint'],
extends: [
"eslint:recommended",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
/*,"prettier",
"prettier/@typescript-eslint"*/
],
rules: {
'@typescript-eslint/no-inferrable-types': 1
},
/*
env: {
browser: true,
Expand Down
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@ _random emoji function with zero dependencies_

```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);
// 😍 🙄 🍗 🐥 🤢
$ npm run -s start
> 🙄
$ npm run -s start
> 😜
```


Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
},
"scripts": {
"coverage": "npx nyc report --reporter=text-lcov | yarn coveralls",
"build": "npx tsc --outFile lib/index.js src/index.ts",
"build": "npx tsc",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix",
"test": "npm run build && npx nyc ava",
"prepublish": "npm run build && npm run test"
"prepublish": "npm run build && npm run test",
"start": "npm run build && node -e \"let { default: r } = require('./lib/index'); console.log(r('food'));\""
},
"devDependencies": {
"@babel/cli": "^7.6.4",
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
interface NamedCharRange {
emoticons: string;
food: string;
animals: string;
expressions: string;
}

const CHAR_RANGE = {
emoticons: [0x1f600, 0x1f64f],
food: [0x1f32d, 0x1f37f],
animals: [0x1f400, 0x1f4d3],
expressions: [0x1f910, 0x1f92f]
};

const random = function(range = 'emoticons'): string {
const random = function(range: keyof NamedCharRange = 'emoticons'): string {
const [max, min] = CHAR_RANGE[range];
const codePoint = Math.floor(Math.random() * (max - min) + min);
return String.fromCodePoint(codePoint);
};

module.exports = random;
export default random;

0 comments on commit 1953c19

Please sign in to comment.