diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..2bd7eee --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +lancaster-stemmer.js +lancaster-stemmer.min.js diff --git a/cli.js b/cli.js index 1cf7662..7cc462e 100755 --- a/cli.js +++ b/cli.js @@ -1,55 +1,54 @@ #!/usr/bin/env node -'use strict'; +'use strict' -var pack = require('./package.json'); -var stemmer = require('.'); +var pack = require('./package.json') +var stemmer = require('.') -var argv = process.argv.slice(2); +var argv = process.argv.slice(2) -if ( - argv.indexOf('--help') !== -1 || - argv.indexOf('-h') !== -1 -) { - console.log(help()); -} else if ( - argv.indexOf('--version') !== -1 || - argv.indexOf('-v') !== -1 -) { - console.log(pack.version); +if (argv.indexOf('--help') !== -1 || argv.indexOf('-h') !== -1) { + console.log(help()) +} else if (argv.indexOf('--version') !== -1 || argv.indexOf('-v') !== -1) { + console.log(pack.version) } else if (argv.length === 0) { - process.stdin.resume(); - process.stdin.setEncoding('utf8'); - process.stdin.on('data', function (data) { - console.log(stem(data)); - }); + process.stdin.resume() + process.stdin.setEncoding('utf8') + process.stdin.on('data', function(data) { + console.log(stem(data)) + }) } else { - console.log(stem(argv.join(' '))); + console.log(stem(argv.join(' '))) } function stem(values) { - return values.split(/\s+/g).map(stemmer).join(' '); + return values + .split(/\s+/g) + .map(stemmer) + .join(' ') } function help() { - return [ - '', - 'Usage: ' + pack.name + ' [options] ', - '', - pack.description, - '', - 'Options:', - '', - ' -h, --help output usage information', - ' -v, --version output version number', - '', - 'Usage:', - '', - '# output stems', - '$ ' + pack.name + ' considerations', - stem('considerations'), - '', - '# output stems from stdin', - '$ echo "detestable vileness" | ' + pack.name, - stem('detestable vileness') - ].join('\n ') + '\n'; + return ( + [ + '', + 'Usage: ' + pack.name + ' [options] ', + '', + pack.description, + '', + 'Options:', + '', + ' -h, --help output usage information', + ' -v, --version output version number', + '', + 'Usage:', + '', + '# output stems', + '$ ' + pack.name + ' considerations', + stem('considerations'), + '', + '# output stems from stdin', + '$ echo "detestable vileness" | ' + pack.name, + stem('detestable vileness') + ].join('\n ') + '\n' + ) } diff --git a/index.js b/index.js index 95f3ee6..8f055fa 100644 --- a/index.js +++ b/index.js @@ -1,225 +1,225 @@ -'use strict'; +'use strict' -module.exports = lancasterStemmer; +module.exports = lancasterStemmer -var STOP = -1; -var INTACT = 0; -var CONTINUE = 1; -var PROTECT = 2; -var VOWELS = /[aeiouy]/; +var stop = -1 +var intact = 0 +var cont = 1 +var protect = 2 +var vowels = /[aeiouy]/ var rules = { a: [ - {match: 'ia', replacement: '', type: INTACT}, - {match: 'a', replacement: '', type: INTACT} + {match: 'ia', replacement: '', type: intact}, + {match: 'a', replacement: '', type: intact} ], - b: [{match: 'bb', replacement: 'b', type: STOP}], + b: [{match: 'bb', replacement: 'b', type: stop}], c: [ - {match: 'ytic', replacement: 'ys', type: STOP}, - {match: 'ic', replacement: '', type: CONTINUE}, - {match: 'nc', replacement: 'nt', type: CONTINUE} + {match: 'ytic', replacement: 'ys', type: stop}, + {match: 'ic', replacement: '', type: cont}, + {match: 'nc', replacement: 'nt', type: cont} ], d: [ - {match: 'dd', replacement: 'd', type: STOP}, - {match: 'ied', replacement: 'y', type: CONTINUE}, - {match: 'ceed', replacement: 'cess', type: STOP}, - {match: 'eed', replacement: 'ee', type: STOP}, - {match: 'ed', replacement: '', type: CONTINUE}, - {match: 'hood', replacement: '', type: CONTINUE} - ], - e: [{match: 'e', replacement: '', type: CONTINUE}], + {match: 'dd', replacement: 'd', type: stop}, + {match: 'ied', replacement: 'y', type: cont}, + {match: 'ceed', replacement: 'cess', type: stop}, + {match: 'eed', replacement: 'ee', type: stop}, + {match: 'ed', replacement: '', type: cont}, + {match: 'hood', replacement: '', type: cont} + ], + e: [{match: 'e', replacement: '', type: cont}], f: [ - {match: 'lief', replacement: 'liev', type: STOP}, - {match: 'if', replacement: '', type: CONTINUE} + {match: 'lief', replacement: 'liev', type: stop}, + {match: 'if', replacement: '', type: cont} ], g: [ - {match: 'ing', replacement: '', type: CONTINUE}, - {match: 'iag', replacement: 'y', type: STOP}, - {match: 'ag', replacement: '', type: CONTINUE}, - {match: 'gg', replacement: 'g', type: STOP} + {match: 'ing', replacement: '', type: cont}, + {match: 'iag', replacement: 'y', type: stop}, + {match: 'ag', replacement: '', type: cont}, + {match: 'gg', replacement: 'g', type: stop} ], h: [ - {match: 'th', replacement: '', type: INTACT}, - {match: 'guish', replacement: 'ct', type: STOP}, - {match: 'ish', replacement: '', type: CONTINUE} + {match: 'th', replacement: '', type: intact}, + {match: 'guish', replacement: 'ct', type: stop}, + {match: 'ish', replacement: '', type: cont} ], i: [ - {match: 'i', replacement: '', type: INTACT}, - {match: 'i', replacement: 'y', type: CONTINUE} + {match: 'i', replacement: '', type: intact}, + {match: 'i', replacement: 'y', type: cont} ], j: [ - {match: 'ij', replacement: 'id', type: STOP}, - {match: 'fuj', replacement: 'fus', type: STOP}, - {match: 'uj', replacement: 'ud', type: STOP}, - {match: 'oj', replacement: 'od', type: STOP}, - {match: 'hej', replacement: 'her', type: STOP}, - {match: 'verj', replacement: 'vert', type: STOP}, - {match: 'misj', replacement: 'mit', type: STOP}, - {match: 'nj', replacement: 'nd', type: STOP}, - {match: 'j', replacement: 's', type: STOP} + {match: 'ij', replacement: 'id', type: stop}, + {match: 'fuj', replacement: 'fus', type: stop}, + {match: 'uj', replacement: 'ud', type: stop}, + {match: 'oj', replacement: 'od', type: stop}, + {match: 'hej', replacement: 'her', type: stop}, + {match: 'verj', replacement: 'vert', type: stop}, + {match: 'misj', replacement: 'mit', type: stop}, + {match: 'nj', replacement: 'nd', type: stop}, + {match: 'j', replacement: 's', type: stop} ], l: [ - {match: 'ifiabl', replacement: '', type: STOP}, - {match: 'iabl', replacement: 'y', type: STOP}, - {match: 'abl', replacement: '', type: CONTINUE}, - {match: 'ibl', replacement: '', type: STOP}, - {match: 'bil', replacement: 'bl', type: CONTINUE}, - {match: 'cl', replacement: 'c', type: STOP}, - {match: 'iful', replacement: 'y', type: STOP}, - {match: 'ful', replacement: '', type: CONTINUE}, - {match: 'ul', replacement: '', type: STOP}, - {match: 'ial', replacement: '', type: CONTINUE}, - {match: 'ual', replacement: '', type: CONTINUE}, - {match: 'al', replacement: '', type: CONTINUE}, - {match: 'll', replacement: 'l', type: STOP} + {match: 'ifiabl', replacement: '', type: stop}, + {match: 'iabl', replacement: 'y', type: stop}, + {match: 'abl', replacement: '', type: cont}, + {match: 'ibl', replacement: '', type: stop}, + {match: 'bil', replacement: 'bl', type: cont}, + {match: 'cl', replacement: 'c', type: stop}, + {match: 'iful', replacement: 'y', type: stop}, + {match: 'ful', replacement: '', type: cont}, + {match: 'ul', replacement: '', type: stop}, + {match: 'ial', replacement: '', type: cont}, + {match: 'ual', replacement: '', type: cont}, + {match: 'al', replacement: '', type: cont}, + {match: 'll', replacement: 'l', type: stop} ], m: [ - {match: 'ium', replacement: '', type: STOP}, - {match: 'um', replacement: '', type: INTACT}, - {match: 'ism', replacement: '', type: CONTINUE}, - {match: 'mm', replacement: 'm', type: STOP} + {match: 'ium', replacement: '', type: stop}, + {match: 'um', replacement: '', type: intact}, + {match: 'ism', replacement: '', type: cont}, + {match: 'mm', replacement: 'm', type: stop} ], n: [ - {match: 'sion', replacement: 'j', type: CONTINUE}, - {match: 'xion', replacement: 'ct', type: STOP}, - {match: 'ion', replacement: '', type: CONTINUE}, - {match: 'ian', replacement: '', type: CONTINUE}, - {match: 'an', replacement: '', type: CONTINUE}, - {match: 'een', replacement: '', type: PROTECT}, - {match: 'en', replacement: '', type: CONTINUE}, - {match: 'nn', replacement: 'n', type: STOP} + {match: 'sion', replacement: 'j', type: cont}, + {match: 'xion', replacement: 'ct', type: stop}, + {match: 'ion', replacement: '', type: cont}, + {match: 'ian', replacement: '', type: cont}, + {match: 'an', replacement: '', type: cont}, + {match: 'een', replacement: '', type: protect}, + {match: 'en', replacement: '', type: cont}, + {match: 'nn', replacement: 'n', type: stop} ], p: [ - {match: 'ship', replacement: '', type: CONTINUE}, - {match: 'pp', replacement: 'p', type: STOP} + {match: 'ship', replacement: '', type: cont}, + {match: 'pp', replacement: 'p', type: stop} ], r: [ - {match: 'er', replacement: '', type: CONTINUE}, - {match: 'ear', replacement: '', type: PROTECT}, - {match: 'ar', replacement: '', type: STOP}, - {match: 'ior', replacement: '', type: CONTINUE}, - {match: 'or', replacement: '', type: CONTINUE}, - {match: 'ur', replacement: '', type: CONTINUE}, - {match: 'rr', replacement: 'r', type: STOP}, - {match: 'tr', replacement: 't', type: CONTINUE}, - {match: 'ier', replacement: 'y', type: CONTINUE} + {match: 'er', replacement: '', type: cont}, + {match: 'ear', replacement: '', type: protect}, + {match: 'ar', replacement: '', type: stop}, + {match: 'ior', replacement: '', type: cont}, + {match: 'or', replacement: '', type: cont}, + {match: 'ur', replacement: '', type: cont}, + {match: 'rr', replacement: 'r', type: stop}, + {match: 'tr', replacement: 't', type: cont}, + {match: 'ier', replacement: 'y', type: cont} ], s: [ - {match: 'ies', replacement: 'y', type: CONTINUE}, - {match: 'sis', replacement: 's', type: STOP}, - {match: 'is', replacement: '', type: CONTINUE}, - {match: 'ness', replacement: '', type: CONTINUE}, - {match: 'ss', replacement: '', type: PROTECT}, - {match: 'ous', replacement: '', type: CONTINUE}, - {match: 'us', replacement: '', type: INTACT}, - {match: 's', replacement: '', type: CONTINUE}, - {match: 's', replacement: '', type: STOP} + {match: 'ies', replacement: 'y', type: cont}, + {match: 'sis', replacement: 's', type: stop}, + {match: 'is', replacement: '', type: cont}, + {match: 'ness', replacement: '', type: cont}, + {match: 'ss', replacement: '', type: protect}, + {match: 'ous', replacement: '', type: cont}, + {match: 'us', replacement: '', type: intact}, + {match: 's', replacement: '', type: cont}, + {match: 's', replacement: '', type: stop} ], t: [ - {match: 'plicat', replacement: 'ply', type: STOP}, - {match: 'at', replacement: '', type: CONTINUE}, - {match: 'ment', replacement: '', type: CONTINUE}, - {match: 'ent', replacement: '', type: CONTINUE}, - {match: 'ant', replacement: '', type: CONTINUE}, - {match: 'ript', replacement: 'rib', type: STOP}, - {match: 'orpt', replacement: 'orb', type: STOP}, - {match: 'duct', replacement: 'duc', type: STOP}, - {match: 'sumpt', replacement: 'sum', type: STOP}, - {match: 'cept', replacement: 'ceiv', type: STOP}, - {match: 'olut', replacement: 'olv', type: STOP}, - {match: 'sist', replacement: '', type: PROTECT}, - {match: 'ist', replacement: '', type: CONTINUE}, - {match: 'tt', replacement: 't', type: STOP} + {match: 'plicat', replacement: 'ply', type: stop}, + {match: 'at', replacement: '', type: cont}, + {match: 'ment', replacement: '', type: cont}, + {match: 'ent', replacement: '', type: cont}, + {match: 'ant', replacement: '', type: cont}, + {match: 'ript', replacement: 'rib', type: stop}, + {match: 'orpt', replacement: 'orb', type: stop}, + {match: 'duct', replacement: 'duc', type: stop}, + {match: 'sumpt', replacement: 'sum', type: stop}, + {match: 'cept', replacement: 'ceiv', type: stop}, + {match: 'olut', replacement: 'olv', type: stop}, + {match: 'sist', replacement: '', type: protect}, + {match: 'ist', replacement: '', type: cont}, + {match: 'tt', replacement: 't', type: stop} ], u: [ - {match: 'iqu', replacement: '', type: STOP}, - {match: 'ogu', replacement: 'og', type: STOP} + {match: 'iqu', replacement: '', type: stop}, + {match: 'ogu', replacement: 'og', type: stop} ], v: [ - {match: 'siv', replacement: 'j', type: CONTINUE}, - {match: 'eiv', replacement: '', type: PROTECT}, - {match: 'iv', replacement: '', type: CONTINUE} + {match: 'siv', replacement: 'j', type: cont}, + {match: 'eiv', replacement: '', type: protect}, + {match: 'iv', replacement: '', type: cont} ], y: [ - {match: 'bly', replacement: 'bl', type: CONTINUE}, - {match: 'ily', replacement: 'y', type: CONTINUE}, - {match: 'ply', replacement: '', type: PROTECT}, - {match: 'ly', replacement: '', type: CONTINUE}, - {match: 'ogy', replacement: 'og', type: STOP}, - {match: 'phy', replacement: 'ph', type: STOP}, - {match: 'omy', replacement: 'om', type: STOP}, - {match: 'opy', replacement: 'op', type: STOP}, - {match: 'ity', replacement: '', type: CONTINUE}, - {match: 'ety', replacement: '', type: CONTINUE}, - {match: 'lty', replacement: 'l', type: STOP}, - {match: 'istry', replacement: '', type: STOP}, - {match: 'ary', replacement: '', type: CONTINUE}, - {match: 'ory', replacement: '', type: CONTINUE}, - {match: 'ify', replacement: '', type: STOP}, - {match: 'ncy', replacement: 'nt', type: CONTINUE}, - {match: 'acy', replacement: '', type: CONTINUE} + {match: 'bly', replacement: 'bl', type: cont}, + {match: 'ily', replacement: 'y', type: cont}, + {match: 'ply', replacement: '', type: protect}, + {match: 'ly', replacement: '', type: cont}, + {match: 'ogy', replacement: 'og', type: stop}, + {match: 'phy', replacement: 'ph', type: stop}, + {match: 'omy', replacement: 'om', type: stop}, + {match: 'opy', replacement: 'op', type: stop}, + {match: 'ity', replacement: '', type: cont}, + {match: 'ety', replacement: '', type: cont}, + {match: 'lty', replacement: 'l', type: stop}, + {match: 'istry', replacement: '', type: stop}, + {match: 'ary', replacement: '', type: cont}, + {match: 'ory', replacement: '', type: cont}, + {match: 'ify', replacement: '', type: stop}, + {match: 'ncy', replacement: 'nt', type: cont}, + {match: 'acy', replacement: '', type: cont} ], z: [ - {match: 'iz', replacement: '', type: CONTINUE}, - {match: 'yz', replacement: 'ys', type: STOP} + {match: 'iz', replacement: '', type: cont}, + {match: 'yz', replacement: 'ys', type: stop} ] -}; +} function lancasterStemmer(value) { - return applyRules(String(value).toLowerCase(), true); + return applyRules(String(value).toLowerCase(), true) } -function applyRules(value, isIntact) { - var ruleset = rules[value.charAt(value.length - 1)]; - var breakpoint; - var index; - var length; - var rule; - var next; +function applyRules(value, isintact) { + var ruleset = rules[value.charAt(value.length - 1)] + var breakpoint + var index + var length + var rule + var next if (!ruleset) { - return value; + return value } - index = -1; - length = ruleset.length; + index = -1 + length = ruleset.length while (++index < length) { - rule = ruleset[index]; + rule = ruleset[index] - if (!isIntact && rule.type === INTACT) { - continue; + if (!isintact && rule.type === intact) { + continue } - breakpoint = value.length - rule.match.length; + breakpoint = value.length - rule.match.length if (breakpoint < 0 || value.substr(breakpoint) !== rule.match) { - continue; + continue } - if (rule.type === PROTECT) { - return value; + if (rule.type === protect) { + return value } - next = value.substr(0, breakpoint) + rule.replacement; + next = value.substr(0, breakpoint) + rule.replacement if (!acceptable(next)) { - continue; + continue } - if (rule.type === CONTINUE) { - return applyRules(next, false); + if (rule.type === cont) { + return applyRules(next, false) } - return next; + return next } - return value; + return value } -/* Detect if a value is acceptable to return, or should - * be stemmed further. */ +// Detect if a value is acceptable to return, or should be stemmed further. function acceptable(value) { - return VOWELS.test(value.charAt(0)) ? - value.length > 1 : value.length > 2 && VOWELS.test(value); + return vowels.test(value.charAt(0)) + ? value.length > 1 + : value.length > 2 && vowels.test(value) } diff --git a/package.json b/package.json index c3f4cd8..9ce65b0 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "browserify": "^16.0.0", "execa": "^1.0.0", "nyc": "^13.0.0", + "prettier": "^1.14.2", "remark-cli": "^5.0.0", "remark-preset-wooorm": "^4.0.0", "tape": "^4.4.0", @@ -36,14 +37,13 @@ "xo": "^0.22.0" }, "scripts": { - "build-md": "remark . -qfo", + "format": "remark . -qfo && prettier --write \"**/*.js\" && 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-md && npm run build-bundle && npm run build-mangle", - "lint": "xo", + "build": "npm run build-bundle && npm run build-mangle", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run build && npm run lint && npm run test-coverage" + "test": "npm run format && npm run build && npm run test-coverage" }, "nyc": { "check-coverage": true, @@ -51,8 +51,16 @@ "functions": 100, "branches": 100 }, + "prettier": { + "tabWidth": 2, + "useTabs": false, + "singleQuote": true, + "bracketSpacing": false, + "semi": false, + "trailingComma": "none" + }, "xo": { - "space": true, + "prettier": true, "esnext": false, "rules": { "unicorn/prefer-starts-ends-with": "off", diff --git a/readme.md b/readme.md index 82b4910..e878d52 100644 --- a/readme.md +++ b/readme.md @@ -13,16 +13,16 @@ npm install lancaster-stemmer Use: ```js -var lancasterStemmer = require('lancaster-stemmer'); +var lancasterStemmer = require('lancaster-stemmer') -lancasterStemmer('considerations'); //=> 'consid' -lancasterStemmer('detestable'); //=> 'detest' -lancasterStemmer('vileness'); //=> 'vil' -lancasterStemmer('giggling'); //=> 'giggl' -lancasterStemmer('anxious'); //=> 'anxy' +lancasterStemmer('considerations') // => 'consid' +lancasterStemmer('detestable') // => 'detest' +lancasterStemmer('vileness') // => 'vil' +lancasterStemmer('giggling') // => 'giggl' +lancasterStemmer('anxious') // => 'anxy' -/* Case insensitive */ -lancasterStemmer('analytic') === lancasterStemmer('AnAlYtIc'); //=> true +// Case insensitive +lancasterStemmer('analytic') === lancasterStemmer('AnAlYtIc') // => true ``` ## CLI diff --git a/test.js b/test.js index d68f4fb..7595c24 100644 --- a/test.js +++ b/test.js @@ -1,293 +1,299 @@ -'use strict'; +'use strict' -var PassThrough = require('stream').PassThrough; -var test = require('tape'); -var execa = require('execa'); -var version = require('./package').version; -var stemmer = require('.'); +var PassThrough = require('stream').PassThrough +var test = require('tape') +var execa = require('execa') +var pack = require('./package') +var stemmer = require('.') -test('api', function (t) { - t.equal(stemmer('analytic'), stemmer('AnAlYtIc'), 'should be case insensitive'); +test('api', function(t) { + t.equal( + stemmer('analytic'), + stemmer('AnAlYtIc'), + 'should be case insensitive' + ) - t.equal(stemmer(''), '', 'should not fail on empy inputs'); + t.equal(stemmer(''), '', 'should not fail on empy inputs') - t.notOk(/ia$/.test(stemmer('abasia'), 'should drop ia$')); + t.notOk(/ia$/.test(stemmer('abasia'), 'should drop ia$')) - t.notOk(/a$/.test(stemmer('abaya')), 'should drop a$'); + t.notOk(/a$/.test(stemmer('abaya')), 'should drop a$') - t.ok(/[^b]b$/.test(stemmer('ebb')), 'should transform bb$ into b'); + t.ok(/[^b]b$/.test(stemmer('ebb')), 'should transform bb$ into b') - t.ok(/ys$/.test(stemmer('analytic')), 'should transform ytic$ into ys'); + t.ok(/ys$/.test(stemmer('analytic')), 'should transform ytic$ into ys') - t.notOk(/ic$/.test(stemmer('zymotic')), 'should drop ic$'); + t.notOk(/ic$/.test(stemmer('zymotic')), 'should drop ic$') - t.ok(/nt$/.test(stemmer('franc')), 'should transform nc$ into nt'); + t.ok(/nt$/.test(stemmer('franc')), 'should transform nc$ into nt') - t.ok(/[^d]d$/.test(stemmer('add')), 'should transform dd$ into d'); + t.ok(/[^d]d$/.test(stemmer('add')), 'should transform dd$ into d') - t.ok(/y$/.test(stemmer('aeried')), 'should transform ied$ into y'); + t.ok(/y$/.test(stemmer('aeried')), 'should transform ied$ into y') - t.ok(/cess$/.test(stemmer('exceed')), 'should transform ceed$ into cess'); + t.ok(/cess$/.test(stemmer('exceed')), 'should transform ceed$ into cess') - t.ok(/ee$/.test(stemmer('zeed')), 'should transform eed$ into ee'); + t.ok(/ee$/.test(stemmer('zeed')), 'should transform eed$ into ee') - t.notOk(/ed$/.test(stemmer('bowed')), 'should drop ed$'); + t.notOk(/ed$/.test(stemmer('bowed')), 'should drop ed$') - t.notOk(/hood$/.test(stemmer('boyhood')), 'should drop hood$'); + t.notOk(/hood$/.test(stemmer('boyhood')), 'should drop hood$') - t.notOk(/e$/.test(stemmer('brae')), 'should drop e$'); + t.notOk(/e$/.test(stemmer('brae')), 'should drop e$') - t.ok(/liev$/.test(stemmer('disbelief')), 'should transform lief$ into liev'); + t.ok(/liev$/.test(stemmer('disbelief')), 'should transform lief$ into liev') - t.notOk(/if$/.test(stemmer('khalif')), 'should drop if$'); + t.notOk(/if$/.test(stemmer('khalif')), 'should drop if$') - t.notOk(/ing$/.test(stemmer('giggling')), 'should drop ing$'); + t.notOk(/ing$/.test(stemmer('giggling')), 'should drop ing$') - /* `es$` is also removed */ - t.ok(/y$/.test(stemmer('intermarriages')), 'should transform iag$ into y'); + // `es$` is also removed. + t.ok(/y$/.test(stemmer('intermarriages')), 'should transform iag$ into y') - t.notOk(/ag$/.test(stemmer('jetlag')), 'should drop ag$'); + t.notOk(/ag$/.test(stemmer('jetlag')), 'should drop ag$') - t.ok(/[^g]g$/.test(stemmer('magg')), 'should transform gg$ into g'); + t.ok(/[^g]g$/.test(stemmer('magg')), 'should transform gg$ into g') - t.notOk(/th$/.test(stemmer('mammoth')), 'should drop th$'); + t.notOk(/th$/.test(stemmer('mammoth')), 'should drop th$') - t.ok(/ct$/.test(stemmer('aguish')), 'should transform guish$ into ct'); + t.ok(/ct$/.test(stemmer('aguish')), 'should transform guish$ into ct') - t.notOk(/ish$/.test(stemmer('angelfish')), 'should drop ish$'); + t.notOk(/ish$/.test(stemmer('angelfish')), 'should drop ish$') - t.notOk(/i$/.test(stemmer('anti')), 'should drop i$'); + t.notOk(/i$/.test(stemmer('anti')), 'should drop i$') - /* The ous$ will first remove, then the transformation */ - t.ok(/y$/.test(stemmer('anxious')), 'should transform i$ into y'); + // The ous$ will first remove, then the transformation. + t.ok(/y$/.test(stemmer('anxious')), 'should transform i$ into y') - t.ok(/id$/.test(stemmer('basij')), 'should transform ij$ into id'); + t.ok(/id$/.test(stemmer('basij')), 'should transform ij$ into id') - /* sion > j, fuj > fus */ - t.ok(/fus$/.test(stemmer('affusion')), 'should transform fuj$ into fus'); + // sion > j, fuj > fus. + t.ok(/fus$/.test(stemmer('affusion')), 'should transform fuj$ into fus') - /* sion > j, uj > ud */ - t.ok(/ud$/.test(stemmer('collusion')), 'should transform uj$ into ud'); + // sion > j, uj > ud. + t.ok(/ud$/.test(stemmer('collusion')), 'should transform uj$ into ud') - /* sion > j, oj > od */ - t.ok(/od$/.test(stemmer('corrosion')), 'should transform oj$ into od'); + // sion > j, oj > od. + t.ok(/od$/.test(stemmer('corrosion')), 'should transform oj$ into od') - /* sion > j, hej > her */ - t.ok(/her$/.test(stemmer('adhesion')), 'should transform hej$ into her'); + // sion > j, hej > her. + t.ok(/her$/.test(stemmer('adhesion')), 'should transform hej$ into her') - /* sion > j, verj > vert */ - t.ok(/vert$/.test(stemmer('version')), 'should transform verj$ into vert'); + // sion > j, verj > vert. + t.ok(/vert$/.test(stemmer('version')), 'should transform verj$ into vert') - /* sion > j, misj > mit */ - /* For some unknown reason the original code returns `misj` */ - t.ok(/mit$/.test(stemmer('mission')), 'should transform misj$ into mit'); + // sion > j, misj > mit. + // For some unknown reason the original code returns `misj`. + t.ok(/mit$/.test(stemmer('mission')), 'should transform misj$ into mit') - /* sion > j, nj > nd */ - t.ok(/nd$/.test(stemmer('comprehension')), 'should transform nj$ into nd'); + // sion > j, nj > nd. + t.ok(/nd$/.test(stemmer('comprehension')), 'should transform nj$ into nd') - t.ok(/s$/.test(stemmer('svaraj')), 'should transform j$ into s'); + t.ok(/s$/.test(stemmer('svaraj')), 'should transform j$ into s') - t.notOk(/ifiabl$/.test(stemmer('classifiable')), 'should drop ifiabl$'); + t.notOk(/ifiabl$/.test(stemmer('classifiable')), 'should drop ifiabl$') - t.ok(/y$/.test(stemmer('compliable')), 'should transform iabl$ into y'); + t.ok(/y$/.test(stemmer('compliable')), 'should transform iabl$ into y') - t.notOk(/abl$/.test(stemmer('compostable')), 'should drop abl$'); + t.notOk(/abl$/.test(stemmer('compostable')), 'should drop abl$') - t.notOk(/ibl$/.test(stemmer('conductible')), 'should drop ibl$'); + t.notOk(/ibl$/.test(stemmer('conductible')), 'should drop ibl$') - t.ok(/bl$/.test(stemmer('airmobile')), 'should transform bil$ into bl'); + t.ok(/bl$/.test(stemmer('airmobile')), 'should transform bil$ into bl') - t.ok(/c$/.test(stemmer('curricle')), 'should transform cl$ into c'); + t.ok(/c$/.test(stemmer('curricle')), 'should transform cl$ into c') - t.ok(/y$/.test(stemmer('beautiful')), 'should transform iful$ into y'); + t.ok(/y$/.test(stemmer('beautiful')), 'should transform iful$ into y') - t.notOk(/ful$/.test(stemmer('behoveful')), 'should drop ful$'); + t.notOk(/ful$/.test(stemmer('behoveful')), 'should drop ful$') - t.notOk(/ul$/.test(stemmer('blameful')), 'should drop ul$'); + t.notOk(/ul$/.test(stemmer('blameful')), 'should drop ul$') - t.notOk(/ial$/.test(stemmer('akenial')), 'should drop ial$'); + t.notOk(/ial$/.test(stemmer('akenial')), 'should drop ial$') - t.notOk(/ual$/.test(stemmer('annual')), 'should drop ual$'); + t.notOk(/ual$/.test(stemmer('annual')), 'should drop ual$') - t.notOk(/al$/.test(stemmer('anodal')), 'should drop al$'); + t.notOk(/al$/.test(stemmer('anodal')), 'should drop al$') - t.ok(/[^l]l$/.test(stemmer('anthill')), 'should transform ll$ into l'); + t.ok(/[^l]l$/.test(stemmer('anthill')), 'should transform ll$ into l') - t.notOk(/ium$/.test(stemmer('anthodium')), 'should drop ium$'); + t.notOk(/ium$/.test(stemmer('anthodium')), 'should drop ium$') - t.notOk(/um$/.test(stemmer('antirrhinum')), 'should drop um$'); + t.notOk(/um$/.test(stemmer('antirrhinum')), 'should drop um$') - t.notOk(/ism$/.test(stemmer('apism')), 'should drop ism$'); + t.notOk(/ism$/.test(stemmer('apism')), 'should drop ism$') - t.ok(/[^m]m$/.test(stemmer('shtumm')), 'should transform mm$ into m'); + t.ok(/[^m]m$/.test(stemmer('shtumm')), 'should transform mm$ into m') - /* Untestable, although the `j` tests also test this */ + // Untestable, although the `j` test tests this also. // 'should transform sion$ into j' - t.ok(/ct$/.test(stemmer('affluxion')), 'should transform xion$ into ct'); + t.ok(/ct$/.test(stemmer('affluxion')), 'should transform xion$ into ct') - t.notOk(/ion$/.test(stemmer('alation')), 'should drop ion$'); + t.notOk(/ion$/.test(stemmer('alation')), 'should drop ion$') - t.notOk(/ian$/.test(stemmer('abecedarian')), 'should drop ian$'); + t.notOk(/ian$/.test(stemmer('abecedarian')), 'should drop ian$') - t.notOk(/an$/.test(stemmer('acaridan')), 'should drop an$'); + t.notOk(/an$/.test(stemmer('acaridan')), 'should drop an$') - t.ok(/een$/.test(stemmer('armozeen')), 'should protect een$'); + t.ok(/een$/.test(stemmer('armozeen')), 'should protect een$') - t.notOk(/en$/.test(stemmer('bandsmen')), 'should drop en$'); + t.notOk(/en$/.test(stemmer('bandsmen')), 'should drop en$') - t.ok(/[^n]n$/.test(stemmer('jotunn')), 'should transform nn$ into n'); + t.ok(/[^n]n$/.test(stemmer('jotunn')), 'should transform nn$ into n') - t.notOk(/ship$/.test(stemmer('judgeship')), 'should drop ship$'); + t.notOk(/ship$/.test(stemmer('judgeship')), 'should drop ship$') - t.ok(/[^p]p$/.test(stemmer('schlepp')), 'should transform pp$ into p'); + t.ok(/[^p]p$/.test(stemmer('schlepp')), 'should transform pp$ into p') - t.notOk(/er$/.test(stemmer('teacher')), 'should drop er$'); + t.notOk(/er$/.test(stemmer('teacher')), 'should drop er$') - t.ok(/ear$/.test(stemmer('shapewear')), 'should protect ear$'); + t.ok(/ear$/.test(stemmer('shapewear')), 'should protect ear$') - t.notOk(/ar$/.test(stemmer('alcazar')), 'should drop ar$'); + t.notOk(/ar$/.test(stemmer('alcazar')), 'should drop ar$') - t.notOk(/ior$/.test(stemmer('superior')), 'should drop ior$'); + t.notOk(/ior$/.test(stemmer('superior')), 'should drop ior$') - t.notOk(/or$/.test(stemmer('advisor')), 'should drop or$'); + t.notOk(/or$/.test(stemmer('advisor')), 'should drop or$') - t.notOk(/ur$/.test(stemmer('tailleur')), 'should drop ur$'); + t.notOk(/ur$/.test(stemmer('tailleur')), 'should drop ur$') - t.ok(/[^r]r$/.test(stemmer('whirr')), 'should transform rr$ into r'); + t.ok(/[^r]r$/.test(stemmer('whirr')), 'should transform rr$ into r') - t.ok(/t$/.test(stemmer('accipitral')), 'should transform tr$ into t'); + t.ok(/t$/.test(stemmer('accipitral')), 'should transform tr$ into t') - t.ok(/y$/.test(stemmer('aerier')), 'should transform ier$ into y'); + t.ok(/y$/.test(stemmer('aerier')), 'should transform ier$ into y') - t.ok(/y$/.test(stemmer('abbotcies')), 'should transform ies$ into y'); + t.ok(/y$/.test(stemmer('abbotcies')), 'should transform ies$ into y') - t.ok(/s$/.test(stemmer('abiosis')), 'should transform sis$ into s'); + t.ok(/s$/.test(stemmer('abiosis')), 'should transform sis$ into s') - t.notOk(/is$/.test(stemmer('abris')), 'should drop is$'); + t.notOk(/is$/.test(stemmer('abris')), 'should drop is$') - t.notOk(/ness$/.test(stemmer('abruptness')), 'should drop ness$'); + t.notOk(/ness$/.test(stemmer('abruptness')), 'should drop ness$') - t.ok(/ss$/.test(stemmer('abyss')), 'should protect ss$'); + t.ok(/ss$/.test(stemmer('abyss')), 'should protect ss$') - t.notOk(/ous$/.test(stemmer('acetous')), 'should drop ous$'); + t.notOk(/ous$/.test(stemmer('acetous')), 'should drop ous$') - t.notOk(/us$/.test(stemmer('acinus')), 'should drop us$'); + t.notOk(/us$/.test(stemmer('acinus')), 'should drop us$') - t.notOk(/s$/.test(stemmer('abacs')), 'should drop s$'); + t.notOk(/s$/.test(stemmer('abacs')), 'should drop s$') - t.ok(/ply$/.test(stemmer('supplicat')), 'should transform plicat$ into ply'); + t.ok(/ply$/.test(stemmer('supplicat')), 'should transform plicat$ into ply') - t.notOk(/at$/.test(stemmer('surat')), 'should drop at$'); + t.notOk(/at$/.test(stemmer('surat')), 'should drop at$') - t.notOk(/ment$/.test(stemmer('tanglement')), 'should drop ment$'); + t.notOk(/ment$/.test(stemmer('tanglement')), 'should drop ment$') - t.notOk(/ent$/.test(stemmer('temperament')), 'should drop ent$'); + t.notOk(/ent$/.test(stemmer('temperament')), 'should drop ent$') - t.notOk(/ant$/.test(stemmer('tenant')), 'should drop ant$'); + t.notOk(/ant$/.test(stemmer('tenant')), 'should drop ant$') - t.ok(/rib$/.test(stemmer('transcript')), 'should transform ript$ into rib'); + t.ok(/rib$/.test(stemmer('transcript')), 'should transform ript$ into rib') - t.ok(/orb$/.test(stemmer('absorptance')), 'should transform orpt$ into orb'); + t.ok(/orb$/.test(stemmer('absorptance')), 'should transform orpt$ into orb') - t.ok(/duc$/.test(stemmer('aeroduct')), 'should transform duct$ into duc'); + t.ok(/duc$/.test(stemmer('aeroduct')), 'should transform duct$ into duc') - t.ok(/sum$/.test(stemmer('consumpt')), 'should transform sumpt$ into sum'); + t.ok(/sum$/.test(stemmer('consumpt')), 'should transform sumpt$ into sum') - t.ok(/ceiv$/.test(stemmer('discept')), 'should transform cept$ into ceiv'); + t.ok(/ceiv$/.test(stemmer('discept')), 'should transform cept$ into ceiv') - t.ok(/olv$/.test(stemmer('absolute')), 'should transform olut$ into olv'); + t.ok(/olv$/.test(stemmer('absolute')), 'should transform olut$ into olv') - t.ok(/sist$/.test(stemmer('fantasist')), 'should protect sist$'); + t.ok(/sist$/.test(stemmer('fantasist')), 'should protect sist$') - t.notOk(/ist$/.test(stemmer('fashionist')), 'should drop ist$'); + t.notOk(/ist$/.test(stemmer('fashionist')), 'should drop ist$') - t.ok(/[^t]t$/.test(stemmer('forebitt')), 'should transform tt$ into t'); + t.ok(/[^t]t$/.test(stemmer('forebitt')), 'should transform tt$ into t') - t.notOk(/iqu$/.test(stemmer('antiquity')), 'should drop iqu$'); + t.notOk(/iqu$/.test(stemmer('antiquity')), 'should drop iqu$') - t.ok(/og$/.test(stemmer('trialogue')), 'should transform ogu$ into og'); + t.ok(/og$/.test(stemmer('trialogue')), 'should transform ogu$ into og') - /* Untestable, although the `j` tests also test this */ + // Untestable, although the `j` test tests this also. // 'should transform siv$ into j' - t.ok(/eiv$/.test(stemmer('apperceive')), 'should protect eiv$'); + t.ok(/eiv$/.test(stemmer('apperceive')), 'should protect eiv$') - t.notOk(/iv$/.test(stemmer('leitmotiv')), 'should drop iv$'); + t.notOk(/iv$/.test(stemmer('leitmotiv')), 'should drop iv$') - t.ok(/bl$/.test(stemmer('amble')), 'should transform bly$ into bl'); + t.ok(/bl$/.test(stemmer('amble')), 'should transform bly$ into bl') - t.ok(/y$/.test(stemmer('aerily')), 'should transform ily$ into y'); + t.ok(/y$/.test(stemmer('aerily')), 'should transform ily$ into y') - t.ok(/ply$/.test(stemmer('misapply')), 'should protect ply$'); + t.ok(/ply$/.test(stemmer('misapply')), 'should protect ply$') - t.notOk(/ly$/.test(stemmer('miscellaneously')), 'should drop ly$'); + t.notOk(/ly$/.test(stemmer('miscellaneously')), 'should drop ly$') - t.ok(/og$/.test(stemmer('misology')), 'should transform ogy$ into og'); + t.ok(/og$/.test(stemmer('misology')), 'should transform ogy$ into og') - t.ok(/ph$/.test(stemmer('morphography')), 'should transform phy$ into ph'); + t.ok(/ph$/.test(stemmer('morphography')), 'should transform phy$ into ph') - t.ok(/om$/.test(stemmer('neurotomy')), 'should transform omy$ into om'); + t.ok(/om$/.test(stemmer('neurotomy')), 'should transform omy$ into om') - t.ok(/op$/.test(stemmer('otoscopy')), 'should transform opy$ into op'); + t.ok(/op$/.test(stemmer('otoscopy')), 'should transform opy$ into op') - t.notOk(/ity$/.test(stemmer('outcity')), 'should drop ity$'); + t.notOk(/ity$/.test(stemmer('outcity')), 'should drop ity$') - t.notOk(/ety$/.test(stemmer('peripety')), 'should drop ety$'); + t.notOk(/ety$/.test(stemmer('peripety')), 'should drop ety$') - t.ok(/l$/.test(stemmer('realty')), 'should transform lty$ into l'); + t.ok(/l$/.test(stemmer('realty')), 'should transform lty$ into l') - t.notOk(/istry$/.test(stemmer('registry')), 'should drop istry$'); + t.notOk(/istry$/.test(stemmer('registry')), 'should drop istry$') - t.notOk(/ary$/.test(stemmer('repetitionary')), 'should drop ary$'); + t.notOk(/ary$/.test(stemmer('repetitionary')), 'should drop ary$') - t.notOk(/ory$/.test(stemmer('repository')), 'should drop ory$'); + t.notOk(/ory$/.test(stemmer('repository')), 'should drop ory$') - t.notOk(/ify$/.test(stemmer('requalify')), 'should drop ify$'); + t.notOk(/ify$/.test(stemmer('requalify')), 'should drop ify$') - t.ok(/nt$/.test(stemmer('bouncy')), 'should transform ncy$ into nt'); + t.ok(/nt$/.test(stemmer('bouncy')), 'should transform ncy$ into nt') - t.notOk(/acy$/.test(stemmer('retiracy')), 'should drop acy$'); + t.notOk(/acy$/.test(stemmer('retiracy')), 'should drop acy$') - t.notOk(/iz$/.test(stemmer('showbiz')), 'should drop iz$'); + t.notOk(/iz$/.test(stemmer('showbiz')), 'should drop iz$') - t.ok(/ys$/.test(stemmer('agryze')), 'should transform yz$ into ys'); + t.ok(/ys$/.test(stemmer('agryze')), 'should transform yz$ into ys') - t.end(); -}); + t.end() +}) -test('cli', function (t) { - var input = new PassThrough(); +test('cli', function(t) { + var input = new PassThrough() + var version = ['-v', '--version'] + var help = ['-h', '--help'] - t.plan(7); + t.plan(7) - execa.stdout('./cli.js', ['considerations']).then(function (result) { - t.equal(result, 'consid', 'argument'); - }); + execa.stdout('./cli.js', ['considerations']).then(function(result) { + t.equal(result, 'consid', 'argument') + }) - execa.stdout('./cli.js', ['detestable', 'vileness']).then(function (result) { - t.equal(result, 'detest vil', 'arguments'); - }); + execa.stdout('./cli.js', ['detestable', 'vileness']).then(function(result) { + t.equal(result, 'detest vil', 'arguments') + }) - execa.stdout('./cli.js', {input: input}).then(function (result) { - t.equal(result, 'detest vil', 'stdin'); - }); + execa.stdout('./cli.js', {input: input}).then(function(result) { + t.equal(result, 'detest vil', 'stdin') + }) - input.write('detestable'); + input.write('detestable') - setImmediate(function () { - input.end(' vileness'); - }); + setImmediate(function() { + input.end(' vileness') + }) - ['-h', '--help'].forEach(function (flag) { - execa.stdout('./cli.js', [flag]).then(function (result) { - t.ok(/\s+Usage: lancaster-stemmer/.test(result), flag); - }); - }); + help.forEach(function(flag) { + execa.stdout('./cli.js', [flag]).then(function(result) { + t.ok(/\s+Usage: lancaster-stemmer/.test(result), flag) + }) + }) - ['-v', '--version'].forEach(function (flag) { - execa.stdout('./cli.js', [flag]).then(function (result) { - t.equal(result, version, flag); - }); - }); -}); + version.forEach(function(flag) { + execa.stdout('./cli.js', [flag]).then(function(result) { + t.equal(result, pack.version, flag) + }) + }) +})