uraniumjs
v1.5.1
Published
UraniumJS (~40kB) ☢️ - LZ** Compress (-66%) ^ B92 Encode (-25% of B64)
Downloads
23
Maintainers
Readme
UraniumJS (~41kB) :radioactive: - LZ** Compress (-66.7%) ^ B92 Encode (-25% of B64)
LZP3 & LZJBR + BASE92 :heavy_check_mark: ENRICH or DEPLETE elements such as String, Object, and ArrayBuffer :skull:
ENRICH a text into a simple and compressed BASE92 readable string & DEPLETE it back! Only around 41Kb on modern browser and 31 + 77 kB if you use the version with polyfills to make it compatible with older browser, yet it enables you to save up to 66.67% on any "UTF-8" and "UTF-16le" source text... And to saves once again 25% over Base64 encoding, it fits bracket string and JSON not using " or ' or { or } or $, meanwhile it use spaces when you store it on a web server where Gzip is installed by default for distributing content over http(s), you saves again over more than 15-20% because it is less hard to compress than very ugly texts.
DEMO : Go to codepen.io :sparkles:
1) E-A-S-Y!
LZP3 is a very fast (Truly, trust me.) compression algorithm and LZJBR makes us certainly gain 20% of weight after the great size reduction from the first algorithm used but when it comes to the idea of compressing a very complex string you probably don't want to get a strange and unreadable text which you may even not be able to save it inside a bracket in JavaScript because it could be using insane characters!
2) N-E-A-T!
But look, why would someone with the proper tools beside of him just throw -25% of size inside getting to use an encoding in Base64 if it is to embded it inside JSON or a STRING which can truly handle more likely 92 characters without hurting itself into parsing or readability issues!
3) F-A-S-T!
So, while you might get up to 65% lighter source file for web worker function, you might also be able to embded them directly inside your JS text file and load them quite fast! Or one may be using it to save translation file more kindly inside a .js ...
It doesn't use the following characters excepting space / \ " ' `
How to use it?
import UraniumJS from "uraniumjs/UraniumJS.min.js"; // In node.js only around 18kB
import UraniumCompressJS from "uraniumjs/UraniumCompressJS.min.js"; // In node.js only around 22kB
// UraniumJS.enrichFunctionCalls = UraniumCompressJS.UraniumJSEnrichFunctionCalls;
// UraniumJS.UraniumJSDepleteFunctionCalls = UraniumCompressJS.UraniumJSDepleteFunctionCalls;
/* OR */
var UraniumJS = window.UraniumJS;
// You can add the minified 46kB version within /browser/UraniumCompressJS.min.js (55kB) for browser (> safari 10 & > Chrome 80)
// It will enable you to save up to 2/3 of the text size after compression if you install those modules as below :
UraniumJS.enrichFunctionCalls = window.UraniumJSEnrichFunctionCalls;
UraniumJS.depleteFunctionCalls = window.UraniumJSDepleteFunctionCalls;
/* STEP 0 --OPTIONAL ENCODER-- */
import SuperJSONatural from "superjsonatural"; // only ~7.3Kb // This one isn't fully usual JSON but it do the same as much as twice faster and beyond if you use typed array a lot which it does support!
UraniumJS.JSONX = new SuperJSONatural();
/* STEP 1 --INPUT-- */
var text = `var t = function(base64) {
"use strict";
return new Promise(function(resolve, reject) {
var img = new Image();
var is_png = base64.startsWith("data:image/png;");
img.onload = function() {
var canvas = document.createElement("canvas");
canvas.width = img.naturalWidth || img.width;
canvas.height = img.naturalHeight || img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
resolve(canvas.toDataURL(is_png ? "image/png": "image/jpeg"));
};
img.onerror = function() { reject(); };
img.src = base64;
});
}; return t;`;
/* STEP 2 --PROCESSING-- */
var enriched = UraniumJS.enrichString(text); // 5-65% Lighter in average, in this case it is only 16% lighter because the source text is already small
// RAW -> UraniumJS! H~=2;@N4wbkh75WjH9k35#3EZ<{Xc#cmq{vtYYw^~i].8xhBQNq}I|(1§k[#8F^2b{¡%+oyv>,U:Ouo3>Y s0v0v.-^a)2n,WzfTfN;@r[X1,Ez¡Kp4_ >ik -vcs<H23YuK^~RN4tkVFu-e>U]Fo0g{~N(=XI¡Nj7n7I¡U Aj_^DyWzv{nz:{g8m52Aj-.?VB6Q7p%WM)9-sKaU!d712ui40fdqpMBB|vOmK_hemN&=|¡Oe,A.seS§4fO_]9OvzV[RZ>zk7?9mDxU.;z§#{RI=¡X§4|@ph[![+|p 7~)Cm[METQDo¡v_?Rd1LUuaS6dh~YP§JelWRrlMm q=pro0# X)m%TDf¡¡?pCH%&%W m.OQ¡;7Twh0v|y%aE^J+8Az@2hL8WF-feu§c52>o0Y[6~~Y=dC!rk6#2D<3##¡W7[wIL(Rv=hiB§2ZH?UJf AgWTHA*#sY<jrEc=e^F*G5VWYa¡<l1§K(T+quYGY@SDtE!!Du
var depleted = UraniumJS.stringDeplete("UraniumJS! H~=2;@N4wbkh75WjH9k35#3EZ<{Xc#cmq{vtYYw^~i].8xhBQNq}I|(1§k[#8F^2b{¡%+oyv>,U:Ouo3>Y s0v0v.-^a)2n,WzfTfN;@r[X1,Ez¡Kp4_ >ik -vcs<H23YuK^~RN4tkVFu-e>U]Fo0g{~N(=XI¡Nj7n7I¡U Aj_^DyWzv{nz:{g8m52Aj-.?VB6Q7p%WM)9-sKaU!d712ui40fdqpMBB|vOmK_hemN&=|¡Oe,A.seS§4fO_]9OvzV[RZ>zk7?9mDxU.;z§#{RI=¡X§4|@ph[![+|p 7~)Cm[METQDo¡v_?Rd1LUuaS6dh~YP§JelWRrlMm q=pro0# X)m%TDf¡¡?pCH%&%W m.OQ¡;7Twh0v|y%aE^J+8Az@2hL8WF-feu§c52>o0Y[6~~Y=dC!rk6#2D<3##¡W7[wIL(Rv=hiB§2ZH?UJf AgWTHA*#sY<jrEc=e^F*G5VWYa¡<l1§K(T+quYGY@SDtE!!Du
"); // AS ORIGINAL
// RAW -> var t = function(base64) { "use strict"; return new Promise(function(resolve, reject) { var img = new Image(); var is_png = base64.startsWith("data:image/png;"); img.onload = function() { var canvas = document.createElement("canvas"); canvas.width = img.naturalWidth || img.width; canvas.height = img.naturalHeight || img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, canvas.width, canvas.height); resolve(canvas.toDataURL(is_png ? "image/png": "image/jpeg")); }; img.onerror = function() { reject(); }; img.src = base64; }); }; return t;
ALSO
var pluto = UraniumJS.enrichObject({id: 0, sun: "true", strange: false, lights: "on", deaths: [888, 0.164]})
var original = UraniumJS.depleteObject(pluto); // As original from an object converted into base92
var isMyText = UraniumJS.enrichBuffer(Uint8Array.of(92, 64, 16, 8))
var areMyNumbers = UraniumJS.depleteBuffer(isMyText); // As original from a buffer converted into base92
var areMyBytes = UraniumJS.enrichBuffer(Uint8Array.from(areMyNumbers), true)
var isMyArray = UraniumJS.depleteBuffer(areMyBytes, true); // As original from a buffer
How to use it with JavaScript function?
/* STEP 3 --EVAL-- (optional) */
var AsyncFunctionConstructor = Object.getPrototypeOf(async function(){}).constructor;
var FunctionConstructor = Object.getPrototypeOf(function(){}).constructor;
var sanitizeInlineImageFunction = new FunctionConstructor(depleted);
sanitizeInlineImageFunction("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJ8AAACfCAMAAADQxfvSAAAA2FBMVEUBAABVAABYDQdHAAAwMDAzAQExAAEAAAAxAABVUEwgAAA8PDxbW1sAAAB3BARJSUkuDQ1qAgRDPj4AKipmEQqKCgpHR0eBEg+6ORVVBATVGwnwHBJmEAmFAAAqDw+rDw+JBQDeLQyYMxfYVC3YCwPPBgYqKSnr6+sCAgNPAACvCgd9AADR0dHfRQydnJzytxRYVlLULABabGrNcyjmmBPsz0n161hwg3azs7PuGgvhBADqrVXciTZfIR72yYP++7iRNhZtOFQxUE+zdTRaWgmWWi2iqzaKQkhBzAaqAAAAJnRSTlM5A8eVeWekuddvH2+3hDwVJ9xXw2aySIrMPKLeoku3uuDnrtjepTWKF1MAABG1SURBVHja7Jprk6O4FYY7tbWpycd8zaUqSVWEdIQQQgIjwN7Z3Ury//9R3iOMuRjcbc/U7nwYdZe7Gxvz+FzfI/ot+32W/ODr3r5luN+LL/vO953vO993vu983yifVPPvmuib49PdzESkvzE+rSnOPVjpD/lXyt/MuWTMyqUPCN9mvN8AUKWw0364rPioe5dPjuurelHd83Wd6zT5cPkp/HU+3AUnP2K/r0qonNo5SpGIvPd4NEC9HvQXOsjiZfx9KeCah/o9Ph1JaeMZx/vuCtjRpcMR9SG+K+T7oGr9hjDI6gDt2g+EOBG2UjQYCmG0mu4uDmc8ri9yTfguoHIupd4VI/o+FTJ9dZp2ehP2ndbLT+dgQ7p6FbT711vWvzsLvkOovYZrpvLq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X7il7Nk33dfItYd4+7qfNP4Uib13iThX4hgDqofop9ltOnolpPl5+F4+JyH/XR8nq/6WgUBrfBFa+M7ljKB9+TDsZzTQ6bqzoMXzc4MDAe34AUBjvn24+fDzPFe6+lso7m0un6MP+QIM3qlYzSbHuV7TTw77l8F8Y01bHJHr/rkvbE6BvvPIQ84e2k5hqxvfmX7OIAP5E8/JuB+zz9dPjurPmG+6NMeXwrwje85wDe+5443vje+N77/L99/vkqk13+Cw1oAAAAASUVORK5CYII=")
.then(function(result){ console.log(result); })
Why does it is called UraniumJS?
| Property | Value | | ------------- | ------------- | | Name | Uranium (U) | | Atomic number | 92 (Z) | | Density | 19.1 g/cm3 |
The major application of uranium in the military sector is in high-density penetrators.
92 (Huh)? Compression? --> Enriching something in entropy/chaos aka densifying a raw material is the same concept... it encode certainety into such much surprise but a predictable way!
In information theory, the entropy of a random variable is the average level of "information", "surprise", or "uncertainty" inherent to the variable's possible outcomes. Enriched uranium is a type of uranium in which the percent composition of uranium-235 (written 235U) has been increased through the process of isotope separation. Isotope separation is the process of concentrating specific isotopes of a chemical element by removing other isotopes.
You may be interested in :
https://www.npmjs.com/package/utf-zap