UNPKG

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

25 lines (22 loc) 541 B
#!/usr/bin/env node // src/utils/helpers/encodingMO.ts function encodeMO(algorithm, data, score) { return `MO::${algorithm}:${data}::WEISSMAN::${score.toFixed(2)}`; } function decodeMO(encoded) { const regex = /^MO::(.+?):(.*?)::WEISSMAN::([\d.]+)$/; const match = encoded.match(regex); if (!match) { throw new Error("Invalid encoded format"); } const [, algorithm, compressedData, score] = match; return { algorithm, compressedData, weissmanScore: parseFloat(score) }; } export { encodeMO, decodeMO };