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