/**
 * String formatter with key value pairs.
 * @function lib.string.keyValueFormat
 * @param {string} format - Format string.
 * @param {object} data - Data object.
 * @example
 *
 *      var format = 'Hello, {{from}}, This is {{to}}.',
 *          data = {from: 'Mary', to: 'John'};
 *      var applied = keyValueFormat(format, data);
 *      console.log(applied);
 *          // -> 'Hello, Mary, This is John.'
 * @author Taka Okunishi
 *
 */
var object = require('../object'),
    define = object.define;

module.exports = function (format, data) {
    return format && format.replace(/({{)(.*?)(}})/g, function ($0, $1, $2) {
        return data[$2];
    });
};