produce-package-keywords
Advanced tools
Comparing version 1.1.7 to 1.2.0
{ | ||
"name": "produce-package-keywords", | ||
"version": "1.1.7", | ||
"version": "1.2.0", | ||
"description": "Produces keywords for a package by analyzing its package.json, readme and/or given file's text", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"lint": "eslint --fix src", | ||
"tape": "tape src/test/*.js | tap-spec", | ||
"clean": "rimraf coverage .nyc_output coverage.lcov", | ||
"test": "npm run lint && nyc npm run tape", | ||
"lint": "eslint --fix src/lib/*.js", | ||
"prebabel": "npm run lint", | ||
"babel": "babel src -d . -D", | ||
"tape": "tape test/*.js | tap-spec", | ||
"pretest": "npm run babel", | ||
"test": "nyc npm run tape", | ||
"posttest": "npm run coverage", | ||
"prepublish": "npm t && npm run clean", | ||
"prepublish": "npm t && npm run clean && npm run babel", | ||
"pregit": "npm t && npm run clean", | ||
"git": "git commit -a -m", | ||
"postgit": "git push github master", | ||
"clean": "rimraf lib index.js test coverage .nyc_output coverage.lcov", | ||
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" | ||
@@ -36,3 +39,18 @@ }, | ||
"homepage": "https://github.com/mrzmmr/produce-package-keywords#readme", | ||
"babel": { | ||
"presets": [ | ||
"latest" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"extends": "standard", | ||
"plugins": [ | ||
"standard", | ||
"promise" | ||
] | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.22.2", | ||
"babel-preset-latest": "^6.22.0", | ||
"chalk": "^1.1.3", | ||
"codecov": "^1.0.1", | ||
@@ -45,4 +63,4 @@ "eslint": "^3.14.0", | ||
"rimraf": "^2.5.4", | ||
"tape": "^4.6.3", | ||
"tap-spec": "^4.1.1" | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.6.3" | ||
}, | ||
@@ -49,0 +67,0 @@ "dependencies": { |
@@ -29,5 +29,20 @@ # produce-package-keywords | ||
```js | ||
const packageKeywords = require('produce-package-keywords') | ||
``` | ||
Then you can pass the function a path to a file, or a string. | ||
```js | ||
const input = 'path/to/file.txt' // or string | ||
producePackageKeywords(input, (error, result) => { | ||
if (error) { | ||
console.error(error) | ||
} | ||
console.log(result) | ||
}) | ||
``` | ||
## Tests | ||
@@ -34,0 +49,0 @@ |
@@ -1,63 +0,6 @@ | ||
'use strict' | ||
#! usr/bin/env node | ||
/* | ||
* Dependencies | ||
*/ | ||
import * as producePackageKeywords from './lib' | ||
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') | ||
export default producePackageKeywords.process | ||
var stringFromFile = function (input, callback) { | ||
if (!exists(input)) { | ||
return callback(null, input) | ||
} | ||
return fs.readFile(input, 'utf-8', function (error, string) { | ||
if (error) { | ||
return callback(error) | ||
} | ||
return callback(null, string) | ||
}) | ||
} | ||
var pullKeywords = function (file) { | ||
return file.data.keywords.map(function (keyword) { | ||
return nlcstToString(keyword.matches[0].node) | ||
}) | ||
} | ||
var pullKeyphrases = function (file) { | ||
return file.data.keyphrases.map(function (phrase) { | ||
return phrase.matches[0].nodes.map(nlcstToString).join('') | ||
}) | ||
} | ||
var process = function (input, callback) { | ||
return stringFromFile(input, function (error, string) { | ||
if (error) { | ||
return callback(error) | ||
} | ||
return retext().use(retextKeywords).process(string, function (error, file) { | ||
if (error) { | ||
return callback(error) | ||
} | ||
return callback(null, { | ||
keyphrases: pullKeyphrases(file), | ||
keywords: pullKeywords(file) | ||
}) | ||
}) | ||
}) | ||
} | ||
module.exports = { | ||
stringFromFile: stringFromFile, | ||
pullKeyphrases: pullKeyphrases, | ||
pullKeywords: pullKeywords, | ||
process: process | ||
} |
'use strict' | ||
var ppk = require('../index.js') | ||
var path = require('path') | ||
var tape = require('tape') | ||
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' | ||
var testtxt1 = path.resolve('./src/test/test.txt1') | ||
import * as packageKeywords from '../lib' | ||
tape('Test stringFromFile', function (test) { | ||
return ppk.stringFromFile(testtxt1, function (error, result1) { | ||
if (error) { | ||
test.fail(error) | ||
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 expected = { | ||
keyphrases: [ | ||
'terminology extraction', | ||
'terms', | ||
'term extraction', | ||
'knowledge domain', | ||
'information extraction' | ||
], | ||
keywords: [ | ||
'term', | ||
'extraction', | ||
'Terminology', | ||
'web', | ||
'domain' | ||
] | ||
} | ||
const expected2 = { | ||
keyphrases: [ | ||
testtxt2string | ||
], | ||
keywords: [ | ||
'text' | ||
] | ||
} | ||
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() | ||
}) | ||
}) | ||
return ppk.stringFromFile('This is text 2.\n', function (error, result2) { | ||
if (error) { | ||
test.fail(error) | ||
} | ||
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() | ||
}) | ||
}) | ||
var expected1 = 'This is text 1.\n' | ||
var expected2 = 'This is text 2.\n' | ||
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() | ||
}) | ||
}) | ||
test.equal(result1, expected1, 'Called with file') | ||
test.equal(result2, expected2, 'Called with text') | ||
test.end() | ||
}) | ||
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 object | From string | test.txt1', (test) => { | ||
return packageKeywords.process(testtxt1string, (err, result) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
test.ok(typeof result === 'object') | ||
test.deepEqual(result, expected) | ||
test.end() | ||
}) | ||
}) | ||
tape('Should return object | From path | test.txt1', (test) => { | ||
return packageKeywords.process(testtxt1, (err, result) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
test.ok(typeof result === 'object') | ||
test.deepEqual(result, expected) | ||
test.end() | ||
}) | ||
}) | ||
tape('Should return object | From string | test.txt2', (test) => { | ||
return packageKeywords.process(testtxt2string, (err, result) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
test.ok(typeof result === 'object') | ||
test.deepEqual(result, expected2) | ||
test.end() | ||
}) | ||
}) | ||
tape('Should return object | From path | test.txt2', (test) => { | ||
return packageKeywords.process(testtxt2, (err, result) => { | ||
if (err) { | ||
test.fail(err) | ||
} | ||
test.ok(typeof result === 'object') | ||
test.deepEqual(result, expected2) | ||
test.end() | ||
}) | ||
}) | ||
tape('Should return string | From file | testtxt1', (test) => { | ||
return packageKeywords.stringFromFile(testtxt1, (err, result) => { | ||
if (err) { | ||
return test.fail(err) | ||
} | ||
test.ok(typeof result === 'string') | ||
test.equal(result, testtxt1string) | ||
test.end() | ||
}) | ||
}) | ||
tape('Should return string | From string | testtxt1', (test) => { | ||
return packageKeywords.stringFromFile(testtxt1string, (err, result) => { | ||
if (err) { | ||
return test.fail(err) | ||
} | ||
test.ok(typeof result === 'string') | ||
test.equal(result, testtxt1string) | ||
test.end() | ||
}) | ||
}) | ||
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 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() | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
25232
14
437
80
12
6
1