lib/altshift/core/base.js
function format(string, args) {
    if (
        string.length === 0 ||
        !args ||
        Object.keys(args).length === 0
    ) {
        return string;
    }
    var matchVar = '[0-9a-zA-Z_$\\.]+',
        matchBrackets = '\\[[^\\]]*\\]',
        matchParsing = new RegExp(
            //"^" +
            "((" + matchVar + "|" + matchBrackets + ")*)" + //Match arg path
            "(!([rsa]))?" + //Conversion
            "(:([^\\?\\!]+))?" //spec
            //"$"
        ),
        matchCount = 0;

    return string.replace(FORMAT_EXPRESSION, function (_, match) {
        var parts = match.match(matchParsing),
            argName = parts[1] || matchCount,
            conversion = parts[4] || 's', //Default is string conversion
            formatSpec = parts[6],
            value = formatArgGet(args, argName);

        matchCount += 1;
        if (value === undefined) {
            return FORMAT_EXPRESSION_START + match + FORMAT_EXPRESSION_STOP;//Replace unchanged
        }

        if (formatSpec && formatSpec.length > 0) {
            value = formatValueSpec(value, formatSpec);
        }

        //Conversion s, r or a
        switch (conversion) {
        case 's':
            return '' + value;
        case 'r':
            return inspect(value);
        case 'a':
            throw new Error('Not yet implemented conversion "' + conversion + '"');
        default:
            throw new Error('Invalid conversion "' + conversion + '"');
        }


    });
}
function format(string, args) {
    if (
        string.length === 0 ||
        !args ||
        Object.keys(args).length === 0
    ) {
        return string;
    }
    var matchVar = '[0-9a-zA-Z_$\\.]+',
        matchBrackets = '\\[[^\\]]*\\]',
        matchParsing = new RegExp(
            //"^" +
            "((" + matchVar + "|" + matchBrackets + ")*)" + //Match arg path
            "(!([rsa]))?" + //Conversion
            "(:([^\\?\\!]+))?" //spec
            //"$"
        ),
        matchCount = 0;

    return string.replace(FORMAT_EXPRESSION, function (_, match) {
        var parts = match.match(matchParsing),
            argName = parts[1] || matchCount,
            conversion = parts[4] || 's', //Default is string conversion
            formatSpec = parts[6],
            value = formatArgGet(args, argName);

        matchCount += 1;
        if (value === undefined) {
            return FORMAT_EXPRESSION_START + match + FORMAT_EXPRESSION_STOP;//Replace unchanged
        }

        if (formatSpec && formatSpec.length > 0) {
            value = formatValueSpec(value, formatSpec);
        }

        //Conversion s, r or a
        switch (conversion) {
        case 's':
            return '' + value;
        case 'r':
            return inspect(value);
        case 'a':
            throw new Error('Not yet implemented conversion "' + conversion + '"');
        default:
            throw new Error('Invalid conversion "' + conversion + '"');
        }


    });
}
function format ( string , args ) { if ( string . length === 0 || ! args || Object . keys ( args ) . length === 0 ) { return string ; } var matchVar = '[0-9a-zA-Z_$\\.]+' , matchBrackets = '\\[[^\\]]*\\]' , matchParsing = new RegExp ( //"^" + "((" + matchVar + "|" + matchBrackets + ")*)" + //Match arg path "(!([rsa]))?" + //Conversion "(:([^\\?\\!]+))?" //spec //"$" ) , matchCount = 0 ; return string . replace ( FORMAT_EXPRESSION , function ( _ , match ) { var parts = match . match ( matchParsing ) , argName = parts [ 1 ] || matchCount , conversion = parts [ 4 ] || 's' , //Default is string conversion formatSpec = parts [ 6 ] , value = formatArgGet ( args , argName ) ; matchCount += 1 ; if ( value === undefined ) { return FORMAT_EXPRESSION_START + match + FORMAT_EXPRESSION_STOP ; //Replace unchanged } if ( formatSpec && formatSpec . length > 0 ) { value = formatValueSpec ( value , formatSpec ) ; } //Conversion s, r or a switch ( conversion ) { case 's' : return '' + value ; case 'r' : return inspect ( value ) ; case 'a' : throw new Error ( 'Not yet implemented conversion "' + conversion + '"' ) ; default : throw new Error ( 'Invalid conversion "' + conversion + '"' ) ; } } ) ; }
Format string with `args`

@see http://docs.python.org/release/3.1.3/library/string.html#format-string-syntax

@param {string} string
@param {Array|Object} args
@return {string}
Format string with args