Fork me on GitHub

Module core/string

Adds useful methods to the JavaScript String type.

Class String

Instance Methods

Static Methods


String.Sorter (String, Number)

factory to create functions for sorting objects in an array

Parameters

String name of the field each object is compared with
Number order (ascending or descending)

Returns

Function ready for use in Array.prototype.sort

String.compose (String)

create a string from a bunch of substrings

Parameters

String one or more strings as arguments

Returns

String the resulting string

String.join (String, String, String)

append one string onto another and add some "glue" if none of the strings is empty or null.

Parameters

String the first string
String the string to be appended onto the first one
String the "glue" to be inserted between both strings

Returns

String the resulting string

String.prototype.capitalize (Number)

transforms the first n characters of a string to uppercase

Parameters

Number amount of characters to transform

Returns

String the resulting string

String.prototype.contains (String, Int)

function returns true if a string contains the string passed as argument

Parameters

String string to search for
Int Position to start search

Returns

Boolean true if str is contained in this string

String.prototype.count (str)

returns the amount of occurences of one string in another

Parameters

str

String.prototype.debase64 ()

returns the decoded string using the base64 algorithm


String.prototype.digest (algorithm)

function calculates a message digest of a string. If no argument is passed, the MD5 algorithm is used.

Parameters

algorithm the name of the algorithm to use

Returns

String message digest of the string

String.prototype.enbase64 ()

returns the string encoded using the base64 algorithm


String.prototype.endsWith (String)

function returns true if the string ends with the string passed as argument

Parameters

String string pattern to search for

Returns

Boolean true in case it matches the end of the string, false otherwise

String.prototype.entitize ()

translates all characters of a string into HTML entities

Returns

String translated result

String.prototype.escapeHtml ()

Escape the string to make it safe for use within an HTML document.


String.prototype.getCommonPrefix (str)

Get the longest common segment that this and the other string have in common, starting at the beginning of the string

Parameters

str a string

Returns

the longest common segment

String.prototype.group (Int, String, Boolean)

function inserts a string every number of characters

Parameters

Int number of characters after which insertion should take place
String string to be inserted
Boolean definitely insert at each interval position

Returns

String resulting string

String.prototype.isAlpha ()

function returns true if the string contains only characters a-z

Returns

Boolean true in case string is alpha, false otherwise

String.prototype.isAlphanumeric ()

function returns true if the string contains only a-z and 0-9 (case insensitive!)

Returns

Boolean true in case string is alpha, false otherwise

String.prototype.isDateFormat ()

checks if a date format pattern is correct

Returns

Boolean true if the pattern is correct

String.prototype.isEmail ()

returns true if the string looks like an e-mail


String.prototype.isFileName ()

function checks if the string passed contains any characters that are forbidden in image- or filenames

Returns

Boolean

String.prototype.isHexColor ()

function checks a string for a valid color value in hexadecimal format. it may also contain # as first character

Returns

Boolean false, if string length (without #) > 6 or < 6 or contains any character which is not a valid hex value

String.prototype.isNumeric ()

function returns true if the string contains only 0-9

Returns

Boolean true in case string is numeric, false otherwise

String.prototype.isUrl ()

function checks if the string passed contains any characters that are forbidden in URLs and tries to create a java.net.URL from it FIXME: probably deprecated -> ringo.Url

Returns

Boolean

String.prototype.pad (String, Number, Number)

fills a string with another string up to a desired length

Parameters

String the filling string
Number the desired length of the resulting string
Number the direction which the string will be padded in: a negative number means left, 0 means both, a positive number means right

Returns

String the resulting string

String.prototype.repeat (Int)

function repeats a string passed as argument

Parameters

Int amount of repetitions

Returns

String resulting string

String.prototype.startsWith (String)

function returns true if the string starts with the string passed as argument

Parameters

String string pattern to search for

Returns

Boolean true in case it matches the beginning of the string, false otherwise

String.prototype.stripTags ()

Remove all potential HTML/XML tags from this string.


String.prototype.titleize ()

transforms the first n characters of each word in a string to uppercase

Returns

String the resulting string

String.prototype.toAlphanumeric ()

function cleans a string by throwing away all non-alphanumeric characters

Returns

cleaned string

String.prototype.toDate (String, Object)

parse a timestamp into a date object. This is used when users want to set createtime explicitly when creating/editing stories.

Parameters

String date format to be applied
Object Java TimeZone Object (optional)

Returns

Object contains the resulting date

String.prototype.toFileName ()

function cleans the string passed as argument from any characters that are forbidden or shouldn't be used in filenames

Returns

Boolean

String.prototype.toHexColor ()

converts a string into a hexadecimal color representation (e.g. "ffcc33"). also knows how to convert a color string like "rgb (255, 204, 51)".

Returns

String the resulting hex color (w/o "#")

String.prototype.unwrap (Boolean, String)

replace all linebreaks and optionally all w/br tags

Parameters

Boolean flag indicating if html tags should be replaced
String replacement for the linebreaks / html tags

Returns

String the unwrapped string

String.random (len, mode)

creates a random string (numbers and chars)

Parameters

len length of key
mode determines which letters to use. null or 0 = all letters; 1 = skip 0, 1, l and o which can easily be mixed with numbers; 2 = use numbers only

Returns

random string