@opencode-ai/util 0.0.0-dev-18736 → 0.0.0-dev-18742
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/dist/bom.js +1 -1
- package/dist/bom.test.d.ts +1 -0
- package/dist/bom.test.js +19 -0
- package/package.json +1 -1
package/dist/bom.js
CHANGED
|
@@ -19,7 +19,7 @@ export function decodeBytes(content) {
|
|
|
19
19
|
export function syncBytes(content, bom) {
|
|
20
20
|
const decoded = decode(content);
|
|
21
21
|
const current = split(decoded);
|
|
22
|
-
const canonical =
|
|
22
|
+
const canonical = bom ? value + current.text : current.text;
|
|
23
23
|
return { text: current.text, bytes: decoded === canonical ? undefined : new TextEncoder().encode(canonical) };
|
|
24
24
|
}
|
|
25
25
|
export const readFile = Effect.fn("Bom.readFile")(function* (fs, filepath) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/bom.test.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { Bom } from "./bom.js";
|
|
3
|
+
test.each([
|
|
4
|
+
{ prefix: "", bom: false, expected: undefined },
|
|
5
|
+
{ prefix: "", bom: true, expected: "\uFEFF" },
|
|
6
|
+
{ prefix: "\uFEFF", bom: false, expected: "" },
|
|
7
|
+
{ prefix: "\uFEFF", bom: true, expected: undefined },
|
|
8
|
+
{ prefix: "\uFEFF\uFEFF", bom: false, expected: "" },
|
|
9
|
+
{ prefix: "\uFEFF\uFEFF", bom: true, expected: "\uFEFF" },
|
|
10
|
+
])("syncBytes(%j)", (row) => {
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
const text = "a\uFEFF\u00e9";
|
|
13
|
+
const input = encoder.encode(row.prefix + text);
|
|
14
|
+
expect(Bom.syncBytes(input, row.bom)).toEqual({
|
|
15
|
+
text,
|
|
16
|
+
bytes: row.expected === undefined ? undefined : encoder.encode(row.expected + text),
|
|
17
|
+
});
|
|
18
|
+
expect(input).toEqual(encoder.encode(row.prefix + text));
|
|
19
|
+
});
|