mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add polyfills for String.trimLeft/Right for browsers without support.
This commit is contained in:
parent
dce6024e16
commit
85531ff21e
4 changed files with 57 additions and 1 deletions
26
demo/browser-polyfills.js
Normal file
26
demo/browser-polyfills.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
"use strict";
|
||||
|
||||
// Polyfills for browsers that do not support String.trimLeft/Right
|
||||
function trimLeftPolyfill() {
|
||||
return this.replace(/^\s*/, "");
|
||||
}
|
||||
/* istanbul ignore if */
|
||||
if (!String.prototype.trimLeft) {
|
||||
String.prototype.trimLeft = trimLeftPolyfill;
|
||||
}
|
||||
function trimRightPolyfill() {
|
||||
return this.replace(/\s*$/, "");
|
||||
}
|
||||
/* istanbul ignore if */
|
||||
if (!String.prototype.trimRight) {
|
||||
String.prototype.trimRight = trimRightPolyfill;
|
||||
}
|
||||
|
||||
// Export for testing
|
||||
/* istanbul ignore else */
|
||||
if ((typeof module !== "undefined") && module.exports) {
|
||||
module.exports = {
|
||||
"trimLeftPolyfill": trimLeftPolyfill,
|
||||
"trimRightPolyfill": trimRightPolyfill
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue