1 | var baseRepeat = require('./_baseRepeat'),
|
2 | baseToString = require('./_baseToString'),
|
3 | castSlice = require('./_castSlice'),
|
4 | hasUnicode = require('./_hasUnicode'),
|
5 | stringSize = require('./_stringSize'),
|
6 | stringToArray = require('./_stringToArray');
|
7 |
|
8 |
|
9 | var nativeCeil = Math.ceil;
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
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 | module.exports = createPadding;
|