Comparing version 1.0.5 to 2.0.0
24
cli.js
#!/usr/bin/env node | ||
'use strict' | ||
import fs from 'fs' | ||
import {URL} from 'url' | ||
import {stemmer} from './index.js' | ||
var pack = require('./package.json') | ||
var stemmer = require('.') | ||
/** @type {Object.<string, unknown>} */ | ||
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) | ||
@@ -16,4 +20,4 @@ } else if (argv.length === 0) { | ||
process.stdin.setEncoding('utf8') | ||
process.stdin.on('data', function(data) { | ||
console.log(stem(data)) | ||
process.stdin.on('data', function (data) { | ||
console.log(stem(String(data))) | ||
}) | ||
@@ -24,6 +28,10 @@ } else { | ||
/** | ||
* @param {string} values | ||
* @returns {string} | ||
*/ | ||
function stem(values) { | ||
return values | ||
.split(/\s+/g) | ||
.map(stemmer) | ||
.map((d) => stemmer(d)) | ||
.join(' ') | ||
@@ -30,0 +38,0 @@ } |
26
index.js
@@ -1,5 +0,1 @@ | ||
'use strict' | ||
module.exports = stemmer | ||
// Standard suffix manipulations. | ||
@@ -69,6 +65,12 @@ var step2list = { | ||
// Stem `value`. | ||
// eslint-disable-next-line complexity | ||
function stemmer(value) { | ||
/** | ||
* Stem `value`. | ||
* | ||
* @param {string} value | ||
* @returns {string} | ||
*/ | ||
export function stemmer(value) { | ||
/** @type {boolean} */ | ||
var firstCharacterWasLowerCaseY | ||
/** @type {RegExpMatchArray} */ | ||
var match | ||
@@ -94,6 +96,6 @@ | ||
// Remove last two characters. | ||
value = value.slice(0, value.length - 2) | ||
value = value.slice(0, -2) | ||
} else if (sfxS.test(value)) { | ||
// Remove last character. | ||
value = value.slice(0, value.length - 1) | ||
value = value.slice(0, -1) | ||
} | ||
@@ -105,3 +107,3 @@ | ||
// Remove last character. | ||
value = value.slice(0, value.length - 1) | ||
value = value.slice(0, -1) | ||
} | ||
@@ -116,3 +118,3 @@ } else if ((match = sfxEdOrIng.exec(value)) && vowelInStem.test(match[1])) { | ||
// Remove last character. | ||
value = value.slice(0, value.length - 1) | ||
value = value.slice(0, -1) | ||
} else if (consonantLike.test(value)) { | ||
@@ -159,3 +161,3 @@ // Append `e`. | ||
if (sfxLl.test(value) && gt1.test(value)) { | ||
value = value.slice(0, value.length - 1) | ||
value = value.slice(0, -1) | ||
} | ||
@@ -162,0 +164,0 @@ |
{ | ||
"name": "stemmer", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"description": "Porter Stemmer algorithm", | ||
@@ -25,34 +25,32 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"bin": "cli.js", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"cli.js" | ||
"cli.js", | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"bin": "cli.js", | ||
"main": "index.js", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify": "^16.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.0.0", | ||
"xo": "^0.25.0" | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.38.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s stemmer > stemmer.js", | ||
"build-mangle": "browserify . -s stemmer -p tinyify > stemmer.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test/index.js", | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
"prepack": "npm run build && npm run format", | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node test/index.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -68,9 +66,7 @@ "tabWidth": 2, | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"unicorn/prefer-includes": "off" | ||
}, | ||
"ignores": [ | ||
"stemmer.js" | ||
] | ||
"complexity": "off", | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
@@ -81,3 +77,8 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true | ||
} | ||
} |
@@ -12,2 +12,5 @@ # stemmer | ||
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed | ||
instead of `require`d. | ||
[npm][]: | ||
@@ -21,4 +24,7 @@ | ||
This package exports the following identifiers: `stemmer`. | ||
There is no default export. | ||
```js | ||
var stemmer = require('stemmer') | ||
import {stemmer} from 'stemmer' | ||
@@ -78,5 +84,5 @@ stemmer('considerations') // => 'consider' | ||
[build-badge]: https://img.shields.io/travis/words/stemmer.svg | ||
[build-badge]: https://github.com/words/stemmer/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/words/stemmer | ||
[build]: https://github.com/words/stemmer/actions | ||
@@ -83,0 +89,0 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/words/stemmer.svg |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10932
6
211
105
Yes
10
2