Skip to content

Commit

Permalink
refactored to TypeScript
Browse files Browse the repository at this point in the history
* [x] resolved #2

refactored package to typescript

PR comments

thanks Katryn

simpler type
  • Loading branch information
0xADADA authored and 0xadada committed Nov 24, 2019
1 parent c96936b commit f746d1f
Show file tree
Hide file tree
Showing 10 changed files with 947 additions and 768 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# compiled output
<<<<<<< HEAD
/dist/
=======
dist/
lib/
>>>>>>> 93a6802... refactored to TypeScript
22 changes: 15 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2015,
project: './tsconfig.json',
ecmaVersion: 2018,
sourceType: 'module'
},
plugins: ['prettier'],
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
env: {
browser: true,
node: true
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended'
],
rules: {
'@typescript-eslint/no-inferrable-types': 1
},
overrides: [
{
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2017
ecmaVersion: 2018
},
env: {
browser: false,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ yarn-error.log

# built assets
/dist

20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ _random emoji function with zero dependencies_

```bash
$ yarn add @0xadada/random-emoji
$ npm run -s start
> 🙄
$ npm run -s start
> 😜
$ node
> const random = require('@0xadada/random-emoji');
> const { default: 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);
// 😍 🙄 🍗 🐥 🤢
> 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);
😍 🙄 🍗 🐥 🤢
```
Expand Down
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,28 @@
},
"scripts": {
"coverage": "npx nyc report --reporter=text-lcov | yarn coveralls",
"build": "npx babel src/ --out-dir dist/",
"build": "npx tsc",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix",
"test": "npx nyc ava",
"prepublish": "npm run lint && npm run test && npm run build"
"test": "npm run build && npx nyc ava",
"prepublish": "npm run build && npm run test",
"start": "npm run build && node -e \"let { default: r } = require('./dist/index'); console.log(r('food'));\""
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/preset-env": "^7.6.3",
"@babel/preset-typescript": "^7.7.2",
"@typescript-eslint/eslint-plugin": "^2.8.0",
"@typescript-eslint/parser": "^2.8.0",
"ava": "^2.4.0",
"babel-eslint": "^10.0.3",
"coveralls": "^3.0.6",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.3.0",
"eslint": "^6.7.0",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-prettier": "^3.1.1",
"nyc": "^14.1.1",
"prettier": "^1.18.2"
"prettier": "^1.19.1",
"typescript": "^3.7.2"
}
}
14 changes: 0 additions & 14 deletions src/index.js

This file was deleted.

16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type NamedCharRange = 'emoticons' | 'food' | 'animals' | 'expressions';

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

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

export = random;
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import random from './src/index';
import random from './dist/index';

test('without arguments it shows an emoticon', t => {
const a = random();
Expand Down
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es5",
"outDir": "dist",
"strict": true
},
"exclude": ["node_modules", "test.js"]
}
Loading

0 comments on commit f746d1f

Please sign in to comment.