Skip to content

Commit 96de345

Browse files
committed
Refactor and add coverage
1 parent bee3093 commit 96de345

File tree

9 files changed

+83
-81
lines changed

9 files changed

+83
-81
lines changed

.node-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

.npmignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules
2-
src
2+
test
3+
coverage
4+
LICENSE
5+
.*

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v5
1+
v6

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
language: node_js
22
node_js:
3-
- "0.12"
43
- "4"
54
- "5"
5+
- "6"
66
notifications:
77
email: false
8+
after_success:
9+
- npm run coveralls

LICENSE

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
Copyright (c) 2015, Password.diet <>
1+
The MIT License (MIT)
22

3-
Permission to use, copy, modify, and/or distribute this software for any
4-
purpose with or without fee is hereby granted, provided that the above
5-
copyright notice and this permission notice appear in all copies.
3+
Copyright (c) 2016 Leonardo Gatica
64

7-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
1411

12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![npm version](https://img.shields.io/npm/v/diceware-generator.svg?style=flat-square)](https://www.npmjs.com/package/diceware-generator)
44
[![npm downloads](https://img.shields.io/npm/dm/diceware-generator.svg?style=flat-square)](https://www.npmjs.com/package/diceware-generator)
55
[![Build Status](https://img.shields.io/travis/lgaticaq/diceware-generator.svg?style=flat-square)](https://travis-ci.org/lgaticaq/diceware-generator)
6+
[![Coverage Status](https://img.shields.io/coveralls/lgaticaq/diceware-generator/master.svg?style=flat-square)](https://coveralls.io/github/lgaticaq/diceware-generator?branch=master)
67
[![dependency Status](https://img.shields.io/david/lgaticaq/diceware-generator.svg?style=flat-square)](https://david-dm.org/lgaticaq/diceware-generator#info=dependencies)
78
[![devDependency Status](https://img.shields.io/david/dev/lgaticaq/diceware-generator.svg?style=flat-square)](https://david-dm.org/lgaticaq/diceware-generator#info=devDependencies)
89
[![Join the chat at https://gitter.im/lgaticaq/diceware-generator](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg?style=flat-square)](https://gitter.im/lgaticaq/diceware-generator?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

package.json

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,26 @@
22
"name": "diceware-generator",
33
"version": "1.2.2",
44
"description": "A diceware generator",
5-
"main": "dist",
5+
"main": "src",
66
"scripts": {
7-
"prebuild": "npm run lint -s && npm run clean -s",
8-
"build": "babel src --out-dir dist --source-maps",
9-
"lint": "eslint src",
10-
"clean": "rimraf dist",
11-
"prepublish": "npm run test -s",
12-
"pretest": "npm run build -s",
13-
"test": "mocha --compilers js:babel-core/register"
7+
"pretest": "eslint src",
8+
"test": "istanbul cover _mocha",
9+
"coveralls": "coveralls < coverage/lcov.info"
10+
},
11+
"engines": {
12+
"node": ">=4"
1413
},
1514
"repository": {
1615
"type": "git",
1716
"url": "git+https://github.com/lgaticaq/diceware-generator.git"
1817
},
19-
"engines": {
20-
"node": ">=0.12"
21-
},
2218
"keywords": [
2319
"diceware",
2420
"password",
2521
"generator"
2622
],
2723
"author": "Leonardo Gatica <[email protected]> (https://about.me/lgatica)",
28-
"license": "ISC",
24+
"license": "MIT",
2925
"bugs": {
3026
"url": "https://github.com/lgaticaq/diceware-generator/issues"
3127
},
@@ -35,52 +31,42 @@
3531
"diceware-wordlist-jp": "^1.0.1",
3632
"diceware-wordlist-sp": "^1.0.0",
3733
"diceware-wordlist-swe": "^1.0.1",
38-
"lodash": "^4.0.0",
34+
"lodash": "^4.12.0",
3935
"secure-random": "^1.1.1"
4036
},
4137
"devDependencies": {
42-
"babel-cli": "^6.4.0",
43-
"babel-core": "^6.4.0",
44-
"babel-preset-es2015": "^6.3.13",
45-
"chai": "^3.4.1",
38+
"chai": "^3.5.0",
39+
"coveralls": "^2.11.9",
4640
"eslint": "^2.10.1",
47-
"js-combinatorics": "^0.5.0",
48-
"mocha": "^2.3.4",
49-
"rimraf": "^2.5.0"
41+
"istanbul": "^0.4.3",
42+
"js-combinatorics": "^0.5.2",
43+
"mocha": "^2.4.5"
5044
},
5145
"eslintConfig": {
46+
"env": {
47+
"es6": true,
48+
"node": true,
49+
"mocha": true
50+
},
51+
"extends": "eslint:recommended",
5252
"rules": {
5353
"indent": [
5454
2,
5555
2
5656
],
57-
"quotes": [
58-
2,
59-
"single"
60-
],
6157
"linebreak-style": [
6258
2,
6359
"unix"
6460
],
61+
"quotes": [
62+
2,
63+
"single"
64+
],
6565
"semi": [
6666
2,
6767
"always"
6868
]
69-
},
70-
"ecmaFeatures": {
71-
"modules": true
72-
},
73-
"env": {
74-
"es6": true,
75-
"node": true,
76-
"mocha": true
77-
},
78-
"extends": "eslint:recommended"
79-
},
80-
"babel": {
81-
"presets": [
82-
"es2015"
83-
]
69+
}
8470
},
8571
"tonicExampleFilename": "example.js"
8672
}

src/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import secureRandom from 'secure-random';
2-
import {assign, includes, range} from 'lodash';
1+
'use strict';
2+
3+
const secureRandom = require('secure-random');
4+
const _ = require('lodash');
35

46
const dw = {
57
en: require('diceware-wordlist-en'),
@@ -20,22 +22,22 @@ const getRandomInt = (min, max) => {
2022

2123
const diceRoll = () => getRandomInt(1, 6);
2224

23-
const diceSeq = (count) => range(count).map(() => diceRoll()).join('');
25+
const diceSeq = count => _.range(count).map(() => diceRoll()).join('');
2426

2527
const getDices = () => diceSeq(5);
2628

27-
const getRandomWord = (language) => dw[language][getDices()];
29+
const getRandomWord = language => dw[language][getDices()];
2830

29-
const getRandomPassword = (options) => {
30-
options = assign({
31+
const getRandomPassword = options => {
32+
options = _.assign({
3133
'language': 'en',
3234
'wordcount': 6,
3335
'format': 'string'
3436
}, options);
35-
if (!includes(['en', 'swe', 'jp', 'sp'], options.language)) {
37+
if (!_.includes(['en', 'swe', 'jp', 'sp'], options.language)) {
3638
throw(new Error(`Unsupported language: ${options.language}`));
3739
}
38-
const words = range(options.wordcount).map(() => getRandomWord(options.language));
40+
const words = _.range(options.wordcount).map(() => getRandomWord(options.language));
3941
return (options.format === 'array') ? words : words.join(' ');
4042
};
4143

test/index.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1-
import {expect} from 'chai';
2-
import dwGen from '../src';
1+
'use strict';
32

4-
describe('wordlist', function() {
5-
it('should return a string by default', function() {
3+
const expect = require('chai').expect;
4+
const dwGen = require('../src');
5+
6+
describe('wordlist', () => {
7+
it('should return a string by default', () => {
68
expect(dwGen()).to.be.a('string');
79
});
810

9-
it('should return 6 words by default', function() {
11+
it('should return 6 words by default', () => {
1012
expect(dwGen().split(' ').length).to.equal(6);
1113
});
1214

13-
it('should return an array if requested', function() {
15+
it('should return an array if requested', () => {
1416
expect(dwGen({'format': 'array'})).to.be.a('array');
1517
});
1618

17-
it('should return an 6 item array in array mode by default', function() {
19+
it('should return an 6 item array in array mode by default', () => {
1820
expect(dwGen({'format': 'array'}).length).to.equal(6);
1921
});
2022

21-
it('should obey requested length in string mode', function() {
23+
it('should obey requested length in string mode', () => {
2224
expect(dwGen({'wordcount': 11}).split(' ').length).to.equal(11);
2325
});
2426

25-
it('should obey requested length in array mode', function() {
27+
it('should obey requested length in array mode', () => {
2628
expect(dwGen({'format': 'array', 'wordcount': 11}).length).to.equal(11);
2729
});
2830

29-
it('should support en', function() {
30-
expect(function() {
31+
it('should support en', () => {
32+
expect(() => {
3133
dwGen({'language': 'en'});
3234
}).to.not.throw(Error);
3335
});
3436

35-
it('should support jp', function() {
36-
expect(function() {
37+
it('should support jp', () => {
38+
expect(() => {
3739
dwGen({'language': 'jp'});
3840
}).to.not.throw(Error);
3941
});
4042

41-
it('should support swe', function() {
42-
expect(function() {
43+
it('should support swe', () => {
44+
expect(() => {
4345
dwGen({'language': 'swe'});
4446
}).to.not.throw(Error);
4547
});
4648

47-
it('should support sp', function() {
48-
expect(function() {
49+
it('should support sp', () => {
50+
expect(() => {
4951
dwGen({'language': 'sp'});
5052
}).to.not.throw(Error);
5153
});
5254

53-
it('should throw an error if asked for an unsupported language', function() {
54-
expect(function() {
55+
it('should throw an error if asked for an unsupported language', () => {
56+
expect(() => {
5557
dwGen({'language': 'bogusTalk'});
5658
}).to.throw(Error);
5759
});

0 commit comments

Comments
 (0)