produce-package-keywords
Advanced tools
Comparing version 1.2.0 to 1.3.0
14
index.js
#! usr/bin/env node | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var ppk = require('./lib'); | ||
var _lib = require('./lib'); | ||
var producePackageKeywords = _interopRequireWildcard(_lib); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
exports.default = producePackageKeywords.process; | ||
module.exports = ppk.process; | ||
module.exports.process = ppk.process; | ||
module.exports.fromFile = ppk.fromFile; |
125
lib/index.js
'use strict'; | ||
/* | ||
* Dependencies | ||
*/ | ||
var retextKeywords = require('retext-keywords'); | ||
var nlcstToString = require('nlcst-to-string'); | ||
var readPkgUp = require('read-pkg-up'); | ||
var Retext = require('retext'); | ||
var fs = require('fs'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.process = exports.pullKeywords = exports.pullKeyphrases = exports.stringFromFile = undefined; | ||
var retext = Retext(); | ||
var _retextKeywords = require('retext-keywords'); | ||
var formatString = module.exports.formatString = function (string) { | ||
return string.toLowerCase().replace(/[^\w\s|-]/g, '').split(' ').join('-'); | ||
}; | ||
var _retextKeywords2 = _interopRequireDefault(_retextKeywords); | ||
var merge = module.exports.merge = function (first, second) { | ||
return first.concat(second.filter(function (node) { | ||
return first.indexOf(node) < 0; | ||
})); | ||
}; | ||
var _nlcstToString = require('nlcst-to-string'); | ||
var getKeyphrases = module.exports.getKeyphrases = function (file) { | ||
return file.data.keyphrases.map(function (keyphrase) { | ||
return keyphrase.matches[0].nodes.map(nlcstToString).join(''); | ||
}).map(formatString); | ||
}; | ||
var _nlcstToString2 = _interopRequireDefault(_nlcstToString); | ||
var getKeywords = module.exports.getKeywords = function (file) { | ||
return file.data.keywords.map(function (keyword) { | ||
return nlcstToString(keyword.matches[0].node); | ||
}).map(formatString); | ||
}; | ||
var _fsExistsSync = require('fs-exists-sync'); | ||
var extract = module.exports.extract = function (input) { | ||
var file = retext.use(retextKeywords).process(input); | ||
return merge(getKeyphrases(file), getKeywords(file)); | ||
}; | ||
var _fsExistsSync2 = _interopRequireDefault(_fsExistsSync); | ||
var _retext = require('retext'); | ||
var _retext2 = _interopRequireDefault(_retext); | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var stringFromFile = exports.stringFromFile = function stringFromFile(input, callback) { | ||
if (!(0, _fsExistsSync2.default)(input)) { | ||
return callback(null, input); | ||
var fromFile = module.exports.fromFile = function (file, callback) { | ||
var error = fs.accessSync(file); | ||
if (error) { | ||
return callback(error); | ||
} | ||
return _fs2.default.readFile(input, 'utf-8', function (error, string) { | ||
return fs.readFile(file, function (error, string) { | ||
if (error) { | ||
return callback(error); | ||
} | ||
return callback(null, string); | ||
return callback(null, extract(string)); | ||
}); | ||
};var pullKeyphrases = exports.pullKeyphrases = function pullKeyphrases(file) { | ||
return file.data.keyphrases.map(function (phrase) { | ||
return phrase.matches[0].nodes.map(_nlcstToString2.default).join(''); | ||
}); | ||
}; | ||
var pullKeywords = exports.pullKeywords = function pullKeywords(file) { | ||
return file.data.keywords.map(function (keyword) { | ||
return (0, _nlcstToString2.default)(keyword.matches[0].node); | ||
}); | ||
}; | ||
var fromPackageJson = module.exports.fromPackageJson = function (callback) { | ||
return readPkgUp().then(function (json) { | ||
var description = json.pkg.description; | ||
var name = json.pkg.name; | ||
var result = []; | ||
var process = exports.process = function process(input, callback) { | ||
return stringFromFile(input, function (error, string) { | ||
if (error) { | ||
return callback(error); | ||
if (description) { | ||
description = extract(description); | ||
result = merge(result, description); | ||
} | ||
return (0, _retext2.default)().use(_retextKeywords2.default).process(string, function (error, file) { | ||
if (error) { | ||
return callback(error); | ||
} | ||
if (name) { | ||
name = extract(name); | ||
result = merge(result, name); | ||
} | ||
var returns = { | ||
keyphrases: pullKeyphrases(file), | ||
keywords: pullKeywords(file) | ||
}; | ||
return callback(null, result); | ||
}).catch(function (error) { | ||
return callback(error); | ||
}); | ||
}; | ||
if (returns.keyphrases.length === 0) { | ||
returns.keyphrases = [string]; | ||
} | ||
var process = module.exports.process = function (string, callback) { | ||
if (typeof string === 'function') { | ||
callback = string; | ||
string = null; | ||
} | ||
if (returns.keywords.length === 0) { | ||
returns.keywords = [string]; | ||
} | ||
if (string) { | ||
return callback(null, extract(string)); | ||
} | ||
return callback(null, returns); | ||
}); | ||
}); | ||
}; | ||
exports.default = process; | ||
return fromPackageJson(callback); | ||
}; |
{ | ||
"name": "produce-package-keywords", | ||
"version": "1.2.0", | ||
"description": "Produces keywords for a package by analyzing its package.json, readme and/or given file's text", | ||
"version": "1.3.0", | ||
"description": "Produces keywords for your node.js package so that users can better find your package on npm", | ||
"main": "src/index.js", | ||
@@ -49,3 +49,8 @@ "scripts": { | ||
"promise" | ||
] | ||
], | ||
"rules": { | ||
"no-unused-vars": [2, { | ||
"varsIgnorePattern": "fromFile|fromPackageJson|process" | ||
}] | ||
} | ||
}, | ||
@@ -55,8 +60,3 @@ "devDependencies": { | ||
"babel-preset-latest": "^6.22.0", | ||
"chalk": "^1.1.3", | ||
"codecov": "^1.0.1", | ||
"eslint": "^3.14.0", | ||
"eslint-config-standard": "^6.2.1", | ||
"eslint-plugin-promise": "^3.4.0", | ||
"eslint-plugin-standard": "^2.0.1", | ||
"nyc": "^10.1.2", | ||
@@ -68,4 +68,4 @@ "rimraf": "^2.5.4", | ||
"dependencies": { | ||
"fs-exists-sync": "^0.1.0", | ||
"nlcst-to-string": "^2.0.0", | ||
"read-pkg-up": "^2.0.0", | ||
"retext": "^4.0.0", | ||
@@ -72,0 +72,0 @@ "retext-keywords": "^3.1.0" |
104
Readme.md
# produce-package-keywords | ||
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) | ||
[![CircleCI](https://img.shields.io/circleci/project/github/mrzmmr/produce-package-keywords.svg)](https://circleci.com/gh/mrzmmr/produce-package-keywords) | ||
[![Codecov](https://img.shields.io/codecov/c/github/mrzmmr/produce-package-keywords.svg)](https://codecov.io/gh/mrzmmr/produce-package-keywords) | ||
[![David](https://img.shields.io/david/mrzmmr/produce-package-keywords.svg)](https://david-dm.org/) | ||
[![David](https://img.shields.io/david/dev/mrzmmr/produce-package-keywords.svg)](https://david-dm.org/) | ||
[![npm](https://img.shields.io/npm/v/produce-package-keywords.svg)](https://www.npmjs.com/package/produce-package-keywords) | ||
> Produces keywords for a package by analyzing its package.json, readme and/or given file. | ||
> Produces keywords for a package by analyzing its package.json, a string, or | ||
> file. | ||
TODO: Fill out this long description. | ||
## Table of Contents | ||
@@ -18,2 +14,3 @@ | ||
- [Usage](#usage) | ||
- [Api](#api) | ||
- [Contribute](#contribute) | ||
@@ -31,19 +28,82 @@ - [License](#license) | ||
```js | ||
const packageKeywords = require('produce-package-keywords') | ||
const ppk = require('produce-package-keywords') | ||
``` | ||
Then you can pass the function a path to a file, or a string. | ||
produce keywords given a file | ||
```js | ||
const input = 'path/to/file.txt' // or string | ||
ppk.fromFile('path/to/file.txt', (error, result) => { | ||
if (error) { | ||
... | ||
} | ||
producePackageKeywords(input, (error, result) => { | ||
... | ||
}) | ||
``` | ||
produce keywords given a string | ||
```js | ||
ppk.process(string, callback) | ||
// alias | ||
ppk(string, callback) | ||
``` | ||
```js | ||
ppk(string, (error, result) => { | ||
if (error) { | ||
console.error(error) | ||
... | ||
} | ||
console.log(result) | ||
... | ||
}) | ||
``` | ||
or from package.json's name and description fields | ||
```js | ||
ppk.process(callback) | ||
// alias | ||
ppk(callback) | ||
``` | ||
```js | ||
ppk((error, result) => { | ||
if (error) { | ||
... | ||
} | ||
... | ||
}) | ||
``` | ||
## Api | ||
### producePackageKeywords([string], callback) | ||
Returns an error first callback with an array of extracted keywords from string | ||
if given, otherwise from package.json's name and description fields. | ||
#### options | ||
**[string]** - optional string argument | ||
**callback** - error first callback | ||
### producePackageKeywords.fromFile(file, callback) | ||
Returns an error first callback with an array of extracted keywords from the | ||
given file | ||
#### options | ||
**file** - file to extract from | ||
**callback** - error first callback | ||
## Tests | ||
@@ -56,6 +116,14 @@ | ||
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) | ||
[![David](https://img.shields.io/david/mrzmmr/produce-package-keywords.svg)](https://david-dm.org/) | ||
[![David](https://img.shields.io/david/dev/mrzmmr/produce-package-keywords.svg)](https://david-dm.org/) | ||
## Contribute | ||
PRs accepted and greatly appreciated. | ||
## Dependencies | ||
- [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 | ||
- [read-pkg-up](https://github.com/sindresorhus/read-pkg-up): Read the closest package.json file | ||
- [retext](https://github.com/wooorm/retext/tree/master/packages): Natural language processor powered by plugins | ||
@@ -66,15 +134,11 @@ - [retext-keywords](https://github.com/wooorm/retext-keywords): Keyword extraction with Retext | ||
- [babel-cli](https://github.com/babel/babel/tree/master/packages): Babel command line. | ||
- [babel-preset-latest](https://github.com/babel/babel/tree/master/packages): Babel preset including es2015+ | ||
- [codecov](https://github.com/codecov/codecov-node): Uploading report to Codecov: https://codecov.io | ||
- [eslint](https://github.com/eslint/eslint): An AST-based pattern checker for JavaScript. | ||
- [eslint-config-standard](https://github.com/feross/eslint-config-standard): JavaScript Standard Style - ESLint Shareable Config | ||
- [eslint-plugin-promise](https://github.com/xjamundx/eslint-plugin-promise): Enforce best practices for JavaScript promises | ||
- [eslint-plugin-standard](https://github.com/xjamundx/eslint-plugin-standard): ESlint Plugin for the Standard Linter | ||
- [nyc](https://github.com/istanbuljs/nyc): the Istanbul command line interface | ||
- [rimraf](https://github.com/isaacs/rimraf): A deep deletion module for node (like `rm -rf`) | ||
- [tap-spec](https://github.com/scottcorgan/tap-spec): Formatted TAP output like Mocha's spec reporter | ||
- [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 | ||
## Contribute | ||
PRs accepted and greatly appreciated. | ||
@@ -81,0 +145,0 @@ ## License |
#! usr/bin/env node | ||
import * as producePackageKeywords from './lib' | ||
const ppk = require('./lib') | ||
export default producePackageKeywords.process | ||
module.exports = ppk.process | ||
module.exports.process = ppk.process | ||
module.exports.fromFile = ppk.fromFile |
'use strict' | ||
/* | ||
* Dependencies | ||
*/ | ||
const retextKeywords = require('retext-keywords') | ||
const nlcstToString = require('nlcst-to-string') | ||
const readPkgUp = require('read-pkg-up') | ||
const Retext = require('retext') | ||
const fs = require('fs') | ||
import {default as retextKeywords} from 'retext-keywords' | ||
import {default as nlcstToString} from 'nlcst-to-string' | ||
import {default as exists} from 'fs-exists-sync' | ||
import {default as retext} from 'retext' | ||
import {default as fs} from 'fs' | ||
const retext = Retext() | ||
export const stringFromFile = (input, callback) => { | ||
if (!exists(input)) { | ||
return callback(null, input) | ||
} | ||
const formatString = module.exports.formatString = (string) => { | ||
return string.toLowerCase().replace(/[^\w\s|-]/g, '').split(' ').join('-') | ||
} | ||
return fs.readFile(input, 'utf-8', (error, string) => { | ||
if (error) { | ||
return callback(error) | ||
} | ||
return callback(null, string) | ||
}) | ||
const merge = module.exports.merge = (first, second) => { | ||
return first.concat(second.filter((node) => { | ||
return first.indexOf(node) < 0 | ||
})) | ||
} | ||
export const pullKeyphrases = (file) => { | ||
return file.data.keyphrases.map((phrase) => { | ||
return phrase.matches[0].nodes.map(nlcstToString).join('') | ||
const getKeyphrases = module.exports.getKeyphrases = (file) => { | ||
return file.data.keyphrases.map((keyphrase) => { | ||
return keyphrase.matches[0].nodes.map(nlcstToString).join('') | ||
}) | ||
.map(formatString) | ||
} | ||
export const pullKeywords = (file) => { | ||
return file.data.keywords.map(keyword => { | ||
const getKeywords = module.exports.getKeywords = (file) => { | ||
return file.data.keywords.map((keyword) => { | ||
return nlcstToString(keyword.matches[0].node) | ||
}) | ||
.map(formatString) | ||
} | ||
export const process = function (input, callback) { | ||
return stringFromFile(input, function (error, string) { | ||
const extract = module.exports.extract = (input) => { | ||
const file = retext.use(retextKeywords).process(input) | ||
return merge(getKeyphrases(file), getKeywords(file)) | ||
} | ||
const fromFile = module.exports.fromFile = (file, callback) => { | ||
const error = fs.accessSync(file) | ||
if (error) { | ||
return callback(error) | ||
} | ||
return fs.readFile(file, (error, string) => { | ||
if (error) { | ||
return callback(error) | ||
} | ||
return callback(null, extract(string)) | ||
}) | ||
} | ||
return retext().use(retextKeywords).process(string, function (error, file) { | ||
if (error) { | ||
return callback(error) | ||
} | ||
const fromPackageJson = module.exports.fromPackageJson = (callback) => { | ||
return readPkgUp().then((json) => { | ||
let description = json.pkg.description | ||
let name = json.pkg.name | ||
let result = [] | ||
const returns = { | ||
keyphrases: pullKeyphrases(file), | ||
keywords: pullKeywords(file) | ||
} | ||
if (description) { | ||
description = extract(description) | ||
result = merge(result, description) | ||
} | ||
if (returns.keyphrases.length === 0) { | ||
returns.keyphrases = [string] | ||
} | ||
if (name) { | ||
name = extract(name) | ||
result = merge(result, name) | ||
} | ||
if (returns.keywords.length === 0) { | ||
returns.keywords = [string] | ||
} | ||
return callback(null, returns) | ||
}) | ||
return callback(null, result) | ||
}) | ||
.catch((error) => callback(error)) | ||
} | ||
export default process | ||
const process = module.exports.process = (string, callback) => { | ||
if (typeof string === 'function') { | ||
callback = string | ||
string = null | ||
} | ||
if (string) { | ||
return callback(null, extract(string)) | ||
} | ||
return fromPackageJson(callback) | ||
} |
'use strict' | ||
import {default as retextKeywords} from 'retext-keywords' | ||
import {default as retext} from 'retext' | ||
import {default as path} from 'path' | ||
import {default as tape} from 'tape' | ||
import {default as fs} from 'fs' | ||
const retextKeywords = require('retext-keywords') | ||
const Retext = require('retext') | ||
const path = require('path') | ||
const tape = require('tape') | ||
const fs = require('fs') | ||
import * as packageKeywords from '../lib' | ||
const ppk = require('../lib') | ||
const testtxt1 = path.resolve('./src/test/test.txt1') | ||
const testtxt2 = path.resolve('./src/test/test.txt2') | ||
const testtxt1string = fs.readFileSync(testtxt1, 'utf-8') | ||
const testtxt2string = fs.readFileSync(testtxt2, 'utf-8') | ||
const retext = Retext() | ||
const expected = { | ||
keyphrases: [ | ||
'terminology extraction', | ||
'terms', | ||
'term extraction', | ||
'knowledge domain', | ||
'information extraction' | ||
], | ||
keywords: [ | ||
'term', | ||
'extraction', | ||
'Terminology', | ||
'web', | ||
'domain' | ||
] | ||
} | ||
const filePath = path.resolve(__dirname, './test.txt1') | ||
const expected2 = { | ||
keyphrases: [ | ||
testtxt2string | ||
], | ||
keywords: [ | ||
'text' | ||
] | ||
const expected = [ | ||
'package', | ||
'test', | ||
'produce-package-keywords', | ||
'keywords', | ||
'packages', | ||
'users', | ||
'npm' | ||
] | ||
const expectedKeyphrases = [ 'package' ] | ||
const expectedKeywords = [ | ||
'package', | ||
'test', | ||
'produce-package-keywords', | ||
'keywords', | ||
'packages', | ||
'users', | ||
'npm' | ||
] | ||
const expected2 = [ | ||
'package', | ||
'keywords', | ||
'users', | ||
'npm', | ||
'produce-package-keywords' | ||
] | ||
const array1 = [ | ||
'foo bar', | ||
'foo bar baz', | ||
'foo\'s bar', | ||
'foo\'s bar\'s baz\'s' | ||
] | ||
const array1expected = [ | ||
'foo-bar', | ||
'foo-bar-baz', | ||
'foos-bar', | ||
'foos-bars-bazs' | ||
] | ||
const ok = (test, result, expected) => { | ||
test.ok(result) | ||
test.ok(Array.isArray(result)) | ||
test.deepEqual(result, expected) | ||
test.end() | ||
} | ||
tape('Should return array of keywords | test.txt1', (test) => { | ||
return retext().use(retextKeywords).process(testtxt1string, (err, file) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
const result = packageKeywords.pullKeywords(file) | ||
test.ok(Array.isArray(result)) | ||
test.deepEqual(result, expected.keywords) | ||
test.end() | ||
}) | ||
}) | ||
/* | ||
* Callback api | ||
*/ | ||
tape('Should return array of keyphrases | test.txt1', (test) => { | ||
return retext().use(retextKeywords).process(testtxt1string, (err, file) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
const result = packageKeywords.pullKeyphrases(file) | ||
test.ok(Array.isArray(result)) | ||
test.deepEqual(result, expected.keyphrases) | ||
test.end() | ||
}) | ||
tape('Should return hyphenated, de-apostrophied array | formatString', (t) => { | ||
return ok(t, array1.map((p) => ppk.formatString(p)), array1expected) | ||
}) | ||
tape('Should return array of keywords | test.txt2', (test) => { | ||
return retext().use(retextKeywords).process(testtxt2string, (err, file) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
const result = packageKeywords.pullKeywords(file) | ||
test.ok(Array.isArray(result)) | ||
test.deepEqual(result, expected2.keywords) | ||
test.end() | ||
}) | ||
tape('Should return uniq\'d merged array | merge', (t) => { | ||
const array = ['foo-bar', 'bar-foo', 'foo-bar-baz', 'baz-bar-foo'] | ||
const expectedArray = [ | ||
'foo-bar', | ||
'foo-bar-baz', | ||
'foos-bar', | ||
'foos-bars-bazs', | ||
'bar-foo', | ||
'baz-bar-foo' | ||
] | ||
return ok(t, ppk.merge(array1expected, array), expectedArray) | ||
}) | ||
tape('Should return array of keyphrases | test.txt2', (test) => { | ||
return retext().use(retextKeywords).process(testtxt2string, (err, file) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
const result = packageKeywords.pullKeyphrases(file) | ||
test.ok(Array.isArray(result)) | ||
test.deepEqual(result, []) | ||
test.end() | ||
}) | ||
tape('Should return keyphrases from test.txt1 | getKeyphrases', (t) => { | ||
const file = retext.use(retextKeywords).process(fs.readFileSync(filePath)) | ||
const result = ppk.getKeyphrases(file) | ||
return ok(t, result, expectedKeyphrases) | ||
}) | ||
tape('Should return object | From string | test.txt1', (test) => { | ||
return packageKeywords.process(testtxt1string, (err, result) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
tape('Should return keywords from test.txt1 | getKeywords', (t) => { | ||
const file = retext.use(retextKeywords).process(fs.readFileSync(filePath)) | ||
const result = ppk.getKeywords(file) | ||
test.ok(typeof result === 'object') | ||
test.deepEqual(result, expected) | ||
test.end() | ||
}) | ||
return ok(t, result, expectedKeywords) | ||
}) | ||
tape('Should return object | From path | test.txt1', (test) => { | ||
return packageKeywords.process(testtxt1, (err, result) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
tape('Should return merged array from test.txt1 | extract', (t) => { | ||
const result = ppk.extract(fs.readFileSync(filePath)) | ||
const expectedArray = ppk.merge(expectedKeywords, expectedKeyphrases) | ||
test.ok(typeof result === 'object') | ||
test.deepEqual(result, expected) | ||
test.end() | ||
}) | ||
return ok(t, result, expectedArray) | ||
}) | ||
tape('Should return object | From string | test.txt2', (test) => { | ||
return packageKeywords.process(testtxt2string, (err, result) => { | ||
if (err) { | ||
test.fail(err) | ||
tape('Should return array from file | fromFile | callback', (t) => { | ||
return ppk.fromFile(filePath, (error, result) => { | ||
if (error) { | ||
return t.fail(error) | ||
} | ||
test.ok(typeof result === 'object') | ||
test.deepEqual(result, expected2) | ||
test.end() | ||
return ok(t, result, expected) | ||
}) | ||
}) | ||
tape('Should return object | From path | test.txt2', (test) => { | ||
return packageKeywords.process(testtxt2, (err, result) => { | ||
if (err) { | ||
test.fail(err) | ||
tape('Should return array from package.json | fromPackageJson | callback', (t) => { | ||
return ppk.fromPackageJson((error, result) => { | ||
if (error) { | ||
return t.fail(error) | ||
} | ||
test.ok(typeof result === 'object') | ||
test.deepEqual(result, expected2) | ||
test.end() | ||
return ok(t, result, expected2) | ||
}) | ||
}) | ||
tape('Should return string | From file | testtxt1', (test) => { | ||
return packageKeywords.stringFromFile(testtxt1, (err, result) => { | ||
if (err) { | ||
return test.fail(err) | ||
tape('Should return array from string | process | callback', (t) => { | ||
return ppk.process(fs.readFileSync(filePath, 'utf-8'), (error, result) => { | ||
if (error) { | ||
return t.fail(error) | ||
} | ||
test.ok(typeof result === 'string') | ||
test.equal(result, testtxt1string) | ||
test.end() | ||
return ok(t, result, expected) | ||
}) | ||
}) | ||
tape('Should return string | From string | testtxt1', (test) => { | ||
return packageKeywords.stringFromFile(testtxt1string, (err, result) => { | ||
if (err) { | ||
return test.fail(err) | ||
tape('Should return array from package.json | process | callback', (t) => { | ||
return ppk.process((error, result) => { | ||
if (error) { | ||
return t.fail(error) | ||
} | ||
test.ok(typeof result === 'string') | ||
test.equal(result, testtxt1string) | ||
test.end() | ||
return ok(t, result, expected2) | ||
}) | ||
}) | ||
tape('Should return string | From file | testtxt2', (test) => { | ||
return packageKeywords.stringFromFile(testtxt2, (err, result) => { | ||
if (err) { | ||
return test.fail(err) | ||
} | ||
test.ok(typeof result === 'string') | ||
test.equal(result, testtxt2string) | ||
test.end() | ||
tape('Should fail from file | fromFile | callback', (t) => { | ||
t.plan(1) | ||
t.throws(() => { | ||
return ppk.fromFile((error, result) => { | ||
if (error) { | ||
throw error | ||
} | ||
}) | ||
}) | ||
}) | ||
tape('Should return string | From string | testtxt2', (test) => { | ||
return packageKeywords.stringFromFile(testtxt2string, (err, result) => { | ||
if (err) { | ||
return test.fail(err) | ||
} | ||
test.ok(typeof result === 'string') | ||
test.equal(result, testtxt2string) | ||
test.end() | ||
tape('Should fail from file | fromFile | callback', (t) => { | ||
t.plan(1) | ||
t.throws(() => { | ||
return ppk.fromFile('./foo', (error, result) => { | ||
if (error) { | ||
throw error | ||
} | ||
}) | ||
}) | ||
}) | ||
/* | ||
* Promise api | ||
*/ |
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var retextKeywords = require('retext-keywords'); | ||
var Retext = require('retext'); | ||
var path = require('path'); | ||
var tape = require('tape'); | ||
var fs = require('fs'); | ||
var _retextKeywords = require('retext-keywords'); | ||
var ppk = require('../lib'); | ||
var _retextKeywords2 = _interopRequireDefault(_retextKeywords); | ||
var retext = Retext(); | ||
var _retext = require('retext'); | ||
var filePath = path.resolve(__dirname, './test.txt1'); | ||
var _retext2 = _interopRequireDefault(_retext); | ||
var expected = ['package', 'test', 'produce-package-keywords', 'keywords', 'packages', 'users', 'npm']; | ||
var _path = require('path'); | ||
var expectedKeyphrases = ['package']; | ||
var _path2 = _interopRequireDefault(_path); | ||
var expectedKeywords = ['package', 'test', 'produce-package-keywords', 'keywords', 'packages', 'users', 'npm']; | ||
var _tape = require('tape'); | ||
var expected2 = ['package', 'keywords', 'users', 'npm', 'produce-package-keywords']; | ||
var _tape2 = _interopRequireDefault(_tape); | ||
var array1 = ['foo bar', 'foo bar baz', 'foo\'s bar', 'foo\'s bar\'s baz\'s']; | ||
var _fs = require('fs'); | ||
var array1expected = ['foo-bar', 'foo-bar-baz', 'foos-bar', 'foos-bars-bazs']; | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _lib = require('../lib'); | ||
var packageKeywords = _interopRequireWildcard(_lib); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var testtxt1 = _path2.default.resolve('./src/test/test.txt1'); | ||
var testtxt2 = _path2.default.resolve('./src/test/test.txt2'); | ||
var testtxt1string = _fs2.default.readFileSync(testtxt1, 'utf-8'); | ||
var testtxt2string = _fs2.default.readFileSync(testtxt2, 'utf-8'); | ||
var expected = { | ||
keyphrases: ['terminology extraction', 'terms', 'term extraction', 'knowledge domain', 'information extraction'], | ||
keywords: ['term', 'extraction', 'Terminology', 'web', 'domain'] | ||
var ok = function ok(test, result, expected) { | ||
test.ok(result); | ||
test.ok(Array.isArray(result)); | ||
test.deepEqual(result, expected); | ||
test.end(); | ||
}; | ||
var expected2 = { | ||
keyphrases: [testtxt2string], | ||
keywords: ['text'] | ||
}; | ||
/* | ||
* Callback api | ||
*/ | ||
(0, _tape2.default)('Should return array of keywords | test.txt1', function (test) { | ||
return (0, _retext2.default)().use(_retextKeywords2.default).process(testtxt1string, function (err, file) { | ||
if (err) { | ||
test.fail(err); | ||
} | ||
var result = packageKeywords.pullKeywords(file); | ||
test.ok(Array.isArray(result)); | ||
test.deepEqual(result, expected.keywords); | ||
test.end(); | ||
}); | ||
tape('Should return hyphenated, de-apostrophied array | formatString', function (t) { | ||
return ok(t, array1.map(function (p) { | ||
return ppk.formatString(p); | ||
}), array1expected); | ||
}); | ||
(0, _tape2.default)('Should return array of keyphrases | test.txt1', function (test) { | ||
return (0, _retext2.default)().use(_retextKeywords2.default).process(testtxt1string, function (err, file) { | ||
if (err) { | ||
test.fail(err); | ||
} | ||
var result = packageKeywords.pullKeyphrases(file); | ||
test.ok(Array.isArray(result)); | ||
test.deepEqual(result, expected.keyphrases); | ||
test.end(); | ||
}); | ||
tape('Should return uniq\'d merged array | merge', function (t) { | ||
var array = ['foo-bar', 'bar-foo', 'foo-bar-baz', 'baz-bar-foo']; | ||
var expectedArray = ['foo-bar', 'foo-bar-baz', 'foos-bar', 'foos-bars-bazs', 'bar-foo', 'baz-bar-foo']; | ||
return ok(t, ppk.merge(array1expected, array), expectedArray); | ||
}); | ||
(0, _tape2.default)('Should return array of keywords | test.txt2', function (test) { | ||
return (0, _retext2.default)().use(_retextKeywords2.default).process(testtxt2string, function (err, file) { | ||
if (err) { | ||
test.fail(err); | ||
} | ||
var result = packageKeywords.pullKeywords(file); | ||
test.ok(Array.isArray(result)); | ||
test.deepEqual(result, expected2.keywords); | ||
test.end(); | ||
}); | ||
tape('Should return keyphrases from test.txt1 | getKeyphrases', function (t) { | ||
var file = retext.use(retextKeywords).process(fs.readFileSync(filePath)); | ||
var result = ppk.getKeyphrases(file); | ||
return ok(t, result, expectedKeyphrases); | ||
}); | ||
(0, _tape2.default)('Should return array of keyphrases | test.txt2', function (test) { | ||
return (0, _retext2.default)().use(_retextKeywords2.default).process(testtxt2string, function (err, file) { | ||
if (err) { | ||
test.fail(err); | ||
} | ||
var result = packageKeywords.pullKeyphrases(file); | ||
test.ok(Array.isArray(result)); | ||
test.deepEqual(result, []); | ||
test.end(); | ||
}); | ||
tape('Should return keywords from test.txt1 | getKeywords', function (t) { | ||
var file = retext.use(retextKeywords).process(fs.readFileSync(filePath)); | ||
var result = ppk.getKeywords(file); | ||
return ok(t, result, expectedKeywords); | ||
}); | ||
(0, _tape2.default)('Should return object | From string | test.txt1', function (test) { | ||
return packageKeywords.process(testtxt1string, function (err, result) { | ||
if (err) { | ||
test.fail(err); | ||
} | ||
tape('Should return merged array from test.txt1 | extract', function (t) { | ||
var result = ppk.extract(fs.readFileSync(filePath)); | ||
var expectedArray = ppk.merge(expectedKeywords, expectedKeyphrases); | ||
test.ok((typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object'); | ||
test.deepEqual(result, expected); | ||
test.end(); | ||
}); | ||
return ok(t, result, expectedArray); | ||
}); | ||
(0, _tape2.default)('Should return object | From path | test.txt1', function (test) { | ||
return packageKeywords.process(testtxt1, function (err, result) { | ||
if (err) { | ||
test.fail(err); | ||
tape('Should return array from file | fromFile | callback', function (t) { | ||
return ppk.fromFile(filePath, function (error, result) { | ||
if (error) { | ||
return t.fail(error); | ||
} | ||
test.ok((typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object'); | ||
test.deepEqual(result, expected); | ||
test.end(); | ||
return ok(t, result, expected); | ||
}); | ||
}); | ||
(0, _tape2.default)('Should return object | From string | test.txt2', function (test) { | ||
return packageKeywords.process(testtxt2string, function (err, result) { | ||
if (err) { | ||
test.fail(err); | ||
tape('Should return array from package.json | fromPackageJson | callback', function (t) { | ||
return ppk.fromPackageJson(function (error, result) { | ||
if (error) { | ||
return t.fail(error); | ||
} | ||
test.ok((typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object'); | ||
test.deepEqual(result, expected2); | ||
test.end(); | ||
return ok(t, result, expected2); | ||
}); | ||
}); | ||
(0, _tape2.default)('Should return object | From path | test.txt2', function (test) { | ||
return packageKeywords.process(testtxt2, function (err, result) { | ||
if (err) { | ||
test.fail(err); | ||
tape('Should return array from string | process | callback', function (t) { | ||
return ppk.process(fs.readFileSync(filePath, 'utf-8'), function (error, result) { | ||
if (error) { | ||
return t.fail(error); | ||
} | ||
test.ok((typeof result === 'undefined' ? 'undefined' : _typeof(result)) === 'object'); | ||
test.deepEqual(result, expected2); | ||
test.end(); | ||
return ok(t, result, expected); | ||
}); | ||
}); | ||
(0, _tape2.default)('Should return string | From file | testtxt1', function (test) { | ||
return packageKeywords.stringFromFile(testtxt1, function (err, result) { | ||
if (err) { | ||
return test.fail(err); | ||
tape('Should return array from package.json | process | callback', function (t) { | ||
return ppk.process(function (error, result) { | ||
if (error) { | ||
return t.fail(error); | ||
} | ||
test.ok(typeof result === 'string'); | ||
test.equal(result, testtxt1string); | ||
test.end(); | ||
return ok(t, result, expected2); | ||
}); | ||
}); | ||
(0, _tape2.default)('Should return string | From string | testtxt1', function (test) { | ||
return packageKeywords.stringFromFile(testtxt1string, function (err, result) { | ||
if (err) { | ||
return test.fail(err); | ||
} | ||
test.ok(typeof result === 'string'); | ||
test.equal(result, testtxt1string); | ||
test.end(); | ||
tape('Should fail from file | fromFile | callback', function (t) { | ||
t.plan(1); | ||
t.throws(function () { | ||
return ppk.fromFile(function (error, result) { | ||
if (error) { | ||
throw error; | ||
} | ||
}); | ||
}); | ||
}); | ||
(0, _tape2.default)('Should return string | From file | testtxt2', function (test) { | ||
return packageKeywords.stringFromFile(testtxt2, function (err, result) { | ||
if (err) { | ||
return test.fail(err); | ||
} | ||
test.ok(typeof result === 'string'); | ||
test.equal(result, testtxt2string); | ||
test.end(); | ||
tape('Should fail from file | fromFile | callback', function (t) { | ||
t.plan(1); | ||
t.throws(function () { | ||
return ppk.fromFile('./foo', function (error, result) { | ||
if (error) { | ||
throw error; | ||
} | ||
}); | ||
}); | ||
}); | ||
(0, _tape2.default)('Should return string | From string | testtxt2', function (test) { | ||
return packageKeywords.stringFromFile(testtxt2string, function (err, result) { | ||
if (err) { | ||
return test.fail(err); | ||
} | ||
test.ok(typeof result === 'string'); | ||
test.equal(result, testtxt2string); | ||
test.end(); | ||
}); | ||
}); | ||
/* | ||
* Promise api | ||
*/ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
7
144
4
20052
392
+ Addedread-pkg-up@^2.0.0
+ Addederror-ex@1.3.2(transitive)
+ Addedfind-up@2.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.9(transitive)
+ Addedis-arrayish@0.2.1(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedload-json-file@2.0.0(transitive)
+ Addedlocate-path@2.0.0(transitive)
+ Addednormalize-package-data@2.5.0(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-locate@2.0.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedparse-json@2.2.0(transitive)
+ Addedpath-exists@3.0.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-type@2.0.0(transitive)
+ Addedpify@2.3.0(transitive)
+ Addedread-pkg@2.0.0(transitive)
+ Addedread-pkg-up@2.0.0(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.20(transitive)
+ Addedstrip-bom@3.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
- Removedfs-exists-sync@^0.1.0
- Removedfs-exists-sync@0.1.0(transitive)