Adds useful methods to the JavaScript String type.
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/core/String.js')
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/core/String.js')
Methods
checks if a date format pattern is correct
returns
Boolean true if the pattern is correct |
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 |
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 -> helma.Url
returns
Boolean |
see
function checks if the string passed contains any characters
that are forbidden in image- or filenames
returns
Boolean |
function cleans the string passed as argument from any characters
that are forbidden or shouldn't be used in filenames
returns
Boolean |
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 |
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 "#") |
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 |
function cleans a string by throwing away all
non-alphanumeric characters
returns
cleaned string |
function returns true if the string contains
only characters a-z
returns
Boolean true in case string is alpha, false otherwise |
function returns true if the string contains
only 0-9
returns
Boolean true in case string is numeric, false otherwise |
transforms the first n characters of a string to uppercase
parameters
Number | amount of characters to transform |
returns
String the resulting string |
transforms the first n characters of each
word in a string to uppercase
returns
String the resulting string |
translates all characters of a string into HTML entities
returns
String translated result |
breaks up a string into two parts called
head and tail at the given position
don't apply this to HTML, i.e. use stripTags() in advance
parameters
Number | number of charactrers or of segments separated by the delimiter | |
String | pre-/suffix to be pre-/appended to shortened string | |
String | delimiter |
returns
Object containing head and tail properties |
get the head of a string
parameters
limit | ||
clipping | ||
delimiter |
see
get the tail of a string
parameters
limit | ||
clipping | ||
delimiter |
see
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 |
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 |
function repeats a string the specified amount of times
parameters
Int | amount of repetitions |
returns
String resulting 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 |
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 |
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: -1: left 0: both (balance) 1: right (you can use the constants String.LEFT, String.BALANCE and String.RIGHT here as well.) |
returns
String the resulting string |
function returns true if a string contains the string
passed as argument
parameters
String | string to search for | |
Int | Position to start search | |
Boolean |
function compares a string with the one passed as argument
using diff
parameters
String | String to compare against String object value | |
String | Optional regular expression string to use for splitting. If not defined, newlines will be used. |
returns
Object Array containing one JS object for each line with the following properties: .num Line number .value String line if unchanged .deleted Obj Array containing deleted lines .inserted Obj Array containing added lines |
remove leading and trailing whitespace
returns true if the string looks like an e-mail
returns the string encoded using the base64 algorithm
returns the decoded string using the base64 algorithm
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 |
create a string from a bunch of substrings
parameters
String | one or more strings as arguments |
returns
String the resulting string |
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 |
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 |