|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
876 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var $TypeError = require('es-errors/type');
|
|---|
| 4 |
|
|---|
| 5 | var StringPad = require('./StringPad');
|
|---|
| 6 | var ToLength = require('./ToLength');
|
|---|
| 7 | var ToString = require('./ToString');
|
|---|
| 8 |
|
|---|
| 9 | // https://262.ecma-international.org/15.0/#sec-stringpaddingbuiltinsimpl
|
|---|
| 10 |
|
|---|
| 11 | module.exports = function StringPaddingBuiltinsImpl(O, maxLength, fillString, placement) {
|
|---|
| 12 | if (placement !== 'start' && placement !== 'end' && placement !== 'START' && placement !== 'END') {
|
|---|
| 13 | throw new $TypeError('Assertion failed: `placement` must be ~START~ or ~END~');
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | var S = ToString(O); // step 1
|
|---|
| 17 |
|
|---|
| 18 | var intMaxLength = ToLength(maxLength); // step 2
|
|---|
| 19 |
|
|---|
| 20 | var stringLength = S.length; // step 3
|
|---|
| 21 |
|
|---|
| 22 | if (intMaxLength <= stringLength) { return S; } // step 4
|
|---|
| 23 |
|
|---|
| 24 | var filler = typeof fillString === 'undefined' ? ' ' : ToString(fillString); // steps 5-6
|
|---|
| 25 |
|
|---|
| 26 | return StringPad(S, intMaxLength, filler, placement); // step 7
|
|---|
| 27 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.