Name

sn_hr_core.FormatUtil

Description

Provides functionality similar to MessageFormatter.format in Java but not all functionality of MessageFormatter

Script

/**
* @constructor
*/
function FormatUtil() {

}

/**
* This method provides functionality similar to MessageFormatter.format in Java but not all functionality of
* MessageFormatter.
*
* Sample Usage:
*  gs.info(new sn_hr_core.Formatter().format("An example with place holder1 {0}, place holder 2 {1}", 'value1',
*  'value2'));
*
*  This will output the following
*
*  An example with place holder1 value1, place holder 2 value2
*
* @param {String[]} formatArgs
*
* @return {*} String with place holders replaced with the values
*/
FormatUtil.prototype.format = function(formatArgs) {
  return this._format(arguments);
};

FormatUtil.prototype._format = function(formatArgs) {
  var format = formatArgs[0];
  var args = Array.prototype.slice.call(formatArgs, 1);
  return format.replace(/{(\d+)}/g, function(match, number) {
  	return typeof args[number] != 'undefined' ? args[number] : match;
  });
};

Sys ID

1bfe77c1fb3210101d696a752170691b

Offical Documentation

Official Docs: