Skip to content

refactor(util): reuse BOM-stripped text - #46078

Open
kitlangton wants to merge 1 commit into
v2from
bom-normalization
Open

refactor(util): reuse BOM-stripped text#46078
kitlangton wants to merge 1 commit into
v2from
bom-normalization

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

Why

syncBytes strips leading byte-order marks, then calls join, which strips those same marks again. The second regex pass and temporary result object are redundant.

What Changes

Build the canonical string directly from the already-stripped text and the requested BOM state. Public join behavior remains unchanged for callers that pass unnormalized text.

Scope

One production expression and a small parameterized test. Returned text, encoded bytes, input immutability, and the undefined result for unchanged bytes are preserved.

Verification

cd packages/util
bun run test
bun run test src/bom.test.ts
bun typecheck
cd ../..
bunx prettier --check packages/util/src/bom.ts packages/util/src/bom.test.ts
git diff --check HEAD^ HEAD

All 27 Util tests passed, including six new cases covering absent, single, and repeated leading BOMs, both desired states, and interior Unicode/BOM content. Package typechecking, formatting, and whitespace checks passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant