Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@metacorp/trie

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metacorp/trie - npm Package Compare versions

Comparing version 0.0.10 to 0.1.0

49

dist/trie.js
/**
* Trie v0.0.10
* Trie v0.1.0
* Copyright 2017 Léopold Szabatura

@@ -16,7 +16,44 @@ * Released under the MIT License

}(this, function() {
var whitespaceRE = /\s+/g;
var whitespaceRE = /\s+/g
var config = {
stopWords: [],
punctuationRE: /[!"',.:;?]/g,
processors: [
function (entry) {
return entry.toLowerCase()
},
function (entry) {
return entry.replace(config.punctuationRE, '')
},
function (entry) {
var stopWords = config.stopWords
var terms = getTerms(entry)
var i = terms.length
while ((i--) !== 0)
{ if (stopWords.indexOf(terms[i]) !== -1)
{ terms.splice(i, 1) } }
return terms.join(' ')
}
]
}
var getTerms = function (entry) {
if (!entry || !entry.length) { return [] }
var terms = entry.split(whitespaceRE)
if (terms[0].length === 0) { terms.shift() }
if (terms[terms.length - 1].length === 0) { terms.pop() }
return terms
}
var processEntry = function (entry) {
if (entry.length) {
for (var i = 0, l = config.processors.length; i < l; i++)
{ entry = config.processors[i](entry) }
}
return getTerms(entry)
}
function bNode(root, word, index) {

@@ -56,3 +93,4 @@ var curr = root

var wordArray = word.toLowerCase().split(' ')
var wordArray = processEntry(word)
if (!wordArray.length) { return }
for (var i = 0, l = wordArray.length; i < l; i++) {

@@ -71,4 +109,5 @@ var word$1 = wordArray[i]

var strArray = processEntry(str)
if (!strArray.length) { return [] }
var res = new Set()
var strArray = str.toLowerCase().split(' ')
for (var i = 0, l = strArray.length; i < l; i++) {

@@ -88,5 +127,5 @@ var str$1 = strArray[i]

Trie.version = "0.0.10"
Trie.version = "0.1.0"
return Trie;
}));

4

dist/trie.min.js
/**
* Trie v0.0.10
* Trie v0.1.0
* Copyright 2017 Léopold Szabatura

@@ -7,2 +7,2 @@ * Released under the MIT License

*/
!function(r,t){"undefined"==typeof module?r.Trie=t():module.exports=t()}(this,function(){function r(r,t,o){for(var n=r,e=0,u=null;u=t.charAt(e);e++,prev=n,n=n[u])n[u]={};return n.$?n.$.push(o):n.$=[o],r}function t(r,o){for(var n=Object.keys(r),e=0,u=n.length;e<u;e++)o(r),"$"!==n[e]&&t(r[n[e]],o)}function o(r){this.words=[],this.root={};for(var t=0,o=r.length;t<o;t++)this.addWord(r[t])}o.prototype.addWord=function(t){for(var o=t.toLowerCase().split(" "),n=0,e=o.length;n<e;n++){var u=o[n],c=this.root,s=0;for(curr=c;curr=curr[u.charAt(s)];s++,c=curr);r(c,u.substr(s),this.words.length)}this.words.push(t)},o.prototype.search=function(r){for(var o=this,n=new Set,e=r.toLowerCase().split(" "),u=0,c=e.length;u<c;u++){var s=e[u],i=o.root,f=0;for(curr=i;curr=curr[s.charAt(f)];f++,i=curr);f===s.length&&t(i,function(r){return r.$&&r.$.forEach(function(r){return n.add(o.words[r])})})}return Array.from(n)};var n=o;return n.config={},n.version="0.0.10",n});
!function(r,t){"undefined"==typeof module?r.Trie=t():module.exports=t()}(this,function(){function r(r,t,n){for(var o=r,e=0,u=null;u=t.charAt(e);e++,prev=o,o=o[u])o[u]={};return o.$?o.$.push(n):o.$=[n],r}function t(r,n){for(var o=Object.keys(r),e=0,u=o.length;e<u;e++)n(r),"$"!==o[e]&&t(r[o[e]],n)}function n(r){this.words=[],this.root={};for(var t=0,n=r.length;t<n;t++)this.addWord(r[t])}var o=/\s+/g,e={stopWords:[],punctuationRE:/[!"',.:;?]/g,processors:[function(r){return r.toLowerCase()},function(r){return r.replace(e.punctuationRE,"")},function(r){for(var t=e.stopWords,n=u(r),o=n.length;0!=o--;)-1!==t.indexOf(n[o])&&n.splice(o,1);return n.join(" ")}]},u=function(r){if(!r||!r.length)return[];var t=r.split(o);return 0===t[0].length&&t.shift(),0===t[t.length-1].length&&t.pop(),t},s=function(r){if(r.length)for(var t=0,n=e.processors.length;t<n;t++)r=e.processors[t](r);return u(r)};n.prototype.addWord=function(t){var n=s(t);if(n.length){for(var o=0,e=n.length;o<e;o++){var u=n[o],i=this.root,c=0;for(curr=i;curr=curr[u.charAt(c)];c++,i=curr);r(i,u.substr(c),this.words.length)}this.words.push(t)}},n.prototype.search=function(r){var n=this,o=s(r);if(!o.length)return[];for(var e=new Set,u=0,i=o.length;u<i;u++){var c=o[u],f=n.root,h=0;for(curr=f;curr=curr[c.charAt(h)];h++,f=curr);h===c.length&&t(f,function(r){return r.$&&r.$.forEach(function(r){return e.add(n.words[r])})})}return Array.from(e)};var i=n;return i.config=e,i.version="0.1.0",i});
/**
* Trie v0.0.10
* Trie v0.1.0
* Copyright 2017 Léopold Szabatura

@@ -16,7 +16,44 @@ * Released under the MIT License

}(this, function() {
var whitespaceRE = /\s+/g;
var whitespaceRE = /\s+/g
var config = {
stopWords: [],
punctuationRE: /[!"',.:;?]/g,
processors: [
function (entry) {
return entry.toLowerCase()
},
function (entry) {
return entry.replace(config.punctuationRE, '')
},
function (entry) {
var stopWords = config.stopWords
var terms = getTerms(entry)
var i = terms.length
while ((i--) !== 0)
{ if (stopWords.indexOf(terms[i]) !== -1)
{ terms.splice(i, 1) } }
return terms.join(' ')
}
]
}
var getTerms = function (entry) {
if (!entry || !entry.length) { return [] }
var terms = entry.split(whitespaceRE)
if (terms[0].length === 0) { terms.shift() }
if (terms[terms.length - 1].length === 0) { terms.pop() }
return terms
}
var processEntry = function (entry) {
if (entry.length) {
for (var i = 0, l = config.processors.length; i < l; i++)
{ entry = config.processors[i](entry) }
}
return getTerms(entry)
}
function bNode(word, index) {

@@ -67,8 +104,7 @@ if (!word || !word.length) {

bTree.prototype.addWord = function (word) {
if (!word || !word.length) { return }
var wordArray = processEntry(word)
if (!wordArray.length) { return }
var index = this.words.length
this.words.push(word)
var prev = this.root,
i = 0;
var wordArray = word.toLowerCase().split(' ')
for (var i = 0, l = wordArray.length; i < l; i++) {

@@ -82,2 +118,3 @@ var word$1 = wordArray[i]

}
this.words.push(word)
}

@@ -88,4 +125,5 @@

var strArray = processEntry(str)
if (!strArray.length) { return [] }
var ret = new Set()
var strArray = str.toLowerCase().split(' ')
for (var i = 0, l = strArray.length; i < l; i++) {

@@ -107,5 +145,5 @@ var str$1 = strArray[i]

Trie1.version = "0.0.10"
Trie1.version = "0.1.0"
return Trie1;
}));
/**
* Trie v0.0.10
* Trie v0.1.0
* Copyright 2017 Léopold Szabatura

@@ -7,2 +7,2 @@ * Released under the MIT License

*/
!function(t,n){"undefined"==typeof module?t.Trie1=n():module.exports=n()}(this,function(){function t(n,r){n&&n.length?(this.value=n[0],1===n.length?(this.addIndex(r),this.children=[]):this.children=[new t(n.substr(1),r)]):(this.value=null,this.children=[])}function n(n){var r=this;this.words=[],this.root=new t,n&&n.forEach(function(t){return r.addWord(t)})}t.prototype.getChild=function(t){if(void 0!==t){var n=this.children.filter(function(n){return n.value===t});return n.length?n[0]:void 0}},t.prototype.addChild=function(t){this.children.push(t)},t.prototype.addIndex=function(t){this.indexes?this.indexes.push(t):this.indexes=[t]},t.prototype.run=function(t){t(this),this.children.forEach(function(n){return n.run(t)})},n.prototype.addWord=function(n){if(n&&n.length){var r=this.words.length;this.words.push(n);for(var e=this.root,i=0,o=n.toLowerCase().split(" "),h=(i=0,o.length);i<h;i++){for(var d=o[i],s=e;s=s.getChild(d.charAt(i));i++,e=s);i>=d.length?e.addIndex(r):e.addChild(new t(d.substr(i),r))}}},n.prototype.search=function(t){for(var n=this,r=new Set,e=t.toLowerCase().split(" "),i=0,o=e.length;i<o;i++){for(var h=e[i],d=n.root,s=(i=0,d);s=s.getChild(h.charAt(i));i++,d=s);i===h.length&&d.run(function(t){return t.indexes&&t.indexes.forEach(function(t){return r.add(n.words[t])})})}return Array.from(r)};var r=n;return r.config={},r.version="0.0.10",r});
!function(t,n){"undefined"==typeof module?t.Trie1=n():module.exports=n()}(this,function(){function t(n,r){n&&n.length?(this.value=n[0],1===n.length?(this.addIndex(r),this.children=[]):this.children=[new t(n.substr(1),r)]):(this.value=null,this.children=[])}function n(n){var r=this;this.words=[],this.root=new t,n&&n.forEach(function(t){return r.addWord(t)})}var r=/\s+/g,e={stopWords:[],punctuationRE:/[!"',.:;?]/g,processors:[function(t){return t.toLowerCase()},function(t){return t.replace(e.punctuationRE,"")},function(t){for(var n=e.stopWords,r=o(t),i=r.length;0!=i--;)-1!==n.indexOf(r[i])&&r.splice(i,1);return r.join(" ")}]},o=function(t){if(!t||!t.length)return[];var n=t.split(r);return 0===n[0].length&&n.shift(),0===n[n.length-1].length&&n.pop(),n},i=function(t){if(t.length)for(var n=0,r=e.processors.length;n<r;n++)t=e.processors[n](t);return o(t)};t.prototype.getChild=function(t){if(void 0!==t){var n=this.children.filter(function(n){return n.value===t});return n.length?n[0]:void 0}},t.prototype.addChild=function(t){this.children.push(t)},t.prototype.addIndex=function(t){this.indexes?this.indexes.push(t):this.indexes=[t]},t.prototype.run=function(t){t(this),this.children.forEach(function(n){return n.run(t)})},n.prototype.addWord=function(n){var r=i(n);if(r.length){for(var e=this.words.length,o=this.root,h=0,s=(h=0,r.length);h<s;h++){for(var u=r[h],d=o;d=d.getChild(u.charAt(h));h++,o=d);h>=u.length?o.addIndex(e):o.addChild(new t(u.substr(h),e))}this.words.push(n)}},n.prototype.search=function(t){var n=this,r=i(t);if(!r.length)return[];for(var e=new Set,o=0,h=r.length;o<h;o++){for(var s=r[o],u=n.root,d=(o=0,u);d=d.getChild(s.charAt(o));o++,u=d);o===s.length&&u.run(function(t){return t.indexes&&t.indexes.forEach(function(t){return e.add(n.words[t])})})}return Array.from(e)};var h=n;return h.config=e,h.version="0.1.0",h});
{
"name": "@metacorp/trie",
"version": "0.0.10",
"version": "0.1.0",
"description": "Blazing fast, 1kb search library",

@@ -5,0 +5,0 @@ "main": "dist/trie.min.js",

@@ -1,6 +0,43 @@

const whitespaceRE = /\s+/g;
const whitespaceRE = /\s+/g
const config = {
stopWords: [],
punctuationRE: /[!"',.:;?]/g,
processors: [
function (entry) {
return entry.toLowerCase()
},
function (entry) {
return entry.replace(config.punctuationRE, '')
},
function (entry) {
const stopWords = config.stopWords
const terms = getTerms(entry)
var i = terms.length
while ((i--) !== 0)
if (stopWords.indexOf(terms[i]) !== -1)
terms.splice(i, 1)
return terms.join(' ')
}
]
}
const getTerms = function (entry) {
if (!entry || !entry.length) return []
const terms = entry.split(whitespaceRE)
if (terms[0].length === 0) terms.shift()
if (terms[terms.length - 1].length === 0) terms.pop()
return terms
}
const processEntry = function (entry) {
if (entry.length) {
for (let i = 0, l = config.processors.length; i < l; i++)
entry = config.processors[i](entry)
}
return getTerms(entry)
}
function bNode(root, word, index) {

@@ -36,3 +73,4 @@ var curr = root

bTree.prototype.addWord = function (word) {
const wordArray = word.toLowerCase().split(' ')
const wordArray = processEntry(word)
if (!wordArray.length) return
for (var i = 0, l = wordArray.length; i < l; i++) {

@@ -49,4 +87,5 @@ const word = wordArray[i]

bTree.prototype.search = function (str) {
const strArray = processEntry(str)
if (!strArray.length) return []
const res = new Set()
const strArray = str.toLowerCase().split(' ')
for (var i = 0, l = strArray.length; i < l; i++) {

@@ -53,0 +92,0 @@ const str = strArray[i]

@@ -1,6 +0,43 @@

const whitespaceRE = /\s+/g;
const whitespaceRE = /\s+/g
const config = {
stopWords: [],
punctuationRE: /[!"',.:;?]/g,
processors: [
function (entry) {
return entry.toLowerCase()
},
function (entry) {
return entry.replace(config.punctuationRE, '')
},
function (entry) {
const stopWords = config.stopWords
const terms = getTerms(entry)
var i = terms.length
while ((i--) !== 0)
if (stopWords.indexOf(terms[i]) !== -1)
terms.splice(i, 1)
return terms.join(' ')
}
]
}
const getTerms = function (entry) {
if (!entry || !entry.length) return []
const terms = entry.split(whitespaceRE)
if (terms[0].length === 0) terms.shift()
if (terms[terms.length - 1].length === 0) terms.pop()
return terms
}
const processEntry = function (entry) {
if (entry.length) {
for (let i = 0, l = config.processors.length; i < l; i++)
entry = config.processors[i](entry)
}
return getTerms(entry)
}
function bNode(word, index) {

@@ -49,8 +86,7 @@ if (!word || !word.length) {

bTree.prototype.addWord = function (word) {
if (!word || !word.length) return
const wordArray = processEntry(word)
if (!wordArray.length) return
const index = this.words.length
this.words.push(word)
var prev = this.root,
i = 0;
const wordArray = word.toLowerCase().split(' ')
for (var i = 0, l = wordArray.length; i < l; i++) {

@@ -64,7 +100,9 @@ const word = wordArray[i]

}
this.words.push(word)
}
bTree.prototype.search = function (str) {
const strArray = processEntry(str)
if (!strArray.length) return []
const ret = new Set()
const strArray = str.toLowerCase().split(' ')
for (var i = 0, l = strArray.length; i < l; i++) {

@@ -71,0 +109,0 @@ const str = strArray[i]

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