source: node_modules/ramda-adjunct/src/padCharsStart.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import { flip, invoker, curry } from 'ramda';
2
3import isFunction from './isFunction';
4import ponyfill from './internal/ponyfills/String.padStart';
5
6export const padStartInvoker = flip(invoker(2, 'padStart'));
7
8export const padStartPonyfill = curry(ponyfill);
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 start of the current string.
14 *
15 * @func padCharsStart
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 the current string has been padded
22 * @param {string} value String value to be padded
23 * @return {string} A new string of the specified length with the pad string on the start of current string
24 * @see {@link RA.padStart|padStart}, {@link RA.padEnd|padEnd}, {@link RA.padCharsEnd|padCharsEnd}
25 * @example
26 *
27 * RA.padCharsStart('-', 3, 'a'); // => '--a'
28 * RA.padCharsStart('foo', 10, 'abc'); // => 'foofoofabc'
29 * RA.padCharsStart('123456', 6, 'abc'); // => '123abc'
30 */
31const padCharsStart = isFunction(String.prototype.padStart)
32 ? padStartInvoker
33 : padStartPonyfill;
34
35export default padCharsStart;
Note: See TracBrowser for help on using the repository browser.