changeset 7e3abe856f67 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset;node=7e3abe856f67
description:
Add polyfill for padStart and padEnd
issue9067
review266821004
diffstat:
src/sao.js | 34 ++++++++++++++++++++++++++++++++++
1 files changed, 34 insertions(+), 0 deletions(-)
diffs (44 lines):
diff -r c5e4173dfd24 -r 7e3abe856f67 src/sao.js
--- a/src/sao.js Wed Feb 12 00:11:55 2020 +0100
+++ b/src/sao.js Mon Feb 17 23:15:55 2020 +0100
@@ -35,6 +35,40 @@
}
});
}
+ if (!String.prototype.padEnd) {
+ String.prototype.padEnd = function padEnd(targetLength, padString) {
+ targetLength = targetLength >> 0;
+ padString = String(
+ typeof padString !== 'undefined' ? padString : ' ');
+ if (this.length > targetLength) {
+ return String(this);
+ } else {
+ targetLength = targetLength - this.length;
+ if (targetLength > padString.length) {
+ padString += padString.repeat(
+ targetLength / padString.length);
+ }
+ return String(this) + padString.slice(0, targetLength);
+ }
+ };
+ }
+ if (!String.prototype.padStart) {
+ String.prototype.padStart = function padStart(targetLength, padString)
{
+ targetLength = targetLength >> 0;
+ padString = String(
+ typeof padString !== 'undefined' ? padString : ' ');
+ if (this.length > targetLength) {
+ return String(this);
+ } else {
+ targetLength = targetLength - this.length;
+ if (targetLength > padString.length) {
+ padString += padString.repeat(
+ targetLength / padString.length);
+ }
+ return padString.slice(0, targetLength) + String(this);
+ }
+ };
+ }
if (!Array.prototype.some) {
Array.prototype.some = function(fun /*, thisp */) {
if (this === null) {