[d24f17c] | 1 | import { flip, invoker, curry } from 'ramda';
|
---|
| 2 | import isFunction from './isFunction';
|
---|
| 3 | import ponyfill from './internal/ponyfills/String.padStart';
|
---|
| 4 | export var padStartInvoker = flip(invoker(2, 'padStart'));
|
---|
| 5 | export var padStartPonyfill = curry(ponyfill);
|
---|
| 6 |
|
---|
| 7 | /**
|
---|
| 8 | * The function pads the current string with a given string
|
---|
| 9 | * (repeated, if needed) so that the resulting string reaches a given length.
|
---|
| 10 | * The padding is applied from the start of the current string.
|
---|
| 11 | *
|
---|
| 12 | * @func padCharsStart
|
---|
| 13 | * @memberOf RA
|
---|
| 14 | * @since {@link https://char0n.github.io/ramda-adjunct/2.22.0|v2.22.0}
|
---|
| 15 | * @category String
|
---|
| 16 | * @sig String -> Number -> String -> String
|
---|
| 17 | * @param {string} padString The string to pad the current string with
|
---|
| 18 | * @param {number} targetLength The length of the resulting string once the current string has been padded
|
---|
| 19 | * @param {string} value String value to be padded
|
---|
| 20 | * @return {string} A new string of the specified length with the pad string on the start of current string
|
---|
| 21 | * @see {@link RA.padStart|padStart}, {@link RA.padEnd|padEnd}, {@link RA.padCharsEnd|padCharsEnd}
|
---|
| 22 | * @example
|
---|
| 23 | *
|
---|
| 24 | * RA.padCharsStart('-', 3, 'a'); // => '--a'
|
---|
| 25 | * RA.padCharsStart('foo', 10, 'abc'); // => 'foofoofabc'
|
---|
| 26 | * RA.padCharsStart('123456', 6, 'abc'); // => '123abc'
|
---|
| 27 | */
|
---|
| 28 | var padCharsStart = isFunction(String.prototype.padStart) ? padStartInvoker : padStartPonyfill;
|
---|
| 29 | export default padCharsStart; |
---|