main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d565449] | 1 | import baseRepeat from './_baseRepeat.js';
|
---|
| 2 | import baseToString from './_baseToString.js';
|
---|
| 3 | import castSlice from './_castSlice.js';
|
---|
| 4 | import hasUnicode from './_hasUnicode.js';
|
---|
| 5 | import stringSize from './_stringSize.js';
|
---|
| 6 | import stringToArray from './_stringToArray.js';
|
---|
| 7 |
|
---|
| 8 | /* Built-in method references for those with the same name as other `lodash` methods. */
|
---|
| 9 | var nativeCeil = Math.ceil;
|
---|
| 10 |
|
---|
| 11 | /**
|
---|
| 12 | * Creates the padding for `string` based on `length`. The `chars` string
|
---|
| 13 | * is truncated if the number of characters exceeds `length`.
|
---|
| 14 | *
|
---|
| 15 | * @private
|
---|
| 16 | * @param {number} length The padding length.
|
---|
| 17 | * @param {string} [chars=' '] The string used as padding.
|
---|
| 18 | * @returns {string} Returns the padding for `string`.
|
---|
| 19 | */
|
---|
| 20 | function createPadding(length, chars) {
|
---|
| 21 | chars = chars === undefined ? ' ' : baseToString(chars);
|
---|
| 22 |
|
---|
| 23 | var charsLength = chars.length;
|
---|
| 24 | if (charsLength < 2) {
|
---|
| 25 | return charsLength ? baseRepeat(chars, length) : chars;
|
---|
| 26 | }
|
---|
| 27 | var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
|
---|
| 28 | return hasUnicode(chars)
|
---|
| 29 | ? castSlice(stringToArray(result), 0, length).join('')
|
---|
| 30 | : result.slice(0, length);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | export default createPadding;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.