提交 d9fe7883 authored 作者: vipcxj's avatar vipcxj

增加trimLeft和trimRight和trimStart和trimEnd的polyfill

上级 37a9064e
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"browserslist": [ "browserslist": [
"ie >= 9" "ie >= 9"
], ],
"sideEffects": ["src/polyfill.js"],
"dependencies": { "dependencies": {
"@babel/polyfill": "^7.0.0", "@babel/polyfill": "^7.0.0",
"@babel/runtime": "^7.0.0", "@babel/runtime": "^7.0.0",
......
/* eslint-disable no-extend-native */
import '@babel/polyfill';
String.prototype.trimStart = String.prototype.trimStart ? String.prototype.trimStart : function trimStart() {
if (String.prototype.trimLeft) {
return this.trimLeft();
} else if (String.prototype.trim) {
const trimmed = this.trim();
const indexOfWord = this.indexOf(trimmed);
return this.slice(indexOfWord, this.length);
}
};
String.prototype.trimLeft = String.prototype.trimLeft ? String.prototype.trimLeft : String.prototype.trimStart;
String.prototype.trimEnd = String.prototype.trimEnd ? String.prototype.trimEnd : function trimEnd() {
if (String.prototype.trimRight) {
return this.trimRight();
} else if (String.prototype.trim) {
const trimmed = this.trim();
const indexOfWord = this.indexOf(trimmed);
return this.slice(0, indexOfWord + trimmed.length);
}
};
String.prototype.trimRight = String.prototype.trimRight ? String.prototype.trimRight : String.prototype.trimEnd;
...@@ -159,7 +159,7 @@ const cssRules = [ ...@@ -159,7 +159,7 @@ const cssRules = [
const config = { const config = {
context: path.resolve(__dirname), context: path.resolve(__dirname),
entry: { entry: {
polyfill: '@babel/polyfill', polyfill: './src/polyfill.js',
main: './src/index.js', main: './src/index.js',
}, },
output: { output: {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论