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 e759da8 commit fbf4f70
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 175 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/
lancaster-stemmer.js
lancaster-stemmer.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/
lancaster-stemmer.js
lancaster-stemmer.min.js
*.md
16 changes: 9 additions & 7 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env node
'use strict'

var pack = require('./package.json')
var stemmer = require('.')
import {URL} from 'url'
import fs from 'fs'
import {lancasterStemmer} from './index.js'

var pack = JSON.parse(
String(fs.readFileSync(new URL('./package.json', import.meta.url)))
)
var argv = process.argv.slice(2)

if (argv.indexOf('--help') !== -1 || argv.indexOf('-h') !== -1) {
if (argv.includes('--help') || argv.includes('-h')) {
console.log(help())
} else if (argv.indexOf('--version') !== -1 || argv.indexOf('-v') !== -1) {
} else if (argv.includes('--version') || argv.includes('-v')) {
console.log(pack.version)
} else if (argv.length === 0) {
process.stdin.resume()
Expand All @@ -23,7 +25,7 @@ if (argv.indexOf('--help') !== -1 || argv.indexOf('-h') !== -1) {
function stem(values) {
return values
.split(/\s+/g)
.map((d) => stemmer(d))
.map((d) => lancasterStemmer(d))
.join(' ')
}

Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

module.exports = lancasterStemmer

var stop = -1
var intact = 0
var cont = 1
Expand Down Expand Up @@ -165,7 +163,7 @@ var rules = {
]
}

function lancasterStemmer(value) {
export function lancasterStemmer(value) {
return applyRules(String(value).toLowerCase(), true)
}

Expand Down
37 changes: 12 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,27 @@
"contributors": [
"Titus Wormer <[email protected]> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"bin": "cli.js",
"main": "index.js",
"files": [
"index.js",
"cli.js"
],
"bin": "cli.js",
"main": "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 lancasterStemmer -o lancaster-stemmer.js",
"build-mangle": "browserify . -s lancasterStemmer -p tinyify -o lancaster-stemmer.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"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
"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 @@ -63,15 +54,11 @@
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"unicorn/prefer-includes": "off",
"unicorn/prefer-starts-ends-with": "off",
"capitalized-comments": "off"
},
"ignores": [
"lancaster-stemmer.js"
]
"capitalized-comments": "off",
"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 @@ -9,6 +9,9 @@

## 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 @@ -17,8 +20,11 @@ npm install lancaster-stemmer

## API

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

```js
var lancasterStemmer = require('lancaster-stemmer')
import {lancasterStemmer} from 'lancaster-stemmer'

lancasterStemmer('considerations') // => 'consid'
lancasterStemmer('detestable') // => 'detest'
Expand Down
Loading

0 comments on commit fbf4f70

Please sign in to comment.