Ramda Adjunct 5.0.1

padCharsEnd.js

import { curry, invoker, flip } from 'ramda';

import ponyfill from './internal/ponyfills/String.padEnd.js';
import isFunction from './isFunction.js';

export const padEndPonyfill = curry(ponyfill);

export const padEndInvoker = flip(invoker(2, 'padEnd'));

/**
 * The function pads the current string with a given string
 * (repeated, if needed) so that the resulting string reaches a given length.
 * The padding is applied from the end of the current string.
 *
 * @func padCharsEnd
 * @memberOf RA
 * @since {@link https://char0n.github.io/ramda-adjunct/2.22.0|v2.22.0}
 * @category String
 * @sig String -> Number -> String -> String
 * @param {string} padString The string to pad the current string with
 * @param {number} targetLength The length of the resulting string once
 * the current string has been padded
 * @param {string} value String value to be padded
 * @return {string} A new string of the specified length with the pad string
 * applied at the end of the current string
 * @see {@link RA.padEnd|padEnd}, {@link RA.padCharsStart|padCharsStart}, {@link RA.padStart|padStart}
 * @example
 *
 * RA.padCharsEnd('-', 3, 'a'); // => 'a--'
 * RA.padCharsEnd('foo', 10, 'abc'); // => 'abcfoofoof'
 * RA.padCharsEnd('123456', 6, 'abc'); // => 'abc123'
 */
const padCharsEnd = isFunction(String.prototype.padEnd)
  ? padEndInvoker
  : padEndPonyfill;

export default padCharsEnd;