New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

n-gram

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

n-gram - npm Package Compare versions

Comparing version 0.1.2 to 1.0.0

readme.md

112

index.js
'use strict';
/**
* A factory returning a function that converts a given string to n-grams.
*
* @example
* nGram(2) // [Function]
*
* @example
* nGram(4) // [Function]
*
*
* @param {number} n - The `n` in n-gram.
* @throws {Error} When `n` is not a number (incl. NaN), Infinity, or lt 1.
* @return {Function} A function creating n-grams from a given value.
*/
function nGram(n) {
if (
typeof n !== 'number' ||
n < 1 ||
n !== n ||
n === Infinity
) {
throw new Error(
'Type error: `' + n + '` is not a valid argument for n-gram'
);
}
/* Expose. */
module.exports = exports = nGram;
/*
* Create n-grams from a given value.
*
* @example
* nGram(4)('n-gram')
* // ['n-gr', '-gra', 'gram']
*
* @param {*} value - The value to stringify and convert into n-grams.
* @return {Array.<string>} n-grams
*/
exports.bigram = nGram(2);
exports.trigram = nGram(3);
return function (value) {
var nGrams,
index;
/* Factory returning a function that converts a given 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');
}
nGrams = [];
return grams;
if (value === null || value === undefined) {
return nGrams;
}
/* Create n-grams from a given value. */
function grams(value) {
var nGrams = [];
var index;
value = String(value);
if (value === null || value === undefined) {
return nGrams;
}
index = value.length - n + 1;
value = String(value);
index = value.length - n + 1;
if (index < 1) {
return nGrams;
}
if (index < 1) {
return nGrams;
}
while (index--) {
nGrams[index] = value.substr(index, n);
}
while (index--) {
nGrams[index] = value.substr(index, n);
}
return nGrams;
};
return nGrams;
}
}
/*
* Export `n-gram`.
*/
module.exports = nGram;
/*
* Create bigrams from a given value.
*
* @example
* bigram('n-gram')
* // ["n-", "-g", "gr", "ra", "am"]
*
* @param {*} value - The value to stringify and convert into bigrams.
* @return {Array.<string>} bigrams
*/
nGram.bigram = nGram(2);
/*
* Create trigrams from a given value.
*
* @example
* trigram('n-gram')
* // ["n-g", "-gr", "gra", "ram"]
*
* @param {*} value - The value to stringify and convert into trigrams.
* @return {Array.<string>} trigrams
*/
nGram.trigram = nGram(3);
{
"name": "n-gram",
"version": "0.1.2",
"version": "1.0.0",
"description": "Get n-grams from text",

@@ -16,36 +16,47 @@ "license": "MIT",

],
"repository": {
"type": "git",
"url": "https://github.com/wooorm/n-gram.git"
},
"author": "Titus Wormer <tituswormer@gmail.com>",
"repository": "https://github.com/wooorm/n-gram",
"bugs": "https://github.com/wooorm/n-gram/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)"
],
"files": [
"index.js"
],
"dependencies": {},
"devDependencies": {
"browserify": "^8.0.0",
"eslint": "^0.12.0",
"browserify": "^13.0.0",
"esmangle": "^1.0.0",
"istanbul": "^0.3.0",
"jscs": "^1.0.0",
"jscs-jsdoc": "^0.4.0",
"matcha": "^0.6.0",
"mocha": "^2.0.0",
"ngram": "madbence/node-ngram"
"nyc": "^8.3.1",
"remark-cli": "^2.0.0",
"remark-preset-wooorm": "^1.0.0",
"tape": "^4.0.0",
"xo": "^0.17.0"
},
"scripts": {
"test-api": "_mocha --check-leaks test.js",
"test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test.js",
"test-coverage": "istanbul cover _mocha -- test.js",
"test-travis": "npm run test-coveralls",
"test": "npm run test-api",
"lint-api": "eslint index.js",
"lint-test": "eslint --env mocha test.js",
"lint-benchmark": "eslint --global set,suite,bench benchmark.js",
"lint-style": "jscs --reporter inline index.js test.js benchmark.js",
"lint": "npm run lint-api && npm run lint-test && npm run lint-benchmark && npm run lint-style",
"make": "npm run lint && npm run test-coverage",
"benchmark": "matcha benchmark.js",
"bundle": "browserify index.js -s nGram > n-gram.js",
"postbundle": "esmangle n-gram.js > n-gram.min.js",
"build": "npm run bundle",
"prepublish": "npm run build"
"build-md": "remark . --quiet --frail",
"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",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run build && npm run lint && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"xo": {
"space": true,
"ignores": [
"n-gram.js"
]
},
"remarkConfig": {
"output": true,
"presets": "wooorm"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc