mirror of
https://github.com/photonstorm/phaser
synced 2025-01-15 14:44:01 +00:00
20 lines
509 B
JavaScript
20 lines
509 B
JavaScript
|
/**
|
||
|
* Replaces %1, %2, %3 etc in the String with the values
|
||
|
* given in the array. Values are cast to strings.
|
||
|
* If no value exists an empty string is inserted.
|
||
|
*
|
||
|
* @param {string} string - The string containing the markers
|
||
|
* @param {array} values - An array containing the values to replace the markers with
|
||
|
*/
|
||
|
var Format = function (string, values)
|
||
|
{
|
||
|
string.replace(/%([0-9]+)/g, function (s, n)
|
||
|
{
|
||
|
return values[Number(n) - 1];
|
||
|
});
|
||
|
|
||
|
return string;
|
||
|
};
|
||
|
|
||
|
module.exports = Format;
|