Skip to content

Instantly share code, notes, and snippets.

@antic183
Last active March 13, 2024 08:45
Show Gist options
  • Save antic183/619f42b559b78028d1fe9e7ae8a1352d to your computer and use it in GitHub Desktop.
Save antic183/619f42b559b78028d1fe9e7ae8a1352d to your computer and use it in GitHub Desktop.
remove utf-8 bom with javascript
// remove utf-8 BOM from ressource "res"
// res.charCodeAt(0) === 0xFEFF | res.charCodeAt(0) === 65279
if (res.charCodeAt(0) === 0xFEFF) {
res = res.substr(1);
}
@antic183
Copy link
Author

antic183 commented Aug 17, 2023

@michabaur yes that's true. Why don't you just use my version. Substring is faster than regular expressions. One line more or less doesn't change anything. In development there are many empty heads who always think they know something better. I don't mean you, but you don't have to look far.

@cescoallegrini Editing office documents with js is a pain in the ass.

@eladkarako I think you dont know what you do.

@michabaur
Copy link

@antic183 I agree. In my deployment tool chain it lends itself to doing this in an ant replaceregexp task. So I go the regex way ;-)

@Grammostola
Copy link

Thanks a whole lot for this. Can be a bit mystifying when you first encounter a problem caused by this char. Excellent solution.

@ianthedev
Copy link

@michabaur yes that's true. Why don't you just use my version. Substring is faster than regular expressions. One line more or less doesn't change anything. In development there are many empty heads who always think they know something better. I don't mean you, but you don't have to look far.

@cescoallegrini Editing office documents with js is a pain in the ass.

@eladkarako I think you dont know what you do.

One has nothing to lose to be friendly or to not be unfriendly.

@antic183
Copy link
Author

antic183 commented Mar 13, 2024

@ianthedev
I could have phrased the comment to "cescoallegrini" and "eladkarako" more nicely, I agree with you. But it is simply a fact that many developers always think they know something better and this is often unjustified. Whoever gives it out must also be able to take it. And there are also many developers who sell themselves beyond their worth. Unfortunately, I have experienced this too often. In my opinion, the worst thing about it is that false information is shared and beginners learn the wrong thing.

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