Socket
Socket
Sign inDemoInstall

efrt

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

efrt - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

changelog.md

4

builds/efrt-unpack.es5.js

@@ -73,4 +73,4 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.unpack = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

var k = arr[i];
if (all[k] !== undefined) {
if (typeof all[k] === 'string') {
if (all.hasOwnProperty(k) === true) {
if (Array.isArray(all[k]) === false) {
all[k] = [all[k], cat];

@@ -77,0 +77,0 @@ } else {

@@ -1,2 +0,2 @@

/* efrt trie-compression v1.1.0 github.com/nlp-compromise/efrt - MIT */
/* efrt trie-compression v1.1.1 github.com/nlp-compromise/efrt - MIT */
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.unpack = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

@@ -59,31 +59,31 @@ 'use strict';

},{}],2:[function(_dereq_,module,exports){
'use strict';
const unpack = _dereq_('./unpack');
'use strict'
const unpack = _dereq_('./unpack')
module.exports = function(obj) {
if (typeof obj === 'string') {
obj = JSON.parse(obj); //weee!
obj = JSON.parse(obj) //weee!
}
let all = {};
let all = {}
Object.keys(obj).forEach(function(cat) {
let arr = unpack(obj[cat]);
let arr = unpack(obj[cat])
//special case, for botched-boolean
if (cat === 'true') {
cat = true;
cat = true
}
for (var i = 0; i < arr.length; i++) {
let k = arr[i];
if (all[k] !== undefined) {
if (typeof all[k] === 'string') {
all[k] = [all[k], cat];
let k = arr[i]
if (all.hasOwnProperty(k) === true) {
if (Array.isArray(all[k]) === false) {
all[k] = [all[k], cat]
} else {
all[k].push(cat);
all[k].push(cat)
}
} else {
all[k] = cat;
all[k] = cat
}
}
});
return all;
};
})
return all
}

@@ -90,0 +90,0 @@ },{"./unpack":4}],3:[function(_dereq_,module,exports){

@@ -1,2 +0,2 @@

/* efrt trie-compression v1.1.0 github.com/nlp-compromise/efrt - MIT */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.unpack=e()}}(function(){return function e(n,r,o){function t(f,u){if(!r[f]){if(!n[f]){var s="function"==typeof require&&require;if(!u&&s)return s(f,!0);if(i)return i(f,!0);var a=new Error("Cannot find module '"+f+"'");throw a.code="MODULE_NOT_FOUND",a}var c=r[f]={exports:{}};n[f][0].call(c.exports,function(e){var r=n[f][1][e];return t(r?r:e)},c,c.exports,e,n,r,o)}return r[f].exports}for(var i="function"==typeof require&&require,f=0;f<o.length;f++)t(o[f]);return t}({1:[function(e,n,r){"use strict";var o=36,t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i=t.split("").reduce(function(e,n,r){return e[n]=r,e},{}),f=function(e){if(void 0!==t[e])return t[e];for(var n=1,r=o,i="";e>=r;e-=r,n++,r*=o);for(;n--;){var f=e%o;i=String.fromCharCode((f<10?48:55)+f)+i,e=(e-f)/o}return i},u=function(e){if(void 0!==i[e])return i[e];for(var n=0,r=1,t=o,f=1;r<e.length;n+=t,r++,t*=o);for(var u=e.length-1;u>=0;u--,f*=o){var s=e.charCodeAt(u)-48;s>10&&(s-=7),n+=s*f}return n};n.exports={toAlphaCode:f,fromAlphaCode:u}},{}],2:[function(e,n,r){"use strict";var o=e("./unpack");n.exports=function(e){"string"==typeof e&&(e=JSON.parse(e));var n={};return Object.keys(e).forEach(function(r){var t=o(e[r]);"true"===r&&(r=!0);for(var i=0;i<t.length;i++){var f=t[i];void 0!==n[f]?"string"==typeof n[f]?n[f]=[n[f],r]:n[f].push(r):n[f]=r}}),n}},{"./unpack":4}],3:[function(e,n,r){"use strict";var o=e("../encoding");n.exports=function(e){for(var n=new RegExp("([0-9A-Z]+):([0-9A-Z]+)"),r=0;r<e.nodes.length;r++){var t=n.exec(e.nodes[r]);if(!t){e.symCount=r;break}e.syms[o.fromAlphaCode(t[1])]=o.fromAlphaCode(t[2])}e.nodes=e.nodes.slice(e.symCount,e.nodes.length)}},{"../encoding":1}],4:[function(e,n,r){"use strict";var o=e("./symbols"),t=e("../encoding"),i=function(e,n,r){var o=t.fromAlphaCode(n);return o<e.symCount?e.syms[o]:r+o+1-e.symCount},f=function(e){var n=[],r=function r(o,t){var f=e.nodes[o];"!"===f[0]&&(n.push(t),f=f.slice(1));for(var u=f.split(/([A-Z0-9,]+)/g),s=0;s<u.length;s+=2){var a=u[s],c=u[s+1];if(a){var d=t+a;if(","!==c&&void 0!==c){var p=i(e,c,o);r(p,d)}else n.push(d)}}};return r(0,""),n},u=function(e){var n={nodes:e.split(";"),syms:[],symCount:0};return e.match(":")&&o(n),f(n)};n.exports=u},{"../encoding":1,"./symbols":3}]},{},[2])(2)});
/* efrt trie-compression v1.1.1 github.com/nlp-compromise/efrt - MIT */
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r;r="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,r.unpack=e()}}(function(){return function e(r,n,o){function t(f,u){if(!n[f]){if(!r[f]){var s="function"==typeof require&&require;if(!u&&s)return s(f,!0);if(i)return i(f,!0);var a=new Error("Cannot find module '"+f+"'");throw a.code="MODULE_NOT_FOUND",a}var c=n[f]={exports:{}};r[f][0].call(c.exports,function(e){var n=r[f][1][e];return t(n?n:e)},c,c.exports,e,r,n,o)}return n[f].exports}for(var i="function"==typeof require&&require,f=0;f<o.length;f++)t(o[f]);return t}({1:[function(e,r,n){"use strict";var o=36,t="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",i=t.split("").reduce(function(e,r,n){return e[r]=n,e},{}),f=function(e){if(void 0!==t[e])return t[e];for(var r=1,n=o,i="";e>=n;e-=n,r++,n*=o);for(;r--;){var f=e%o;i=String.fromCharCode((f<10?48:55)+f)+i,e=(e-f)/o}return i},u=function(e){if(void 0!==i[e])return i[e];for(var r=0,n=1,t=o,f=1;n<e.length;r+=t,n++,t*=o);for(var u=e.length-1;u>=0;u--,f*=o){var s=e.charCodeAt(u)-48;s>10&&(s-=7),r+=s*f}return r};r.exports={toAlphaCode:f,fromAlphaCode:u}},{}],2:[function(e,r,n){"use strict";var o=e("./unpack");r.exports=function(e){"string"==typeof e&&(e=JSON.parse(e));var r={};return Object.keys(e).forEach(function(n){var t=o(e[n]);"true"===n&&(n=!0);for(var i=0;i<t.length;i++){var f=t[i];r.hasOwnProperty(f)===!0?Array.isArray(r[f])===!1?r[f]=[r[f],n]:r[f].push(n):r[f]=n}}),r}},{"./unpack":4}],3:[function(e,r,n){"use strict";var o=e("../encoding");r.exports=function(e){for(var r=new RegExp("([0-9A-Z]+):([0-9A-Z]+)"),n=0;n<e.nodes.length;n++){var t=r.exec(e.nodes[n]);if(!t){e.symCount=n;break}e.syms[o.fromAlphaCode(t[1])]=o.fromAlphaCode(t[2])}e.nodes=e.nodes.slice(e.symCount,e.nodes.length)}},{"../encoding":1}],4:[function(e,r,n){"use strict";var o=e("./symbols"),t=e("../encoding"),i=function(e,r,n){var o=t.fromAlphaCode(r);return o<e.symCount?e.syms[o]:n+o+1-e.symCount},f=function(e){var r=[],n=function n(o,t){var f=e.nodes[o];"!"===f[0]&&(r.push(t),f=f.slice(1));for(var u=f.split(/([A-Z0-9,]+)/g),s=0;s<u.length;s+=2){var a=u[s],c=u[s+1];if(a){var d=t+a;if(","!==c&&void 0!==c){var p=i(e,c,o);n(p,d)}else r.push(d)}}};return n(0,""),r},u=function(e){var r={nodes:e.split(";"),syms:[],symCount:0};return e.match(":")&&o(r),f(r)};r.exports=u},{"../encoding":1,"./symbols":3}]},{},[2])(2)});

@@ -1,2 +0,2 @@

/* efrt trie-compression v1.1.0 github.com/nlp-compromise/efrt - MIT */
/* efrt trie-compression v1.1.1 github.com/nlp-compromise/efrt - MIT */
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.efrt = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){

@@ -678,4 +678,4 @@ 'use strict';

var k = arr[i];
if (all[k] !== undefined) {
if (typeof all[k] === 'string') {
if (all.hasOwnProperty(k) === true) {
if (Array.isArray(all[k]) === false) {
all[k] = [all[k], cat];

@@ -682,0 +682,0 @@ } else {

@@ -1,2 +0,2 @@

/* efrt trie-compression v1.1.0 github.com/nlp-compromise/efrt - MIT */
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.efrt=t()}}(function(){var t;return function t(n,e,o){function i(s,u){if(!e[s]){if(!n[s]){var f="function"==typeof require&&require;if(!u&&f)return f(s,!0);if(r)return r(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var d=e[s]={exports:{}};n[s][0].call(d.exports,function(t){var e=n[s][1][t];return i(e?e:t)},d,d.exports,t,n,e,o)}return e[s].exports}for(var r="function"==typeof require&&require,s=0;s<o.length;s++)i(o[s]);return i}({1:[function(t,n,e){"use strict";var o=36,i="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",r=i.split("").reduce(function(t,n,e){return t[n]=e,t},{}),s=function(t){if(void 0!==i[t])return i[t];for(var n=1,e=o,r="";t>=e;t-=e,n++,e*=o);for(;n--;){var s=t%o;r=String.fromCharCode((s<10?48:55)+s)+r,t=(t-s)/o}return r},u=function(t){if(void 0!==r[t])return r[t];for(var n=0,e=1,i=o,s=1;e<t.length;n+=i,e++,i*=o);for(var u=t.length-1;u>=0;u--,s*=o){var f=t.charCodeAt(u)-48;f>10&&(f-=7),n+=f*s}return n};n.exports={toAlphaCode:s,fromAlphaCode:u}},{}],2:[function(n,e,o){(function(o){"use strict";var i={pack:n("./pack/index"),unpack:n("./unpack/index")};"undefined"!=typeof self?self.efrt=i:"undefined"!=typeof window?window.efrt=i:"undefined"!=typeof o&&(o.efrt=i),"function"==typeof t&&t.amd&&t(i),"undefined"!=typeof e&&(e.exports=i)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./pack/index":5,"./unpack/index":9}],3:[function(t,n,e){"use strict";var o=function(t,n){for(var e=Math.min(t.length,n.length);e>0;){var o=t.slice(0,e);if(o===n.slice(0,e))return o;e-=1}return""},i=function(t){t.sort();for(var n=1;n<t.length;n++)t[n-1]===t[n]&&t.splice(n,1)};n.exports={commonPrefix:o,unique:i}},{}],4:[function(t,n,e){"use strict";var o=function(){this.counts={}},i={init:function(t){void 0===this.counts[t]&&(this.counts[t]=0)},add:function(t,n){void 0===n&&(n=1),this.init(t),this.counts[t]+=n},countOf:function(t){return this.init(t),this.counts[t]},highest:function(t){for(var n=[],e=Object.keys(this.counts),o=0;o<e.length;o++){var i=e[o];n.push([i,this.counts[i]])}return n.sort(function(t,n){return n[1]-t[1]}),t&&(n=n.slice(0,t)),n}};Object.keys(i).forEach(function(t){o.prototype[t]=i[t]}),n.exports=o},{}],5:[function(t,n,e){"use strict";var o=t("./trie"),i=function(t){return"[object Array]"===Object.prototype.toString.call(t)},r=function(t){return null===t||void 0===t?{}:"string"==typeof t?t.split(/ +/g).reduce(function(t,n){return t[n]=!0,t},{}):i(t)?t.reduce(function(t,n){return t[n]=!0,t},{}):t},s=function(t){t=r(t);var n=Object.keys(t).reduce(function(n,e){var o=t[e];if(i(o)){for(var r=0;r<o.length;r++)n[o[r]]=n[o[r]]||[],n[o[r]].push(e);return n}return n[o]=n[o]||[],n[o].push(e),n},{});return Object.keys(n).forEach(function(t){var e=new o(n[t]);n[t]=e.pack()}),n=JSON.stringify(n,null,0)};n.exports=s},{"./trie":8}],6:[function(t,n,e){"use strict";var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=t("./fns"),r=t("./pack"),s=new RegExp("[0-9A-Z,;!]");n.exports={insertWords:function(t){if(void 0!==t){"string"==typeof t&&(t=t.split(/[^a-zA-Z]+/));for(var n=0;n<t.length;n++)t[n]=t[n].toLowerCase();i.unique(t);for(var e=0;e<t.length;e++)null===t[e].match(s)&&this.insert(t[e])}},insert:function(t){this._insert(t,this.root);var n=this.lastWord;this.lastWord=t;var e=i.commonPrefix(t,n);if(e!==n){var o=this.uniqueNode(n,t,this.root);o&&this.combineSuffixNode(o)}},_insert:function(t,n){var e=void 0,r=void 0;if(0!==t.length){for(var s=Object.keys(n),u=0;u<s.length;u++){var f=s[u];if(e=i.commonPrefix(t,f),0!==e.length){if(f===e&&"object"===o(n[f]))return void this._insert(t.slice(e.length),n[f]);if(f===t&&"number"==typeof n[f])return;return r={},r[f.slice(e.length)]=n[f],this.addTerminal(r,t=t.slice(e.length)),delete n[f],n[e]=r,void this.wordCount++}}this.addTerminal(n,t),this.wordCount++}},addTerminal:function(t,n){if(n.length<=1)return void(t[n]=1);var e={};t[n[0]]=e,this.addTerminal(e,n.slice(1))},nodeProps:function(t,n){var e=[];for(var i in t)""!==i&&"_"!==i[0]&&(n&&"object"!==o(t[i])||e.push(i));return e.sort(),e},optimize:function(){this.combineSuffixNode(this.root),this.prepDFS(),this.countDegree(this.root),this.prepDFS(),this.collapseChains(this.root)},combineSuffixNode:function(t){if(t._c)return t;var n=[];this.isTerminal(t)&&n.push("!");for(var e=this.nodeProps(t),i=0;i<e.length;i++){var r=e[i];"object"===o(t[r])?(t[r]=this.combineSuffixNode(t[r]),n.push(r),n.push(t[r]._c)):n.push(r)}n=n.join("-");var s=this.suffixes[n];return s?s:(this.suffixes[n]=t,t._c=this.cNext++,t)},prepDFS:function(){this.vCur++},visited:function(t){return t._v===this.vCur||(t._v=this.vCur,!1)},countDegree:function(t){if(void 0===t._d&&(t._d=0),t._d++,!this.visited(t))for(var n=this.nodeProps(t,!0),e=0;e<n.length;e++)this.countDegree(t[n[e]])},collapseChains:function(t){var n=void 0,e=void 0,i=void 0,r=void 0;if(!this.visited(t)){for(e=this.nodeProps(t),r=0;r<e.length;r++)n=e[r],i=t[n],"object"===("undefined"==typeof i?"undefined":o(i))&&(this.collapseChains(i),void 0===i._g||1!==i._d&&1!==i._g.length||(delete t[n],n+=i._g,t[n]=i[i._g]));1!==e.length||this.isTerminal(t)||(t._g=n)}},isTerminal:function(t){return!!t[""]},uniqueNode:function(t,n,e){for(var o=this.nodeProps(e,!0),i=0;i<o.length;i++){var r=o[i];if(r===t.slice(0,r.length))return r!==n.slice(0,r.length)?e[r]:this.uniqueNode(t.slice(r.length),n.slice(r.length),e[r])}},pack:function(){return r(this)}}},{"./fns":3,"./pack":7}],7:[function(t,n,e){"use strict";var o=t("./histogram"),i=t("../encoding"),r={NODE_SEP:";",STRING_SEP:",",TERMINAL_PREFIX:"!",BASE:36},s=function(t,n){var e="",o="";t.isTerminal(n)&&(e+=r.TERMINAL_PREFIX);for(var s=t.nodeProps(n),u=0;u<s.length;u++){var f=s[u];if("number"!=typeof n[f])if(t.syms[n[f]._n])e+=o+f+t.syms[n[f]._n],o="";else{var c=i.toAlphaCode(n._n-n[f]._n-1+t.symCount);n[f]._g&&c.length>=n[f]._g.length&&1===n[n[f]._g]?(c=n[f]._g,e+=o+f+c,o=r.STRING_SEP):(e+=o+f+c,o="")}else e+=o+f,o=r.STRING_SEP}return e},u=function t(n,e){if(!n.visited(e))for(var o=n.nodeProps(e,!0),s=0;s<o.length;s++){var u=o[s],f=e._n-e[u]._n-1;f<r.BASE&&n.histRel.add(f),n.histAbs.add(e[u]._n,i.toAlphaCode(f).length-1),t(n,e[u])}},f=function(t){t.histAbs=t.histAbs.highest(r.BASE);var n=[];n[-1]=0;for(var e=0,o=0,s=3+i.toAlphaCode(t.nodeCount).length,u=0;u<r.BASE&&void 0!==t.histAbs[u];u++)n[u]=t.histAbs[u][1]-s-t.histRel.countOf(r.BASE-u-1)+n[u-1],n[u]>=e&&(e=n[u],o=u+1);return o},c=function t(n,e){if(void 0===e._n){for(var o=n.nodeProps(e,!0),i=0;i<o.length;i++)t(n,e[o[i]]);e._n=n.pos++,n.nodes.unshift(e)}},d=function(t){t.nodes=[],t.nodeCount=0,t.syms={},t.symCount=0,t.pos=0,t.optimize(),t.histAbs=new o,t.histRel=new o,c(t,t.root),t.nodeCount=t.nodes.length,t.prepDFS(),u(t,t.root),t.symCount=f(t);for(var n=0;n<t.symCount;n++)t.syms[t.histAbs[n][0]]=i.toAlphaCode(n);for(var e=0;e<t.nodeCount;e++)t.nodes[e]=s(t,t.nodes[e]);for(var d=t.symCount-1;d>=0;d--)t.nodes.unshift(i.toAlphaCode(d)+":"+i.toAlphaCode(t.nodeCount-t.histAbs[d][0]-1));return t.nodes.join(r.NODE_SEP)};n.exports=d},{"../encoding":1,"./histogram":4}],8:[function(t,n,e){"use strict";var o=t("./methods"),i=function(t){this.root={},this.lastWord="",this.suffixes={},this.suffixCounts={},this.cNext=1,this.wordCount=0,this.insertWords(t),this.vCur=0};Object.keys(o).forEach(function(t){i.prototype[t]=o[t]}),n.exports=i},{"./methods":6}],9:[function(t,n,e){"use strict";var o=t("./unpack");n.exports=function(t){"string"==typeof t&&(t=JSON.parse(t));var n={};return Object.keys(t).forEach(function(e){var i=o(t[e]);"true"===e&&(e=!0);for(var r=0;r<i.length;r++){var s=i[r];void 0!==n[s]?"string"==typeof n[s]?n[s]=[n[s],e]:n[s].push(e):n[s]=e}}),n}},{"./unpack":11}],10:[function(t,n,e){"use strict";var o=t("../encoding");n.exports=function(t){for(var n=new RegExp("([0-9A-Z]+):([0-9A-Z]+)"),e=0;e<t.nodes.length;e++){var i=n.exec(t.nodes[e]);if(!i){t.symCount=e;break}t.syms[o.fromAlphaCode(i[1])]=o.fromAlphaCode(i[2])}t.nodes=t.nodes.slice(t.symCount,t.nodes.length)}},{"../encoding":1}],11:[function(t,n,e){"use strict";var o=t("./symbols"),i=t("../encoding"),r=function(t,n,e){var o=i.fromAlphaCode(n);return o<t.symCount?t.syms[o]:e+o+1-t.symCount},s=function(t){var n=[],e=function e(o,i){var s=t.nodes[o];"!"===s[0]&&(n.push(i),s=s.slice(1));for(var u=s.split(/([A-Z0-9,]+)/g),f=0;f<u.length;f+=2){var c=u[f],d=u[f+1];if(c){var h=i+c;if(","!==d&&void 0!==d){var a=r(t,d,o);e(a,h)}else n.push(h)}}};return e(0,""),n},u=function(t){var n={nodes:t.split(";"),syms:[],symCount:0};return t.match(":")&&o(n),s(n)};n.exports=u},{"../encoding":1,"./symbols":10}]},{},[2])(2)});
/* efrt trie-compression v1.1.1 github.com/nlp-compromise/efrt - MIT */
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.efrt=t()}}(function(){var t;return function t(n,e,o){function i(s,u){if(!e[s]){if(!n[s]){var f="function"==typeof require&&require;if(!u&&f)return f(s,!0);if(r)return r(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var d=e[s]={exports:{}};n[s][0].call(d.exports,function(t){var e=n[s][1][t];return i(e?e:t)},d,d.exports,t,n,e,o)}return e[s].exports}for(var r="function"==typeof require&&require,s=0;s<o.length;s++)i(o[s]);return i}({1:[function(t,n,e){"use strict";var o=36,i="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",r=i.split("").reduce(function(t,n,e){return t[n]=e,t},{}),s=function(t){if(void 0!==i[t])return i[t];for(var n=1,e=o,r="";t>=e;t-=e,n++,e*=o);for(;n--;){var s=t%o;r=String.fromCharCode((s<10?48:55)+s)+r,t=(t-s)/o}return r},u=function(t){if(void 0!==r[t])return r[t];for(var n=0,e=1,i=o,s=1;e<t.length;n+=i,e++,i*=o);for(var u=t.length-1;u>=0;u--,s*=o){var f=t.charCodeAt(u)-48;f>10&&(f-=7),n+=f*s}return n};n.exports={toAlphaCode:s,fromAlphaCode:u}},{}],2:[function(n,e,o){(function(o){"use strict";var i={pack:n("./pack/index"),unpack:n("./unpack/index")};"undefined"!=typeof self?self.efrt=i:"undefined"!=typeof window?window.efrt=i:"undefined"!=typeof o&&(o.efrt=i),"function"==typeof t&&t.amd&&t(i),"undefined"!=typeof e&&(e.exports=i)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./pack/index":5,"./unpack/index":9}],3:[function(t,n,e){"use strict";var o=function(t,n){for(var e=Math.min(t.length,n.length);e>0;){var o=t.slice(0,e);if(o===n.slice(0,e))return o;e-=1}return""},i=function(t){t.sort();for(var n=1;n<t.length;n++)t[n-1]===t[n]&&t.splice(n,1)};n.exports={commonPrefix:o,unique:i}},{}],4:[function(t,n,e){"use strict";var o=function(){this.counts={}},i={init:function(t){void 0===this.counts[t]&&(this.counts[t]=0)},add:function(t,n){void 0===n&&(n=1),this.init(t),this.counts[t]+=n},countOf:function(t){return this.init(t),this.counts[t]},highest:function(t){for(var n=[],e=Object.keys(this.counts),o=0;o<e.length;o++){var i=e[o];n.push([i,this.counts[i]])}return n.sort(function(t,n){return n[1]-t[1]}),t&&(n=n.slice(0,t)),n}};Object.keys(i).forEach(function(t){o.prototype[t]=i[t]}),n.exports=o},{}],5:[function(t,n,e){"use strict";var o=t("./trie"),i=function(t){return"[object Array]"===Object.prototype.toString.call(t)},r=function(t){return null===t||void 0===t?{}:"string"==typeof t?t.split(/ +/g).reduce(function(t,n){return t[n]=!0,t},{}):i(t)?t.reduce(function(t,n){return t[n]=!0,t},{}):t},s=function(t){t=r(t);var n=Object.keys(t).reduce(function(n,e){var o=t[e];if(i(o)){for(var r=0;r<o.length;r++)n[o[r]]=n[o[r]]||[],n[o[r]].push(e);return n}return n[o]=n[o]||[],n[o].push(e),n},{});return Object.keys(n).forEach(function(t){var e=new o(n[t]);n[t]=e.pack()}),n=JSON.stringify(n,null,0)};n.exports=s},{"./trie":8}],6:[function(t,n,e){"use strict";var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=t("./fns"),r=t("./pack"),s=new RegExp("[0-9A-Z,;!]");n.exports={insertWords:function(t){if(void 0!==t){"string"==typeof t&&(t=t.split(/[^a-zA-Z]+/));for(var n=0;n<t.length;n++)t[n]=t[n].toLowerCase();i.unique(t);for(var e=0;e<t.length;e++)null===t[e].match(s)&&this.insert(t[e])}},insert:function(t){this._insert(t,this.root);var n=this.lastWord;this.lastWord=t;var e=i.commonPrefix(t,n);if(e!==n){var o=this.uniqueNode(n,t,this.root);o&&this.combineSuffixNode(o)}},_insert:function(t,n){var e=void 0,r=void 0;if(0!==t.length){for(var s=Object.keys(n),u=0;u<s.length;u++){var f=s[u];if(e=i.commonPrefix(t,f),0!==e.length){if(f===e&&"object"===o(n[f]))return void this._insert(t.slice(e.length),n[f]);if(f===t&&"number"==typeof n[f])return;return r={},r[f.slice(e.length)]=n[f],this.addTerminal(r,t=t.slice(e.length)),delete n[f],n[e]=r,void this.wordCount++}}this.addTerminal(n,t),this.wordCount++}},addTerminal:function(t,n){if(n.length<=1)return void(t[n]=1);var e={};t[n[0]]=e,this.addTerminal(e,n.slice(1))},nodeProps:function(t,n){var e=[];for(var i in t)""!==i&&"_"!==i[0]&&(n&&"object"!==o(t[i])||e.push(i));return e.sort(),e},optimize:function(){this.combineSuffixNode(this.root),this.prepDFS(),this.countDegree(this.root),this.prepDFS(),this.collapseChains(this.root)},combineSuffixNode:function(t){if(t._c)return t;var n=[];this.isTerminal(t)&&n.push("!");for(var e=this.nodeProps(t),i=0;i<e.length;i++){var r=e[i];"object"===o(t[r])?(t[r]=this.combineSuffixNode(t[r]),n.push(r),n.push(t[r]._c)):n.push(r)}n=n.join("-");var s=this.suffixes[n];return s?s:(this.suffixes[n]=t,t._c=this.cNext++,t)},prepDFS:function(){this.vCur++},visited:function(t){return t._v===this.vCur||(t._v=this.vCur,!1)},countDegree:function(t){if(void 0===t._d&&(t._d=0),t._d++,!this.visited(t))for(var n=this.nodeProps(t,!0),e=0;e<n.length;e++)this.countDegree(t[n[e]])},collapseChains:function(t){var n=void 0,e=void 0,i=void 0,r=void 0;if(!this.visited(t)){for(e=this.nodeProps(t),r=0;r<e.length;r++)n=e[r],i=t[n],"object"===("undefined"==typeof i?"undefined":o(i))&&(this.collapseChains(i),void 0===i._g||1!==i._d&&1!==i._g.length||(delete t[n],n+=i._g,t[n]=i[i._g]));1!==e.length||this.isTerminal(t)||(t._g=n)}},isTerminal:function(t){return!!t[""]},uniqueNode:function(t,n,e){for(var o=this.nodeProps(e,!0),i=0;i<o.length;i++){var r=o[i];if(r===t.slice(0,r.length))return r!==n.slice(0,r.length)?e[r]:this.uniqueNode(t.slice(r.length),n.slice(r.length),e[r])}},pack:function(){return r(this)}}},{"./fns":3,"./pack":7}],7:[function(t,n,e){"use strict";var o=t("./histogram"),i=t("../encoding"),r={NODE_SEP:";",STRING_SEP:",",TERMINAL_PREFIX:"!",BASE:36},s=function(t,n){var e="",o="";t.isTerminal(n)&&(e+=r.TERMINAL_PREFIX);for(var s=t.nodeProps(n),u=0;u<s.length;u++){var f=s[u];if("number"!=typeof n[f])if(t.syms[n[f]._n])e+=o+f+t.syms[n[f]._n],o="";else{var c=i.toAlphaCode(n._n-n[f]._n-1+t.symCount);n[f]._g&&c.length>=n[f]._g.length&&1===n[n[f]._g]?(c=n[f]._g,e+=o+f+c,o=r.STRING_SEP):(e+=o+f+c,o="")}else e+=o+f,o=r.STRING_SEP}return e},u=function t(n,e){if(!n.visited(e))for(var o=n.nodeProps(e,!0),s=0;s<o.length;s++){var u=o[s],f=e._n-e[u]._n-1;f<r.BASE&&n.histRel.add(f),n.histAbs.add(e[u]._n,i.toAlphaCode(f).length-1),t(n,e[u])}},f=function(t){t.histAbs=t.histAbs.highest(r.BASE);var n=[];n[-1]=0;for(var e=0,o=0,s=3+i.toAlphaCode(t.nodeCount).length,u=0;u<r.BASE&&void 0!==t.histAbs[u];u++)n[u]=t.histAbs[u][1]-s-t.histRel.countOf(r.BASE-u-1)+n[u-1],n[u]>=e&&(e=n[u],o=u+1);return o},c=function t(n,e){if(void 0===e._n){for(var o=n.nodeProps(e,!0),i=0;i<o.length;i++)t(n,e[o[i]]);e._n=n.pos++,n.nodes.unshift(e)}},d=function(t){t.nodes=[],t.nodeCount=0,t.syms={},t.symCount=0,t.pos=0,t.optimize(),t.histAbs=new o,t.histRel=new o,c(t,t.root),t.nodeCount=t.nodes.length,t.prepDFS(),u(t,t.root),t.symCount=f(t);for(var n=0;n<t.symCount;n++)t.syms[t.histAbs[n][0]]=i.toAlphaCode(n);for(var e=0;e<t.nodeCount;e++)t.nodes[e]=s(t,t.nodes[e]);for(var d=t.symCount-1;d>=0;d--)t.nodes.unshift(i.toAlphaCode(d)+":"+i.toAlphaCode(t.nodeCount-t.histAbs[d][0]-1));return t.nodes.join(r.NODE_SEP)};n.exports=d},{"../encoding":1,"./histogram":4}],8:[function(t,n,e){"use strict";var o=t("./methods"),i=function(t){this.root={},this.lastWord="",this.suffixes={},this.suffixCounts={},this.cNext=1,this.wordCount=0,this.insertWords(t),this.vCur=0};Object.keys(o).forEach(function(t){i.prototype[t]=o[t]}),n.exports=i},{"./methods":6}],9:[function(t,n,e){"use strict";var o=t("./unpack");n.exports=function(t){"string"==typeof t&&(t=JSON.parse(t));var n={};return Object.keys(t).forEach(function(e){var i=o(t[e]);"true"===e&&(e=!0);for(var r=0;r<i.length;r++){var s=i[r];n.hasOwnProperty(s)===!0?Array.isArray(n[s])===!1?n[s]=[n[s],e]:n[s].push(e):n[s]=e}}),n}},{"./unpack":11}],10:[function(t,n,e){"use strict";var o=t("../encoding");n.exports=function(t){for(var n=new RegExp("([0-9A-Z]+):([0-9A-Z]+)"),e=0;e<t.nodes.length;e++){var i=n.exec(t.nodes[e]);if(!i){t.symCount=e;break}t.syms[o.fromAlphaCode(i[1])]=o.fromAlphaCode(i[2])}t.nodes=t.nodes.slice(t.symCount,t.nodes.length)}},{"../encoding":1}],11:[function(t,n,e){"use strict";var o=t("./symbols"),i=t("../encoding"),r=function(t,n,e){var o=i.fromAlphaCode(n);return o<t.symCount?t.syms[o]:e+o+1-t.symCount},s=function(t){var n=[],e=function e(o,i){var s=t.nodes[o];"!"===s[0]&&(n.push(i),s=s.slice(1));for(var u=s.split(/([A-Z0-9,]+)/g),f=0;f<u.length;f+=2){var c=u[f],d=u[f+1];if(c){var h=i+c;if(","!==d&&void 0!==d){var a=r(t,d,o);e(a,h)}else n.push(h)}}};return e(0,""),n},u=function(t){var n={nodes:t.split(";"),syms:[],symCount:0};return t.match(":")&&o(n),s(n)};n.exports=u},{"../encoding":1,"./symbols":10}]},{},[2])(2)});
{
"author": "Spencer Kelly <spencermountain@gmail.com> (http://spencermounta.in)",
"name": "efrt",
"description": "compressed-trie data-structure",
"version": "1.1.0",
"description": "neato compression of key-value data",
"version": "1.1.1",
"main": "./builds/efrt.js",

@@ -13,16 +13,10 @@ "repository": {

"test": "node ./scripts/test.js",
"testBuild": "TESTENV=prod node ./scripts/test.js",
"build": "node ./scripts/build/index.js",
"watch": "node ./scripts/watch.js"
},
"files": [
"builds/"
],
"files": ["builds/"],
"dependencies": {},
"devDependencies": {
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0",
"babel-preset-es2015": "6.9.0",
"babel-preset-stage-2": "^6.11.0",
"babelify": "7.3.0",

@@ -39,2 +33,2 @@ "browserify": "13.0.1",

"license": "MIT"
}
}

@@ -20,47 +20,39 @@ <div align="center">

`efrt` turns a javascript object into a very-compressed prefix [trie](https://en.wikipedia.org/wiki/Trie) format, so that any redundancies in key-value paris are compressed, and nothing is repeated.
it is based on
[lookups](https://github.com/mckoss/lookups) by [Mike Koss](https://github.com/mckoss),
[tamper](https://nytimes.github.io/tamper/) by the [nyTimes](https://github.com/NYTimes/),
and
[bits.js](http://stevehanov.ca/blog/index.php?id=120) by [Steve Hanov](https://twitter.com/smhanov)
* squeeze a key-value object into a very compact form
* reduce filesize/bandwidth a bunch
* ensure the unpacking overhead is negligible
* word-lookups are critical-path
By doing the fancy stuff ahead-of-time, **efrt** lets you ship much bigger key-value data to the client-side, without much hassle.
The whole library is *8kb*, the unpack-half is only *2.5kb*.
if your data looks like this:
```js
var efrt = require('efrt')
var data = {
bedfordshire : 'England',
aberdeenshire : 'Scotland',
berkshire : 'England',
bedfordshire: 'England',
aberdeenshire: 'Scotland',
buckinghamshire: 'England',
argyllshire : 'Scotland',
bambridgeshire : 'England',
angus : 'Scotland',
bristol : 'England',
cheshire : 'England',
ayrshire : 'Scotland',
banffshire : 'Scotland',
berwickshire : 'Scotland'
}
argyllshire: 'Scotland',
bambridgeshire: 'England',
cheshire: 'England',
ayrshire: 'Scotland',
banffshire: 'Scotland'
};
```
you can compress it like this:
```js
var str = efrt.pack(data);
//'{"England":"b0che1;ambridge0edford0uckingham0;shire","Scotland":"a0banff1;berdeen0rgyll0yr0;shire"}'
```
then \_very!\_ quickly flip it back into:
```js
var obj = efrt.unpack(str);
obj['bedfordshire'];//'England'
```
//pack these words as tightly as possible
var compressed = efrt.pack(data);
//{"England":"b0che2;ambridge1e0ristol,uckingham1;dford0rk0;shire","Scotland":"a1b0;anff1erwick1;berdeen0ngus,rgyll0yr0;shire"}
<h1 align="center">Yep,</h1>
//create a lookup-trie
var objAgain = efrt.unpack(compressed);
**efrt** packs category-type data into a *[very compressed prefix trie](https://en.wikipedia.org/wiki/Trie)* format, so that redundancies in the data are shared, and nothing is repeated.
//hit it!
console.log(objAgain['bedfordshire']);//'England'
console.log(objAgain.hasOwnProperty('miles davis'));//false
```
By doing this clever-stuff ahead-of-time, **efrt** lets you ship *much more* data to the client-side, without hassle or overhead.
The whole library is **8kb**, the unpack half is barely **2.5kb**.
it is based on:
* 😍 [tamper](https://nytimes.github.io/tamper/) by the [NYTimes](https://github.com/NYTimes/)
* 💝 [lookups](https://github.com/mckoss/lookups) by [Mike Koss](https://github.com/mckoss),
* 💓 [bits.js](http://stevehanov.ca/blog/index.php?id=120) by [Steve Hanov](https://twitter.com/smhanov)
<h3 align="center">

@@ -70,6 +62,14 @@ <a href="https://rawgit.com/nlp-compromise/efrt/master/demo/index.html">Demo!</a>

the keys you input are pretty normalized. Spaces and unicode are good, but numbers, case-sensitivity, and *some punctuation* (semicolon, comma, exclamation-mark) are not (yet) supported.
<h5 align="left">
Basically,
</h5>
an element may have more than one category. It will accept an array of strings, and pack them into multiple tries like this:
* get a js object into very compact form
* reduce filesize/bandwidth a bunch
* ensure the unpacking time is negligible
* keep word-lookups on critical-path
```js
var efrt = require('efrt')
var foods = {

@@ -85,2 +85,3 @@ strawberry: 'fruit',

//'{"fruit":"bl0straw1tomato;ack0ue0;berry","vegetable":"cucumb0pepp0tomato;er"}'
var obj=efrt.unpack(str)

@@ -90,4 +91,5 @@ console.log(obj.tomato)

```
the keys of the object are normalized. Spaces/unicode are good, but numbers, case-sensitivity, and *some punctuation* (semicolon, comma, exclamation-mark) are not (yet) supported.
*efrt* is used in [compromise](https://github.com/nlp-compromise/compromise), to greatly expand the amount of word-data it can fit onto the client-side.
*efrt* is built-for, and used heavily in [compromise](https://github.com/nlp-compromise/compromise), to expand the amount of data it can ship onto the client-side.
If you find another use for efrt, please [drop us a line](mailto:spencermountain@gmail.com)🎈

@@ -94,0 +96,0 @@

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