Last active
January 7, 2021 15:07
-
-
Save arturotena/22158dcabe386bbfc536 to your computer and use it in GitHub Desktop.
JavaScript trim() polyfill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* trim ployfill: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim */ | |
| if (!String.prototype.trim) { | |
| (function() { | |
| // Make sure we trim BOM and NBSP | |
| var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; | |
| String.prototype.trim = function() { | |
| return this.replace(rtrim, ''); | |
| }; | |
| })(); | |
| } | |
| /* Because old browsers (IE 8-) don't define trim() */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment