summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/n-gram/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/n-gram/index.js')
-rw-r--r--bin/wiki/ImportarDesdeURL/node_modules/n-gram/index.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/n-gram/index.js b/bin/wiki/ImportarDesdeURL/node_modules/n-gram/index.js
new file mode 100644
index 00000000..6346fd63
--- /dev/null
+++ b/bin/wiki/ImportarDesdeURL/node_modules/n-gram/index.js
@@ -0,0 +1,38 @@
+'use strict'
+
+module.exports = nGram
+
+nGram.bigram = nGram(2)
+nGram.trigram = nGram(3)
+
+// 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')
+ }
+
+ return grams
+
+ // Create n-grams from a given value.
+ function grams(value) {
+ var nGrams = []
+ var index
+
+ if (value === null || value === undefined) {
+ return nGrams
+ }
+
+ value = value.slice ? value : String(value)
+ index = value.length - n + 1
+
+ if (index < 1) {
+ return nGrams
+ }
+
+ while (index--) {
+ nGrams[index] = value.slice(index, index + n)
+ }
+
+ return nGrams
+ }
+}