middleout.js
Version:
A spoof compression library that pretends to revolutionize data compression using made-up algorithms — inspired by the legendary middle-out compression from Silicon Valley
46 lines (43 loc) • 1.2 kB
JavaScript
import {
decodeMO,
encodeMO
} from "./chunk-EKQOSSOR.js";
import {
getWeissmanScore
} from "./chunk-MRISBIOS.js";
// src/algorithms/tnt.ts
function compressWithTNT(input, config) {
const preserveWhitespace = config?.preserveWhitespace ?? true;
const cleanedInput = preserveWhitespace ? input : input.replace(/\s+/g, "");
let compressed = "";
for (let i = 0; i < cleanedInput.length; i++) {
compressed += (i + 1) % 3 === 0 ? "*" : cleanedInput[i];
}
compressed += "|TNT_SIG|" + Math.floor(Math.random() * 900 + 100);
const targetWeissman = config?.targetWeissman || 10;
const weissmanScore = getWeissmanScore(
"tnt",
input.length,
compressed.length,
targetWeissman
);
return {
original: input,
compressed,
originalSize: input.length,
compressedSize: compressed.length,
algorithm: "tnt",
weissmanScore,
encoded: encodeMO("tnt", compressed, weissmanScore)
};
}
function decompressWithTNT(encoded) {
const { compressedData } = decodeMO(encoded);
const baseData = compressedData.replace(/\|TNT_SIG\|\d+$/, "");
return baseData.replace(/\*/g, "?");
}
export {
compressWithTNT,
decompressWithTNT
};