main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
876 bytes
|
Rev | Line | |
---|
[d565449] | 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.