Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
npm install efrt
npm install efrt-unpack
efrt
turns a javascript object into a very-compressed prefix trie format, so that any redundancies in key-value paris are compressed, and nothing is repeated.
it is based on lookups by Mike Koss, tamper by the nyTimes, and bits.js by Steve Hanov
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.
var efrt = require('efrt')
var data = {
bedfordshire : 'England',
aberdeenshire : 'Scotland',
berkshire : 'England',
buckinghamshire: 'England',
argyllshire : 'Scotland',
bambridgeshire : 'England',
angus : 'Scotland',
bristol : 'England',
cheshire : 'England',
ayrshire : 'Scotland',
banffshire : 'Scotland',
berwickshire : 'Scotland'
}
//pack these words as tightly as possible
var compressed = efrt.pack(data);
//{"England":"b0che2;ambridge1e0ristol,uckingham1;dford0rk0;shire","Scotland":"a1b0;anff1erwick1;berdeen0ngus,rgyll0yr0;shire"}
//create a lookup-trie
var objAgain = efrt.unpack(compressed);
//hit it!
console.log(objAgain['bedfordshire']);//'England'
console.log(objAgain.hasOwnProperty('miles davis'));//false
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.
an element may have more than one category. It will accept an array of strings, and pack them into multiple tries like this:
var foods = {
strawberry: 'fruit',
blueberry: 'fruit',
blackberry: 'fruit',
tomato: ['fruit', 'vegetable'],
cucumber: 'vegetable',
pepper: 'vegetable'
};
var str = efrt.pack(foods);
//'{"fruit":"bl0straw1tomato;ack0ue0;berry","vegetable":"cucumb0pepp0tomato;er"}'
var obj=efrt.unpack(str)
console.log(obj.tomato)
//['fruit', 'vegetable']
efrt is used in compromise, to greatly expand the amount of word-data it can fit onto the client-side. If you find another use for efrt, please drop us a line🎈
efrt is tuned to be very quick to unzip. It is O(1) to lookup. Packing-up the data is the slowest part, which is usually cool.
var compressed = efrt.pack(skateboarders);//1k words (on a macbook)
var trie = efrt.unpack(compressed)
// unpacking-step: 5.1ms
trie.hasOwnProperty('tony hawk')
// cached-lookup: 0.02ms
efrt
will pack filesize down as much as possible, depending upon the redundancy of the prefixes/suffixes in the words, and the size of the list.
1.5k -> 0.8k
(46% compressed)58k -> 24k
(58% compressed)265k -> 99k
(62% compressed)1,775k -> 692k
(61% compressed)but there are some things to consider:
Assuming your data has a low category-to-data ratio, you will hit-breakeven with at about 250 keys. If your data is in the thousands, you can very be confident about saving your users some considerable bandwidth.
IE9+
<script src="https://unpkg.com/efrt@latest/builds/efrt.min.js"></script>
<script>
var smaller=efrt.pack(['larry','curly','moe'])
var trie=efrt.unpack(smaller)
console.log(trie['moe'])
</script>
if you're doing the second step in the client, you can load just the unpack-half of the library(~3k):
npm install efrt-unpack
<script src="https://unpkg.com/efrt@latest/builds/efrt-unpack.min.js"></script>
<script>
var trie=unpack(compressedStuff);
trie.hasOwnProperty('miles davis');
</script>
MIT
1.1.0
FAQs
neato compression of key-value data
The npm package efrt receives a total of 44,806 weekly downloads. As such, efrt popularity was classified as popular.
We found that efrt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.