Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 6, 2021
1 parent 162726e commit 914644d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 31 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
smog-formula.js
smog-formula.min.js
yarn.lock
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
coverage/
smog-formula.js
smog-formula.min.js
*.md
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict'

module.exports = smog

var sentenceSize = 30
var weight = 1.043
var base = 3.1291

// Get the grade level of a given value according to the SMOG formula.
// More information is available at WikiPedia:
// <https://en.wikipedia.org/wiki/SMOG>
function smog(counts) {
export function smogFormula(counts) {
if (!counts || !counts.sentence) {
return Number.NaN
}
Expand Down
24 changes: 11 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,25 @@
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"index.js"
],
"devDependencies": {
"browserify": "^17.0.0",
"nyc": "^15.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"tinyify": "^3.0.0",
"xo": "^0.38.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"build-bundle": "browserify . -s smogFormula -o smog-formula.js",
"build-mangle": "browserify . -s smogFormula -p tinyify -o smog-formula.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run build && npm run test-coverage"
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -54,10 +52,10 @@
},
"xo": {
"prettier": true,
"esnext": false,
"ignores": [
"smog-formula.js"
]
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ See [`syllable`][syllable] for detecting syllables.

## Install

This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
instead of `require`d.

[npm][]:

```sh
Expand All @@ -21,7 +24,7 @@ npm install smog-formula
## Use

```js
var smogFormula = require('smog-formula')
import {smogFormula} from 'smog-formula'

// For “The Australian platypus is seemingly a hybrid of a mammal and reptilian
// creature.” (1 sentence; 4 polysillabic words).
Expand All @@ -31,6 +34,9 @@ smogFormula({sentence: 1, polysillabicWord: 4})

## API

This package exports the following identifiers: `smogFormula`.
There is no default export.

### `smogFormula(counts)`

Given an object containing the number of sentences (`sentence`) and the number
Expand Down
12 changes: 5 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict'

var test = require('tape')
var smog = require('.')
import test from 'tape'
import {smogFormula} from './index.js'

test('smogFormula', function (t) {
t.ok(Number.isNaN(smog()), 'NaN when an invalid value is given')
t.equal(round(smog({sentence: 1})), 3.1291)
t.equal(round(smog({sentence: 1, polysillabicWord: 4})), 14.554593)
t.ok(Number.isNaN(smogFormula()), 'NaN when an invalid value is given')
t.equal(round(smogFormula({sentence: 1})), 3.1291)
t.equal(round(smogFormula({sentence: 1, polysillabicWord: 4})), 14.554593)
t.end()
})

Expand Down

0 comments on commit 914644d

Please sign in to comment.