strings
appendIfMissing(string str, string value)
Appends str with value if str does not already end with value.
Example
{
existing: ds.strings.appendIfMissing("Hello World","World"),
missing: ds.strings.appendIfMissing("Hello ","World")
}
{
"existing": "Hello World",
"missing": "Hello World"
}
camelize(string str)
Converts words in str using camel case, which removes all spaces and converts the first letter of each word except the first word to upper case.
Example
ds.strings.camelize("Hello_world")
"helloWorld"
capitalize(string str)
Converts words in str using capitalized case, which changes the first letter of each word to uppercase, with the rest of the letters in lowercase.
Example
ds.strings.capitalize("hello world")
"Hello World"
charCode(string char)
Converts char to its char code.
Example
ds.strings.charCode("*")
42
charCodeAt(string str, number index)
Returns the char code at index in str.
Example
ds.strings.charCodeAt("*", 0)
42
dasherize(string str)
Converts words in str using kebab-case, which converts all letters in str to lowercase and all spaces into dashes (-).
Example
ds.strings.dasherize("Hello WorldX")
"hello-world-x"
fromCharCode(number charCode)
Converts charCode to its string value.
Example
ds.strings.fromCharCode(42)
"*"
isAlpha(string str)
Returns a boolean which determines if the provided string only contains alpha characters.
Example
ds.strings.isAlpha("abcde")
true
isAlphanumeric(string str)
Returns a boolean which determines if str only contains alpha numeric values.
Example
ds.strings.isAlphanumeric("a1b2cd3e4")
true
isLowerCase(string str)
Returns a boolean which determines if str is all lowercase.
Example
ds.strings.isLowerCase("hello")
true
isNumeric(string str)
Returns a boolean which determines if str contains only numbers.
Example
ds.strings.isNumeric("34634")
true
isUpperCase(string str)
Returns a boolean which determines if str is all uppercase.
Example
ds.strings.isUpperCase("HELLO")
true
isWhitespace(string str)
Returns a boolean which determines if str only contains spaces.
Example
ds.strings.isWhitespace(" ")
true
leftPad(string str, number offset)
Pads the left side of str with spaces if the string is below the offset length.
Example
ds.strings.leftPad("Hello",10)
" Hello"
ordinalize(number num)
Converts num to its ordinal string format, e.g. 1st, 2nd, 3rd, etc.
Example
ds.strings.ordinalize(1)
"1st"
pluralize(string singularWord)
Converts singularWord to its plural counterpart. May not work with all edge cases.
Example
ds.strings.pluralize("car")
"cars"
prependIfMissing(string str, string value)
Prepends str with value if str does not already begin with value.
Example
{
existing: ds.strings.prependIfMissing("Hello World","Hello"),
missing: ds.strings.prependIfMissing(" World","Hello")
}
{
"existing": "Hello World",
"missing": "Hello World"
}
repeat(string str, number times)
Repeats str the given amount of times.
Example
ds.strings.repeat("Hello ", 2)
"Hello Hello "
rightPad(string str, number offset)
Pads the right side str with spaces if the string is below the offset length.
Example
ds.strings.rightPad("Hello",10)
"Hello "
singularize(string pluralWord)
Converts pluralWord to a singular word. May not work with all edge cases.
Example
ds.strings.singularize("cars")
"car"
substringAfter(string str, string separator)
Gets the substring of str after the first occurrence of the separator.
Example
ds.strings.substringAfter("!XHelloXWorldXAfter", "X")
"HelloXWorldXAfter"
substringAfterLast(string str, string separator)
Gets the substring in str after the final occurrence of the separator.
Example
ds.strings.substringAfterLast("!XHelloXWorldXAfter", "X")
"After"
substringBefore(string str, string separator)
Gets the substring in str before the first occurrence of the separator.
Example
ds.strings.substringBefore("!XHelloXWorldXAfter", "X")
"!"
substringBeforeLast(string str, string separator)
Gets the substring in str before the final occurrence of the separator.
Example
ds.strings.substringBeforeLast("!XHelloXWorldXAfter", "X")
"!XHelloXWorld"
underscore(string str)
Converts words in str using snake case, which converts all letters in str to lowercase and all spaces into underscores (_).
Example
ds.strings.underscore("Hello WorldX")
"hello_world_x"
unwrap(string str, string wrapper)
Returns the str without the wrapper text.
Returns the str without the wrapper text.
The wrapper text is the prepended and/or appended values to the str.
Example
{
exists: ds.strings.unwrap("Hello World Hello","Hello"),
partial: ds.strings.unwrap("Hello World ","Hello"),
missing: ds.strings.unwrap(" World ","Hello")
}
{
"exists": " World ",
"partial": " World Hello",
"missing": " World "
}
withMaxSize(string str, number size)
Limits the size of str.
Example
ds.strings.withMaxSize("Hello World", 5)
"Hello"
wrapIfMissing(string str, string wrapper)
Prepends and appends the wrapper to str if str is not already wrapped. Will update only missing side if wrapper already exists at the beginning or end.
Example
{
exists: ds.strings.wrapIfMissing("Hello World Hello","Hello"),
partialBeg: ds.strings.wrapIfMissing("Hello World ","Hello"),
partialEnd: ds.strings.wrapIfMissing(" World Hello","Hello"),
missing: ds.strings.wrapIfMissing(" World ","Hello")
}
{
"exists": "Hello World Hello",
"partialBeg": "Hello World Hello",
"partialEnd": "Hello World Hello",
"missing": "Hello World Hello"
}