Object
String utilities for Dojo
Function
the string to replicate
number of times to replicate the string
Efficiently replicate a string `n` times.
String
Function
the string to pad
length to provide padding
character to pad, defaults to '0'
adds padding at the end if true, otherwise pads at start
Pad a string to guarantee that it is at least `size` length by filling with the character `ch` at either the start or end of the string. Pads at the start, by default.
String
// Fill the string to length 10 with "+" characters on the right. Yields "Dojo++++++". dojo.string.pad("Dojo", 10, "+", true);
Function
a string with expressions in the form `${key}` to be replaced or `${key:format}` which specifies a format function. keys are case-sensitive.
hash to search for substitutions
a function to process all parameters before substitution takes place, e.g. mylib.encodeXML
where to look for optional format function; default to the global namespace
Performs parameterized substitutions on a string. Throws an exception if any parameter is unmatched.
Substitutes two expressions in a string from an Array or Object // returns "File 'foo.html' is not found in directory '/temp'." // by providing substitution data in an Array dojo.string.substitute( "File '${0}' is not found in directory '${1}'.", ["foo.html","/temp"] ); // also returns "File 'foo.html' is not found in directory '/temp'." // but provides substitution data in an Object structure. Dotted // notation may be used to traverse the structure. dojo.string.substitute( "File '${name}' is not found in directory '${info.dir}'.", { name: "foo.html", info: { dir: "/temp" } } );
Use a transform function to modify the values: // returns "file 'foo.html' is not found in directory '/temp'." dojo.string.substitute( "${0} is not found in ${1}.", ["foo.html","/temp"], function(str){ // try to figure out the type var prefix = (str.charAt(0) == "/") ? "directory": "file"; return prefix + " '" + str + "'"; } );
Use a formatter // returns "thinger -- howdy" dojo.string.substitute( "${0:postfix}", ["thinger"], null, { postfix: function(value, key){ return value + " -- howdy"; } } );
Function
String to be trimmed
Trims whitespace from both sides of the string
String Returns the trimmed string
This version of trim() was taken from [Steven Levithan's blog](http://blog.stevenlevithan.com/archives/faster-trim-javascript). The short yet performant version of this function is dojo.trim(), which is part of Dojo base. Uses String.prototype.trim instead, if available.
String
Object