Skip to content

Build your personal knowledge base with Trilium Notes

refactor(core): inline stripBom, drop strip-bom dependency

Elian Doranf76da6b2acb7
diff --git a/packages/trilium-core/package.json b/packages/trilium-core/package.json
index 150dacd770..d3c5c60983 100644
--- a/packages/trilium-core/package.json
+++ b/packages/trilium-core/package.json
@@ -19,7 +19,6 @@
"sanitize-filename": "1.6.4",
"sanitize-html": "2.17.5",
"sax": "1.6.0",
- "strip-bom": "5.0.0",
"striptags": "3.2.0",
"sucrase": "3.35.1",
"turnish": "1.12.2",
diff --git a/packages/trilium-core/src/services/import/single.spec.ts b/packages/trilium-core/src/services/import/single.spec.ts
index 0ce769ceb5..8e6f939fb6 100644
--- a/packages/trilium-core/src/services/import/single.spec.ts
+++ b/packages/trilium-core/src/services/import/single.spec.ts
@@ -8,7 +8,7 @@ import BNote from "../../becca/entities/bnote.js";
import TaskContext from "../task_context.js";
import sql_init from "../sql_init.js";
import single from "./single.js";
-import stripBom from "strip-bom";
+import { stripBom } from "../utils/binary.js";
import { getContext } from "../context.js";
const scriptDir = dirname(fileURLToPath(import.meta.url));
diff --git a/packages/trilium-core/src/services/utils/binary.spec.ts b/packages/trilium-core/src/services/utils/binary.spec.ts
index 7ef6b82c72..2503751f61 100644
Binary files a/packages/trilium-core/src/services/utils/binary.spec.ts and b/packages/trilium-core/src/services/utils/binary.spec.ts differ
diff --git a/packages/trilium-core/src/services/utils/binary.ts b/packages/trilium-core/src/services/utils/binary.ts
index a2dac2f365..2cbf60b4d8 100644
--- a/packages/trilium-core/src/services/utils/binary.ts
+++ b/packages/trilium-core/src/services/utils/binary.ts
@@ -1,5 +1,4 @@
import chardet from "chardet";
-import stripBom from "strip-bom";
const utf8Decoder = new TextDecoder("utf-8");
const utf8Encoder = new TextEncoder();
@@ -63,6 +62,15 @@ export function wrapStringOrBuffer(stringOrBuffer: string | Uint8Array) {
}
}
+/**
+ * Strips a leading byte order mark (U+FEFF) from a string, if present. A
+ * buffer-to-string conversion translates a UTF-8 BOM (EF BB BF) into the same
+ * U+FEFF code point, so this covers both UTF-8 and UTF-16 BOMs.
+ */
+export function stripBom(text: string): string {
+ return text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
+}
+
/**
* For buffers, they are scanned for a supported encoding and decoded (UTF-8, UTF-16). In some cases, the BOM is also stripped.
*
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 07fc5252fe..aaa961035e 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1656,9 +1656,6 @@ importers:
sax:
specifier: 1.6.0
version: 1.6.0
- strip-bom:
- specifier: 5.0.0
- version: 5.0.0
striptags:
specifier: 3.2.0
version: 3.2.0