-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathvprintf.js
More file actions
25 lines (24 loc) · 912 Bytes
/
vprintf.js
File metadata and controls
25 lines (24 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import nilDefault from 'helper/undefined/nil_default';
import sprintf from 'format/sprintf';
/**
* Produces a string according to `format`. Works exactly like <a href="#sprintf"><code>sprintf()</code></a>,
* with the only difference that accepts the formatting arguments in an array `values`.<br/>
* See <a href="#sprintf-format">here</a> `format` string specifications.
*
* @function vprintf
* @static
* @since 1.0.0
* @memberOf Format
* @param {string} format=''] The format string.
* @param {Array} replacements The array of replacements to produce the string.
* @return {string} Returns the produced string.
* @example
* v.vprintf('%s', ['Welcome'])
* // => 'Welcome'
*
* v.vprintf('%s has %d apples', ['Alexandra', 3]);
* // => 'Alexandra has 3 apples'
*/
export default function vprintf(format, replacements) {
return sprintf(format, ...nilDefault(replacements, []));
}