A quick start guide.

Installation

tns plugin add nativescript-enumerable

Import

import StringFormat = require("nativescript-stringformat");

Examples

Simple example

// "TM + MK"
StringFormat.format("{0} + {1}",
                    "TM",  // {0}
                    "MK");  // {1}

// the alternative:
StringFormat.formatArray("{0} + {1}",
                         ["TM", "MK"]);

Custom order of arguments

// "Marcel Kloubert"
StringFormat.format("{1} {0}",
                    "Kloubert",   // {0}
                    "Marcel");  // {1}

Functions as arguments

// "23091979 + 5091979 = 28183958"
StringFormat.format("{0} + {1} = {2}",
                    23091979,  // {0}
                    5091979,  // {1}
                    function (index, args) {  // {2}
                        return args[0] + args[1];  // 28183958
                    });

The full signature of a function:

function (index, args, match, formatExpr, funcDepth) {
    return <THE-VALUE-TO-USE>;
}
NameDescription
indexThe index value of the argument. For {7} this will be 7.
argsThe values that were passed to the underlying format() or formatArray() function.
matchThe complete (unhandled) expression of the argument.
formatExprThe optional format expression of the argument. For {0:lower} this will be lower.
funcDepthThis value is 0 at the beginning. If you return a function in that function again, this will increase until you stop to return a function.