smol-string 0.0.0 → 0.0.2
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 +1 -1
- package/src/common.ts +18 -4
- 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 +2 -5
- package/src/smol-string-worker.ts +0 -3
- package/src/smol-string.ts +24 -39
- package/test/basic.test.ts +29 -29
- package/test/common.ts +15 -15
- package/test/json.bench.ts +51 -51
- package/dist/wasm-helper-6790be72.js +0 -45
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
|
+
});
|
|
@@ -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
|
-
};
|