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
50 lines (48 loc) • 1.84 kB
JavaScript
import {
compressWithMiddleOut,
decompressWithMiddleOut
} from "../../chunk-3GMK3JRF.js";
import "../../chunk-VACPRHPL.js";
import "../../chunk-BTEEIR3V.js";
import "../../chunk-EKQOSSOR.js";
import "../../chunk-MRISBIOS.js";
// tests/algorithms/mo.test.ts
var defaultConfig = {
preserveWhitespace: true,
targetWeissman: 5.2
};
describe("MiddleOut Compression", () => {
it("should remove the middle and \u03BC-mangle the output", () => {
const input = "MiddleOut is totally legit compression.";
const compressed = compressWithMiddleOut(input, defaultConfig);
expect(typeof compressed.compressed).toBe("string");
expect(compressed.compressed).not.toBe(input);
});
it("should decompress by reversing and un-\u03BC-ifying", () => {
const original = "We reverse and pretend it's real decompression.";
const compressed = compressWithMiddleOut(original, defaultConfig);
const restored = decompressWithMiddleOut(compressed.encoded);
expect(compressed.compressed).not.toBe(restored);
});
it("should trim whitespace by default", () => {
const input = " padded like a 2000s website ";
const compressed = compressWithMiddleOut(input, {
...defaultConfig,
preserveWhitespace: false
});
const output = decompressWithMiddleOut(compressed.encoded);
expect(output.startsWith(" ")).toBe(false);
expect(output.endsWith(" ")).toBe(false);
});
it("should preserve whitespace if config allows it", () => {
const input = " maintain my sacred indents ";
const compressed = compressWithMiddleOut(input, {
...defaultConfig,
preserveWhitespace: true
});
const output = decompressWithMiddleOut(compressed.encoded);
expect(output.startsWith(" ")).toBe(true);
expect(output.endsWith(" ")).toBe(true);
});
});