Comparing version 1.0.1 to 1.1.0
33
index.js
@@ -1,39 +0,38 @@ | ||
'use strict'; | ||
'use strict' | ||
module.exports = nGram; | ||
module.exports = nGram | ||
nGram.bigram = nGram(2); | ||
nGram.trigram = nGram(3); | ||
nGram.bigram = nGram(2) | ||
nGram.trigram = nGram(3) | ||
/* Factory returning a function that converts a given string | ||
* to n-grams. */ | ||
// Factory returning a function that converts a value string to n-grams. | ||
function nGram(n) { | ||
if (typeof n !== 'number' || isNaN(n) || n < 1 || n === Infinity) { | ||
throw new Error('`' + n + '` is not a valid argument for n-gram'); | ||
throw new Error('`' + n + '` is not a valid argument for n-gram') | ||
} | ||
return grams; | ||
return grams | ||
/* Create n-grams from a given value. */ | ||
// Create n-grams from a given value. | ||
function grams(value) { | ||
var nGrams = []; | ||
var index; | ||
var nGrams = [] | ||
var index | ||
if (value === null || value === undefined) { | ||
return nGrams; | ||
return nGrams | ||
} | ||
value = String(value); | ||
index = value.length - n + 1; | ||
value = value.slice ? value : String(value) | ||
index = value.length - n + 1 | ||
if (index < 1) { | ||
return nGrams; | ||
return nGrams | ||
} | ||
while (index--) { | ||
nGrams[index] = value.substr(index, n); | ||
nGrams[index] = value.slice(index, index + n) | ||
} | ||
return nGrams; | ||
return nGrams | ||
} | ||
} |
{ | ||
"name": "n-gram", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Get n-grams from text", | ||
@@ -16,7 +16,8 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/words/n-gram", | ||
"repository": "words/n-gram", | ||
"bugs": "https://github.com/words/n-gram/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)" | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"Matt Fletcher <mattflet@gmail.com>" | ||
], | ||
@@ -28,19 +29,19 @@ "files": [ | ||
"devDependencies": { | ||
"browserify": "^14.0.0", | ||
"esmangle": "^1.0.0", | ||
"nyc": "^11.0.0", | ||
"remark-cli": "^4.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"browserify": "^16.0.0", | ||
"nyc": "^12.0.0", | ||
"prettier": "^1.14.2", | ||
"remark-cli": "^5.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.18.0" | ||
"tinyify": "^2.4.3", | ||
"xo": "^0.22.0" | ||
}, | ||
"scripts": { | ||
"build-md": "remark . -qfo", | ||
"build-bundle": "browserify index.js --bare -s nGram > n-gram.js", | ||
"build-mangle": "esmangle n-gram.js > n-gram.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"test-api": "node test.js", | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify . -s nGram > n-gram.js", | ||
"build-mangle": "browserify . -s nGram -p tinyify > n-gram.min.js", | ||
"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" | ||
}, | ||
@@ -53,4 +54,12 @@ "nyc": { | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"prettier": true, | ||
"esnext": false, | ||
@@ -57,0 +66,0 @@ "ignores": [ |
@@ -16,11 +16,14 @@ # n-gram [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
```js | ||
var nGram = require('n-gram'); | ||
var nGram = require('n-gram') | ||
nGram.bigram('n-gram'); // ['n-', '-g', 'gr', 'ra', 'am'] | ||
nGram(2)('n-gram'); // ['n-', '-g', 'gr', 'ra', 'am'] | ||
nGram.bigram('n-gram') // ['n-', '-g', 'gr', 'ra', 'am'] | ||
nGram(2)('n-gram') // ['n-', '-g', 'gr', 'ra', 'am'] | ||
nGram.trigram('n-gram'); // ['n-g', '-gr', 'gra', 'ram'] | ||
nGram.trigram('n-gram') // ['n-g', '-gr', 'gra', 'ram'] | ||
nGram(6)('n-gram'); // ['n-gram'] | ||
nGram(7)('n-gram'); // [] | ||
nGram(6)('n-gram') // ['n-gram'] | ||
nGram(7)('n-gram') // [] | ||
// Anything with a `.length` and `.slice` works: arrays too. | ||
nGram.bigram(['alpha', 'bravo', 'charlie']) // [['alpha', 'bravo'], ['bravo', 'charlie']] | ||
``` | ||
@@ -32,3 +35,3 @@ | ||
Factory returning a function that converts a given string to n-grams. | ||
Factory returning a function that converts a given value to n-grams. | ||
@@ -61,3 +64,3 @@ Want padding? Use something like the following: `nGram(2)(' ' + value + ' ');` | ||
[license]: LICENSE | ||
[license]: license | ||
@@ -64,0 +67,0 @@ [author]: http://wooorm.com |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
4898
67
8
28