GT2/Ejectable/node_modules/core-js/modules/$.string-pad.js

17 lines
773 B
JavaScript
Raw Normal View History

2021-08-16 00:14:59 +00:00
// https://github.com/ljharb/proposal-string-pad-left-right
var toLength = require('./$.to-length')
, repeat = require('./$.string-repeat')
, defined = require('./$.defined');
module.exports = function(that, maxLength, fillString, left){
var S = String(defined(that))
, stringLength = S.length
, fillStr = fillString === undefined ? ' ' : String(fillString)
, intMaxLength = toLength(maxLength);
if(intMaxLength <= stringLength)return S;
if(fillStr == '')fillStr = ' ';
var fillLen = intMaxLength - stringLength
, stringFiller = repeat.call(fillStr, Math.ceil(fillLen / fillStr.length));
if(stringFiller.length > fillLen)stringFiller = stringFiller.slice(0, fillLen);
return left ? stringFiller + S : S + stringFiller;
};