produce-package-keywords
Advanced tools
Comparing version 1.0.3 to 1.1.4
{ | ||
"name": "produce-package-keywords", | ||
"version": "1.0.3", | ||
"version": "1.1.4", | ||
"description": "Produces keywords for a package by analyzing its package.json, readme and/or given file's text", | ||
"main": "index.js", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"tape": "tape test/*.js", | ||
"babel": "babel src -d .", | ||
"lint": "eslint --fix src", | ||
"postpublish": "npm run clean", | ||
"tape": "tape src/test/*.js | tap-spec", | ||
"clean": "rimraf coverage .nyc_output coverage.lcov", | ||
"test": "npm run lint && nyc npm run tape", | ||
"posttest": "npm run coverage", | ||
"test": "npm run babel && nyc npm run tape", | ||
"prepublish": "npm t && npm run clean && npm run babel", | ||
"clean": "rimraf index.js test coverage .nyc_output coverage.lcov", | ||
"prepublish": "npm t && npm run clean", | ||
"postpublish": "git commit -a -m && git push github master", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
@@ -35,22 +34,3 @@ }, | ||
"homepage": "https://github.com/mrzmmr/produce-package-keywords#readme", | ||
"babel": { | ||
"presets": [ | ||
"env" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"parser": "babel-eslint", | ||
"env": { | ||
"node": true | ||
}, | ||
"extends": "standard", | ||
"plugins": [ | ||
"standard", | ||
"promise" | ||
] | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.22.2", | ||
"babel-eslint": "^7.1.1", | ||
"babel-preset-env": "^1.1.8", | ||
"codecov": "^1.0.1", | ||
@@ -63,5 +43,7 @@ "eslint": "^3.14.0", | ||
"rimraf": "^2.5.4", | ||
"tape": "^4.6.3" | ||
"tape": "^4.6.3", | ||
"tap-spec": "^4.1.1" | ||
}, | ||
"dependencies": { | ||
"fs-exists-sync": "^0.1.0", | ||
"nlcst-to-string": "^2.0.0", | ||
@@ -68,0 +50,0 @@ "retext": "^4.0.0", |
@@ -41,2 +41,3 @@ # produce-package-keywords | ||
- [is-file](https://github.com/jsdevel/node-is-file): Tests if a given path resolves to a file. | ||
- [nlcst-to-string](https://github.com/wooorm/nlcst-to-string): Stringify NLCST | ||
@@ -48,5 +49,2 @@ - [retext](https://github.com/wooorm/retext/tree/master/packages): Natural language processor powered by plugins | ||
- [babel-cli](https://github.com/babel/babel/tree/master/packages): Babel command line. | ||
- [babel-eslint](https://github.com/babel/babel-eslint): Custom parser for ESLint | ||
- [babel-preset-env](https://github.com/babel/babel-preset-env): A Babel preset for each environment. | ||
- [codecov](https://github.com/codecov/codecov-node): Uploading report to Codecov: https://codecov.io | ||
@@ -60,2 +58,3 @@ - [eslint](https://github.com/eslint/eslint): An AST-based pattern checker for JavaScript. | ||
- [tape](https://github.com/substack/tape): tap-producing test harness for node and browsers | ||
- [tap-spec](https://github.com/scottcorgan/tap-spec): Formatted TAP output like Mocha's spec reporter | ||
@@ -69,2 +68,1 @@ ## Contribute | ||
MIT © mrzmmr | ||
@@ -7,13 +7,14 @@ 'use strict' | ||
const retextKeywords = require('retext-keywords') | ||
const nlcstToString = require('nlcst-to-string') | ||
// const isThere = require('is-there') | ||
const retext = require('retext') | ||
// const path = require('path') | ||
const fs = require('fs') | ||
var retextKeywords = require('retext-keywords') | ||
var nlcstToString = require('nlcst-to-string') | ||
var exists = require('fs-exists-sync') | ||
var retext = require('retext') | ||
var fs = require('fs') | ||
require('babel-polyfill') | ||
var stringFromFile = function (input, callback) { | ||
if (!exists(input)) { | ||
return callback(null, input) | ||
} | ||
const producePackageKeywords = module.exports = (_file, options, callback) => { | ||
return fs.readFile(_file, 'utf-8', (error, string) => { | ||
return fs.readFile(input, 'utf-8', function (error, string) { | ||
if (error) { | ||
@@ -23,58 +24,32 @@ return callback(error) | ||
return retext().use(retextKeywords).process(string, (error, file) => { | ||
if (error) { | ||
return callback(error) | ||
} | ||
const keywords = file.data.keywords.map((keyword) => { | ||
return nlcstToString(keyword.matches[0].node) | ||
}) | ||
const keyphrases = file.data.keyphrases.map((phrase) => { | ||
return phrase.matches[0].nodes.map(nlcstToString).join('') | ||
}) | ||
return callback(null, {keywords: keywords, keyphrases: keyphrases}) | ||
}) | ||
return callback(null, string) | ||
}) | ||
} | ||
/* | ||
const extractKeywords = (file) => { | ||
return new Promise((resolve) => { | ||
return resolve(file.data.keywords.map((keyword) => { | ||
return nlcstToString(keyword.matches[0].node) | ||
})) | ||
var pullKeywords = function (file) { | ||
return file.data.keywords.map(function (keyword) { | ||
return nlcstToString(keyword.matches[0].node) | ||
}) | ||
} | ||
const extractKeyphrases = (file) => { | ||
return new Promise((resolve) => { | ||
return resolve(file.data.keyphrases.map((keyphrases) => { | ||
return keyphrases.matches[0].nodes.map(nlcstToString).join('') | ||
})) | ||
var pullKeyphrases = function (file) { | ||
return file.data.keyphrases.map(function (phrase) { | ||
return phrase.matches[0].nodes.map(nlcstToString).join('') | ||
}) | ||
} | ||
const readfile = (_file) => { | ||
const file = path.resolve(_file) | ||
var process = function (input, callback) { | ||
return stringFromFile(input, function (error, string) { | ||
if (error) { | ||
return callback(error) | ||
} | ||
return new Promise((resolve, reject) => { | ||
return fs.readFile(file, 'utf-8', (error, string) => { | ||
return retext().use(retextKeywords).process(string, function (error, file) { | ||
if (error) { | ||
return reject(error) | ||
} else { | ||
return resolve(string) | ||
return callback(error) | ||
} | ||
}) | ||
}) | ||
} | ||
const getRetextFile = (string) => { | ||
return new Promise((resolve, reject) => { | ||
return retext().use(retextKeywords).process(string, (error, file) => { | ||
if (error) { | ||
return reject(error) | ||
} else { | ||
return resolve(file) | ||
return { | ||
keyphrases: pullKeyphrases(file), | ||
keywords: pullKeywords(file) | ||
} | ||
@@ -85,17 +60,7 @@ }) | ||
const producePackageKeywords = module.exports = async (path, options) => { | ||
try { | ||
const data = await readfile(path, 'UTF-8') | ||
const file = await getRetextFile(data) | ||
const keyphrases = await extractKeyphrases(file) | ||
const keywords = await extractKeywords(file) | ||
return { | ||
keyphrases: keyphrases, | ||
keywords: keywords | ||
} | ||
} catch (error) { | ||
throw error | ||
} | ||
module.exports = { | ||
stringFromFile: stringFromFile, | ||
pullKeyphrases: pullKeyphrases, | ||
pullKeywords: pullKeywords, | ||
process: process | ||
} | ||
*/ |
'use strict' | ||
const producePackageKeywords = require('../index.js') | ||
const path = require('path') | ||
const tape = require('tape') | ||
var ppk = require('../index.js') | ||
var path = require('path') | ||
var tape = require('tape') | ||
const testtxt1 = path.resolve('./src/test/test.txt1') | ||
var testtxt1 = path.resolve('./src/test/test.txt1') | ||
const expected1 = { | ||
keywords: ['term', 'extraction', 'Terminology', 'web', 'domain'], | ||
keyphrases: [ | ||
'terminology extraction', | ||
'terms', | ||
'term extraction', | ||
'knowledge domain', | ||
'information extraction' | ||
] | ||
} | ||
tape('Test txt file 1. Should return ' + JSON.stringify(expected1), (test) => { | ||
return producePackageKeywords(testtxt1, {}, (error, result) => { | ||
tape('Test stringFromFile', function (test) { | ||
return ppk.stringFromFile(testtxt1, function (error, result1) { | ||
if (error) { | ||
return test.fail(error) | ||
test.fail(error) | ||
} | ||
if ('communities' in result.keyphrases) { | ||
test.fail(new Error('hahahahahahaha it is there!')) | ||
} | ||
return ppk.stringFromFile('This is text 2.\n', function (error, result2) { | ||
if (error) { | ||
test.fail(error) | ||
} | ||
test.deepEqual(result, expected1) | ||
test.end() | ||
var expected1 = 'This is text 1.\n' | ||
var expected2 = 'This is text 2.\n' | ||
test.equal(result1, expected1, 'Called with file') | ||
test.equal(result2, expected2, 'Called with text') | ||
test.end() | ||
}) | ||
}) | ||
}) | ||
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
9
9810
4
9
74
65
1
+ Addedfs-exists-sync@^0.1.0
+ Addedfs-exists-sync@0.1.0(transitive)