smol-string 0.0.0 → 0.0.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/dist/common.d.ts +13 -8
- package/dist/smol-string-packed.d.ts +2 -2
- package/dist/smol-string-packed.js +30 -42
- package/dist/smol-string-worker-packed.d.ts +2 -2
- package/dist/smol-string-worker-packed.js +36 -37
- package/dist/smol-string-worker.d.ts +2 -2
- package/dist/smol-string-worker.js +36 -37
- package/dist/smol-string.d.ts +2 -2
- package/dist/smol-string.js +28 -42
- package/dist/wasm-helper-57a16a1d.js +56 -0
- package/dist/worker-packed.d.ts +5 -5
- package/dist/worker.d.ts +5 -5
- package/package.json +5 -5
- package/src/common.ts +19 -5
- package/src/module-packed.wasm +0 -0
- package/src/module.wasm +0 -0
- package/src/smol-string-packed.ts +25 -35
- package/src/smol-string-worker-packed.ts +29 -32
- package/src/smol-string-worker.ts +29 -32
- package/src/smol-string.ts +24 -39
- package/src/worker-packed.ts +21 -21
- package/src/worker.ts +21 -21
- package/test/basic.test.ts +29 -29
- package/test/common.ts +15 -15
- package/test/json.bench.ts +51 -51
- package/test/worker.test.browser.ts +29 -0
- package/vite.config.ts +11 -1
- package/dist/wasm-helper-6790be72.js +0 -45
package/src/worker.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { compress, decompress } from "./smol-string.js";
|
|
2
|
-
|
|
3
|
-
export type Message = {
|
|
4
|
-
command: string;
|
|
5
|
-
id: number;
|
|
6
|
-
data: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
onmessage =
|
|
10
|
-
const { command, id, data } = e.data;
|
|
11
|
-
switch (command) {
|
|
12
|
-
case "decompress": {
|
|
13
|
-
postMessage({ id, data: decompress(data) });
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
16
|
-
case "compress": {
|
|
17
|
-
postMessage({ id, data: compress(data) });
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
};
|
|
1
|
+
import { compress, decompress } from "./smol-string.js";
|
|
2
|
+
|
|
3
|
+
export type Message = {
|
|
4
|
+
command: string;
|
|
5
|
+
id: number;
|
|
6
|
+
data: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
self.onmessage = function (e: { data: Message }) {
|
|
10
|
+
const { command, id, data } = e.data;
|
|
11
|
+
switch (command) {
|
|
12
|
+
case "decompress": {
|
|
13
|
+
self.postMessage({ id, data: decompress(data) });
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
case "compress": {
|
|
17
|
+
self.postMessage({ id, data: compress(data) });
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
package/test/basic.test.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { describe, expect, test } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { TestData } from "./common.js";
|
|
4
|
-
|
|
5
|
-
import { compress, decompress } from "../dist/smol-string.js";
|
|
6
|
-
import {
|
|
7
|
-
compressPacked,
|
|
8
|
-
decompressPacked,
|
|
9
|
-
} from "../dist/smol-string-packed.js";
|
|
10
|
-
|
|
11
|
-
describe("compress and decompress", () => {
|
|
12
|
-
for (const { name, input } of TestData) {
|
|
13
|
-
test(name, async () => {
|
|
14
|
-
const compressed = compress(input);
|
|
15
|
-
const decompressed = decompress(compressed);
|
|
16
|
-
expect(decompressed).toBe(input);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("compressPacked and decompressPacked", () => {
|
|
22
|
-
for (const { name, input } of TestData) {
|
|
23
|
-
test(name, async () => {
|
|
24
|
-
const compressed = compressPacked(input);
|
|
25
|
-
const decompressed = decompressPacked(compressed);
|
|
26
|
-
expect(decompressed).toBe(input);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
});
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { TestData } from "./common.js";
|
|
4
|
+
|
|
5
|
+
import { compress, decompress } from "../dist/smol-string.js";
|
|
6
|
+
import {
|
|
7
|
+
compressPacked,
|
|
8
|
+
decompressPacked,
|
|
9
|
+
} from "../dist/smol-string-packed.js";
|
|
10
|
+
|
|
11
|
+
describe("compress and decompress", () => {
|
|
12
|
+
for (const { name, input } of TestData) {
|
|
13
|
+
test(name, async () => {
|
|
14
|
+
const compressed = compress(input);
|
|
15
|
+
const decompressed = decompress(compressed);
|
|
16
|
+
expect(decompressed).toBe(input);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("compressPacked and decompressPacked", () => {
|
|
22
|
+
for (const { name, input } of TestData) {
|
|
23
|
+
test(name, async () => {
|
|
24
|
+
const compressed = compressPacked(input);
|
|
25
|
+
const decompressed = decompressPacked(compressed);
|
|
26
|
+
expect(decompressed).toBe(input);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
package/test/common.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export const json_512kb = import("../../test/data/512KB.json");
|
|
2
|
-
export const json_1mb = import("../../test/data/1MB.json");
|
|
3
|
-
export const rw_medium = import("../../test/data/rw_medium.json");
|
|
4
|
-
export const rw_large = import("../../test/data/rw_large.json");
|
|
5
|
-
|
|
6
|
-
export const TestData = [
|
|
7
|
-
{
|
|
8
|
-
name: "Simple String",
|
|
9
|
-
input: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
|
|
10
|
-
},
|
|
11
|
-
{ name: "json_512kb", input: JSON.stringify(await json_512kb) },
|
|
12
|
-
{ name: "json_1mb", input: JSON.stringify(await json_1mb) },
|
|
13
|
-
{ name: "rw_medium", input: JSON.stringify(await rw_medium) },
|
|
14
|
-
{ name: "rw_large", input: JSON.stringify(await rw_large) },
|
|
15
|
-
];
|
|
1
|
+
export const json_512kb = import("../../test/data/512KB.json");
|
|
2
|
+
export const json_1mb = import("../../test/data/1MB.json");
|
|
3
|
+
export const rw_medium = import("../../test/data/rw_medium.json");
|
|
4
|
+
export const rw_large = import("../../test/data/rw_large.json");
|
|
5
|
+
|
|
6
|
+
export const TestData = [
|
|
7
|
+
{
|
|
8
|
+
name: "Simple String",
|
|
9
|
+
input: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
|
|
10
|
+
},
|
|
11
|
+
{ name: "json_512kb", input: JSON.stringify(await json_512kb) },
|
|
12
|
+
{ name: "json_1mb", input: JSON.stringify(await json_1mb) },
|
|
13
|
+
{ name: "rw_medium", input: JSON.stringify(await rw_medium) },
|
|
14
|
+
{ name: "rw_large", input: JSON.stringify(await rw_large) },
|
|
15
|
+
];
|
package/test/json.bench.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { describe, bench, expect, test, beforeAll } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { TestData } from "./common.js";
|
|
4
|
-
|
|
5
|
-
import { compress, decompress } from "../dist/smol-string.js";
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
compressPacked,
|
|
9
|
-
decompressPacked,
|
|
10
|
-
} from "../dist/smol-string-packed.js";
|
|
11
|
-
|
|
12
|
-
const options = { iterations: 5 };
|
|
13
|
-
|
|
14
|
-
describe.each(TestData)("Compression: $name", ({ name, input }) => {
|
|
15
|
-
bench(
|
|
16
|
-
"compress",
|
|
17
|
-
async () => {
|
|
18
|
-
compress(input);
|
|
19
|
-
},
|
|
20
|
-
options
|
|
21
|
-
);
|
|
22
|
-
bench(
|
|
23
|
-
"compressPacked",
|
|
24
|
-
async () => {
|
|
25
|
-
compressPacked(input);
|
|
26
|
-
},
|
|
27
|
-
options
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe.each(TestData)("Decompression: $name", ({ name, input }) => {
|
|
32
|
-
let compressed = compress(input);
|
|
33
|
-
let compressedPacked = compressPacked(input);
|
|
34
|
-
|
|
35
|
-
bench(
|
|
36
|
-
"decompress",
|
|
37
|
-
async () => {
|
|
38
|
-
const decompressed = decompress(compressed);
|
|
39
|
-
expect(decompressed).toBe(input);
|
|
40
|
-
},
|
|
41
|
-
options
|
|
42
|
-
);
|
|
43
|
-
bench(
|
|
44
|
-
"decompressPacked",
|
|
45
|
-
async () => {
|
|
46
|
-
const decompressed = decompressPacked(compressedPacked);
|
|
47
|
-
expect(decompressed).toBe(input);
|
|
48
|
-
},
|
|
49
|
-
options
|
|
50
|
-
);
|
|
51
|
-
});
|
|
1
|
+
import { describe, bench, expect, test, beforeAll } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { TestData } from "./common.js";
|
|
4
|
+
|
|
5
|
+
import { compress, decompress } from "../dist/smol-string.js";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
compressPacked,
|
|
9
|
+
decompressPacked,
|
|
10
|
+
} from "../dist/smol-string-packed.js";
|
|
11
|
+
|
|
12
|
+
const options = { iterations: 5 };
|
|
13
|
+
|
|
14
|
+
describe.each(TestData)("Compression: $name", ({ name, input }) => {
|
|
15
|
+
bench(
|
|
16
|
+
"compress",
|
|
17
|
+
async () => {
|
|
18
|
+
compress(input);
|
|
19
|
+
},
|
|
20
|
+
options
|
|
21
|
+
);
|
|
22
|
+
bench(
|
|
23
|
+
"compressPacked",
|
|
24
|
+
async () => {
|
|
25
|
+
compressPacked(input);
|
|
26
|
+
},
|
|
27
|
+
options
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe.each(TestData)("Decompression: $name", ({ name, input }) => {
|
|
32
|
+
let compressed = compress(input);
|
|
33
|
+
let compressedPacked = compressPacked(input);
|
|
34
|
+
|
|
35
|
+
bench(
|
|
36
|
+
"decompress",
|
|
37
|
+
async () => {
|
|
38
|
+
const decompressed = decompress(compressed);
|
|
39
|
+
expect(decompressed).toBe(input);
|
|
40
|
+
},
|
|
41
|
+
options
|
|
42
|
+
);
|
|
43
|
+
bench(
|
|
44
|
+
"decompressPacked",
|
|
45
|
+
async () => {
|
|
46
|
+
const decompressed = decompressPacked(compressedPacked);
|
|
47
|
+
expect(decompressed).toBe(input);
|
|
48
|
+
},
|
|
49
|
+
options
|
|
50
|
+
);
|
|
51
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { TestData } from "./common.js";
|
|
4
|
+
|
|
5
|
+
import { compress, decompress } from "../dist/smol-string-worker.js";
|
|
6
|
+
import {
|
|
7
|
+
compressPacked,
|
|
8
|
+
decompressPacked,
|
|
9
|
+
} from "../dist/smol-string-worker-packed.js";
|
|
10
|
+
|
|
11
|
+
describe("compress and decompress", () => {
|
|
12
|
+
for (const { name, input } of TestData) {
|
|
13
|
+
test(name, async () => {
|
|
14
|
+
const compressed = await compress(input);
|
|
15
|
+
const decompressed = await decompress(compressed);
|
|
16
|
+
expect(decompressed).toBe(input);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("compressPacked and decompressPacked", () => {
|
|
22
|
+
for (const { name, input } of TestData) {
|
|
23
|
+
test(name, async () => {
|
|
24
|
+
const compressed = await compressPacked(input);
|
|
25
|
+
const decompressed = await decompressPacked(compressed);
|
|
26
|
+
expect(decompressed).toBe(input);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
package/vite.config.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { defineConfig } from "vite";
|
|
|
3
3
|
import dts from "vite-plugin-dts";
|
|
4
4
|
import pkg from "./package.json" assert { type: "json" };
|
|
5
5
|
|
|
6
|
+
import topLevelAwait from "vite-plugin-top-level-await";
|
|
7
|
+
|
|
6
8
|
export default defineConfig({
|
|
7
9
|
build: {
|
|
8
10
|
lib: {
|
|
@@ -17,7 +19,7 @@ export default defineConfig({
|
|
|
17
19
|
},
|
|
18
20
|
rollupOptions: {
|
|
19
21
|
external: [
|
|
20
|
-
...Object.keys(pkg
|
|
22
|
+
...Object.keys(pkg["dependencies"] ?? {}), // don't bundle dependencies
|
|
21
23
|
/^node:.*/, // don't bundle built-in Node.js modules (use protocol imports!)
|
|
22
24
|
],
|
|
23
25
|
},
|
|
@@ -25,6 +27,14 @@ export default defineConfig({
|
|
|
25
27
|
},
|
|
26
28
|
worker: {
|
|
27
29
|
format: "es",
|
|
30
|
+
plugins: [
|
|
31
|
+
topLevelAwait({
|
|
32
|
+
// The export name of top-level await promise for each chunk module
|
|
33
|
+
promiseExportName: "__tla",
|
|
34
|
+
// The function to generate import names of top-level await promise in each chunk module
|
|
35
|
+
promiseImportName: (i) => `__tla_${i}`,
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
28
38
|
},
|
|
29
39
|
plugins: [
|
|
30
40
|
dts(), // emit TS declaration files
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
function s(e, n) {
|
|
2
|
-
const t = new TextEncoder().encode(e), a = n.allocUint8(t.length + 1), r = new Uint8Array(
|
|
3
|
-
n.memory.buffer,
|
|
4
|
-
a,
|
|
5
|
-
t.length + 1
|
|
6
|
-
);
|
|
7
|
-
return r.set(t), r[t.length] = 0, { ptr: a, length: t.length + 1 };
|
|
8
|
-
}
|
|
9
|
-
function f(e) {
|
|
10
|
-
const n = new Array(e.length);
|
|
11
|
-
for (let t = 0; t < e.length; t++)
|
|
12
|
-
n[t] = String.fromCharCode(e[t]);
|
|
13
|
-
return n.join("");
|
|
14
|
-
}
|
|
15
|
-
const c = async (e = {}, n) => {
|
|
16
|
-
let t;
|
|
17
|
-
if (n.startsWith("data:")) {
|
|
18
|
-
const a = n.replace(/^data:.*?base64,/, "");
|
|
19
|
-
let r;
|
|
20
|
-
if (typeof Buffer == "function" && typeof Buffer.from == "function")
|
|
21
|
-
r = Buffer.from(a, "base64");
|
|
22
|
-
else if (typeof atob == "function") {
|
|
23
|
-
const i = atob(a);
|
|
24
|
-
r = new Uint8Array(i.length);
|
|
25
|
-
for (let o = 0; o < i.length; o++)
|
|
26
|
-
r[o] = i.charCodeAt(o);
|
|
27
|
-
} else
|
|
28
|
-
throw new Error("Failed to decode base64-encoded data URL, Buffer and atob are not supported");
|
|
29
|
-
t = await WebAssembly.instantiate(r, e);
|
|
30
|
-
} else {
|
|
31
|
-
const a = await fetch(n), r = a.headers.get("Content-Type") || "";
|
|
32
|
-
if ("instantiateStreaming" in WebAssembly && r.startsWith("application/wasm"))
|
|
33
|
-
t = await WebAssembly.instantiateStreaming(a, e);
|
|
34
|
-
else {
|
|
35
|
-
const i = await a.arrayBuffer();
|
|
36
|
-
t = await WebAssembly.instantiate(i, e);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return t.instance;
|
|
40
|
-
};
|
|
41
|
-
export {
|
|
42
|
-
f as U,
|
|
43
|
-
s as c,
|
|
44
|
-
c as i
|
|
45
|
-
};
|