Skip to content

Commit 2c7a32e

Browse files
committed
Refactor code-style
1 parent a18b8a3 commit 2c7a32e

File tree

5 files changed

+47
-46
lines changed

5 files changed

+47
-46
lines changed

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
spache-formula.js
3+
spache-formula.min.js

index.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
'use strict';
1+
'use strict'
22

3-
module.exports = spache;
3+
module.exports = spache
44

5-
var SENTENCE_WEIGHT = 0.121;
6-
var WORD_WEIGHT = 0.082;
7-
var PERCENTAGE = 100;
8-
var BASE = 0.659;
5+
var sentenceWeight = 0.121
6+
var wordWeight = 0.082
7+
var percentage = 100
8+
var base = 0.659
99

10-
/* Get the grade level of a given value according to
11-
* the Spache Readability Formula. More information
12-
* is available at WikiPedia:
13-
* See: http://en.wikipedia.org/wiki/Spache_Readability_Formula. */
10+
// Get the grade level of a given value according to the Spache Readability
11+
// Formula.
12+
// More information is available at WikiPedia:
13+
// <http://en.wikipedia.org/wiki/Spache_Readability_Formula>
1414
function spache(counts) {
1515
if (!counts || !counts.sentence || !counts.word) {
16-
return NaN;
16+
return NaN
1717
}
1818

19-
return BASE +
20-
(SENTENCE_WEIGHT * counts.word / counts.sentence) +
21-
(WORD_WEIGHT * (counts.unfamiliarWord || 0) / counts.word * PERCENTAGE);
19+
return (
20+
base +
21+
(sentenceWeight * counts.word) / counts.sentence +
22+
((wordWeight * (counts.unfamiliarWord || 0)) / counts.word) * percentage
23+
)
2224
}

package.json

+13-5
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,38 @@
2323
"browserify": "^16.0.0",
2424
"is-nan": "^1.2.1",
2525
"nyc": "^13.0.0",
26+
"prettier": "^1.14.2",
2627
"remark-cli": "^5.0.0",
2728
"remark-preset-wooorm": "^4.0.0",
2829
"tape": "^4.0.0",
2930
"tinyify": "^2.4.3",
3031
"xo": "^0.22.0"
3132
},
3233
"scripts": {
33-
"build-md": "remark . -qfo",
34+
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
3435
"build-bundle": "browserify . -s spacheFormula -o spache-formula.js",
3536
"build-mangle": "browserify . -s spacheFormula -p tinyify -o spache-formula.min.js",
36-
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
37-
"lint": "xo",
37+
"build": "npm run build-bundle && npm run build-mangle",
3838
"test-api": "node test",
3939
"test-coverage": "nyc --reporter lcov tape test.js",
40-
"test": "npm run build && npm run lint && npm run test-coverage"
40+
"test": "npm run format && npm run build && npm run test-coverage"
4141
},
4242
"nyc": {
4343
"check-coverage": true,
4444
"lines": 100,
4545
"functions": 100,
4646
"branches": 100
4747
},
48+
"prettier": {
49+
"tabWidth": 2,
50+
"useTabs": false,
51+
"singleQuote": true,
52+
"bracketSpacing": false,
53+
"semi": false,
54+
"trailingComma": "none"
55+
},
4856
"xo": {
49-
"space": true,
57+
"prettier": true,
5058
"esnext": false,
5159
"ignores": [
5260
"spache-formula.js"

readme.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ npm install spache-formula
1616
## Usage
1717

1818
```js
19-
var spacheFormula = require('spache-formula');
19+
var spacheFormula = require('spache-formula')
2020

21-
spacheFormula({word: 30, sentence: 2, unfamiliarWord: 6});
22-
// 4.114
21+
spacheFormula({word: 30, sentence: 2, unfamiliarWord: 6}) // => 4.114
2322

24-
spacheFormula({word: 30, sentence: 2});
25-
// 2.474
23+
spacheFormula({word: 30, sentence: 2}) // => 2.474
2624

27-
spacheFormula()
28-
// NaN
25+
spacheFormula() // => NaN
2926
```
3027

3128
## API

test.js

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
'use strict';
1+
'use strict'
22

3-
var test = require('tape');
4-
var nan = require('is-nan');
5-
var spache = require('.');
3+
var test = require('tape')
4+
var nan = require('is-nan')
5+
var spache = require('.')
66

7-
test('daleChall', function (t) {
8-
t.ok(nan(spache()), 'NaN when an invalid value is given');
9-
10-
t.equal(
11-
round(spache({word: 30, sentence: 2, unfamiliarWord: 6})),
12-
4.114
13-
);
14-
15-
t.equal(
16-
round(spache({word: 30, sentence: 2})),
17-
2.474
18-
);
19-
20-
t.end();
21-
});
7+
test('daleChall', function(t) {
8+
t.ok(nan(spache()), 'NaN when an invalid value is given')
9+
t.equal(round(spache({word: 30, sentence: 2, unfamiliarWord: 6})), 4.114)
10+
t.equal(round(spache({word: 30, sentence: 2})), 2.474)
11+
t.end()
12+
})
2213

2314
function round(val) {
24-
return Math.round(val * 1e6) / 1e6;
15+
return Math.round(val * 1e6) / 1e6
2516
}

0 commit comments

Comments
 (0)