Skip to content

feat: add strip-bom and strip-bom-string to replacements#692

Merged
43081j merged 2 commits into
e18e:mainfrom
gameroman:strip-bom
Jun 1, 2026
Merged

feat: add strip-bom and strip-bom-string to replacements#692
43081j merged 2 commits into
e18e:mainfrom
gameroman:strip-bom

Conversation

@gameroman
Copy link
Copy Markdown
Contributor

🔗 Linked issue

Closes #612
Closes #667

📚 Description

Adds strip-bom and strip-bom-string to replacements

Comment thread manifests/micro-utilities.json Outdated
"id": "snippet::strip-bom",
"type": "simple",
"description": "You can check the start of a string for the BOM character and use `String.prototype.slice` if it is present.",
"example": "str.startsWith('\\ufeff') ? str.slice(1) : str;"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its probably more efficient to use charCodeAt:

str.charCodeAt(0) === 0xFEFF

since its a numeric comparison, single character

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not codePointAt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

charCodeAt, since we are looking at the first character specifically, and 0xFEFF is in BMP

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

charCodeAt is faster than codePointAt in this case since we're retrieving the first character rather than having to compute the first code point (which could be a surrogate pair)

Comment thread manifests/micro-utilities.json Outdated
@43081j 43081j merged commit 1281f96 into e18e:main Jun 1, 2026
5 checks passed
@gameroman gameroman deleted the strip-bom branch June 1, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Replacement]: strip-bom [Replacement]: strip-bom-string

3 participants