source: trip-planner-front/node_modules/core-js/internals/string-pad.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1// https://github.com/tc39/proposal-string-pad-start-end
2var toLength = require('../internals/to-length');
3var toString = require('../internals/to-string');
4var repeat = require('../internals/string-repeat');
5var requireObjectCoercible = require('../internals/require-object-coercible');
6
7var ceil = Math.ceil;
8
9// `String.prototype.{ padStart, padEnd }` methods implementation
10var createMethod = function (IS_END) {
11 return function ($this, maxLength, fillString) {
12 var S = toString(requireObjectCoercible($this));
13 var stringLength = S.length;
14 var fillStr = fillString === undefined ? ' ' : toString(fillString);
15 var intMaxLength = toLength(maxLength);
16 var fillLen, stringFiller;
17 if (intMaxLength <= stringLength || fillStr == '') return S;
18 fillLen = intMaxLength - stringLength;
19 stringFiller = repeat.call(fillStr, ceil(fillLen / fillStr.length));
20 if (stringFiller.length > fillLen) stringFiller = stringFiller.slice(0, fillLen);
21 return IS_END ? S + stringFiller : stringFiller + S;
22 };
23};
24
25module.exports = {
26 // `String.prototype.padStart` method
27 // https://tc39.es/ecma262/#sec-string.prototype.padstart
28 start: createMethod(false),
29 // `String.prototype.padEnd` method
30 // https://tc39.es/ecma262/#sec-string.prototype.padend
31 end: createMethod(true)
32};
Note: See TracBrowser for help on using the repository browser.