Skip to main content

String functions

The following list contains the functions that you can use to manipulating strings.


camel_case()#

Converts string to camel case.

camel_case(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The camel cased string.

Examples#

InputExpressionResult
[]
camel_case('Foo Bar')
"fooBar"
[]
camel_case('--foo-bar--')
"fooBar"
[]
camel_case('__FOO_BAR__')
"fooBar"

capitalize()#

Converts the first character of string to upper case and the remaining to lower case.

capitalize(string)

Arguments#

string (String)
The string to capitalize.

Returns#

(String)
The capitalized string.

Examples#

InputExpressionResult
[]
capitalize('KELP')
"Kelp"

deburr()#

Deburrs string by converting Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removing combining diacritical marks.

deburr(string)

Arguments#

string (String)
The string to deburr.

Returns#

(String)
The deburred string.

Examples#

InputExpressionResult
[]
deburr('déjà vu')
"deja vu"

decode_uri_component()#

Perform URL percent-decoding of input string.

decode_uri_component(string)

Arguments#

string (String)
The string to decode.

Returns#

(String)
The decoded string.

Examples#

InputExpressionResult
[]
decode_uri_component('%3Fx%3Dtest')
"?x=test"

encode_uri_component()#

Perform URL percent-encoding of input string.

encode_uri_component(string)

Arguments#

string (String)
The string to encode.

Returns#

(String)
The encoded string.

Examples#

InputExpressionResult
[]
encode_uri_component('?x=test')
"%3Fx%3Dtest"

ends_with()#

Checks if string ends with the given target string.

ends_with(string, target, [position])

Arguments#

string (String)
The string to inspect.
target (String)
The string to search for.
position (String)
(Optional) The position to search up to. Default value is length(string).

Returns#

(Boolean)
true if string ends with target, else false.

Examples#

InputExpressionResult
[]
ends_with('abc', 'c')
true
[]
ends_with('abc', 'b')
false
[]
ends_with('abc', 'b', 2)
true

escape()#

Converts the characters &, <, >, ", and ' in string to their corresponding HTML entities.

escape(string)

Arguments#

string (String)
The string to escape.

Returns#

(String)
The escaped string.

Examples#

InputExpressionResult
"<p>cut & paste</p>"
escape(@)
"&lt;p&gt;cut &amp; paste&lt;/p&gt;"

escape_reg_exp()#

Escapes the RegExp special characters ^, $, ., *, +, ?, (, ), [, ], {, }, and | in string.

escape_reg_exp(string)

Arguments#

string (String)
The string to escape.

Returns#

(String)
The escaped string.

Examples#

InputExpressionResult
"a(bc){1,5}"
escape_reg_exp(@)
"a\\(bc\\)\\{1,5\\}"

kebab_case()#

Converts string to kebab case.

kebab_case(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The kebab cased string.

Examples#

InputExpressionResult
[]
kebab_case('Foo Bar')
"foo-bar"
[]
kebab_case('fooBar')
"foo-bar"
[]
kebab_case('__FOO_BAR__')
"foo-bar"

lower_case()#

Converts string, as space separated words, to lower case.

lower_case(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The lower cased string.

Examples#

InputExpressionResult
[]
lower_case('--Foo-Bar--')
"foo bar"
[]
lower_case('fooBar')
"foo bar"
[]
lower_case('__FOO_BAR__')
"foo bar"

lower_first()#

Converts the first character of string to lower case.

lower_first(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The converted string.

Examples#

InputExpressionResult
[]
lower_first('Kelp')
"kelp"
[]
lower_first('KELP')
"kELP"

pad()#

Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.

pad(string, [length], [chars])

Arguments#

string (String)
The string to pad.
length (Number)
(Optional) The padding length. Default value is 0.
chars (String)
(Optional) The string used as padding. Default value is " " (space).

Returns#

(String)
The padded string.

Examples#

InputExpressionResult
[]
pad('abc', 8)
"  abc   "
[]
pad('abc', 8, '_-')
"_-abc_-_"
[]
pad('abc', 3)
"abc"

pad_end()#

Pads string on the right side if it's shorter than length. Padding characters are truncated if they exceed length.

pad_end(string, [length], [chars])

Arguments#

string (String)
The string to pad.
length (Number)
(Optional) The padding length. Default value is 0.
chars (String)
(Optional) The string used as padding. Default value is " " (space).

Returns#

(String)
The padded string.

Examples#

InputExpressionResult
[]
pad_end('abc', 6)
"abc   "
[]
pad_end('abc', 6, '_-')
"abc_-_"
[]
pad_end('abc', 3)
"abc"

pad_start()#

Pads string on the left side if it's shorter than length. Padding characters are truncated if they exceed length.

pad_start(string, [length], [chars])

Arguments#

string (String)
The string to pad.
length (Number)
(Optional) The padding length. Default value is 0.
chars (String)
(Optional) The string used as padding. Default value is " " (space).

Returns#

(String)
The padded string.

Examples#

InputExpressionResult
[]
pad_start('abc', 6)
"   abc"
[]
pad_start('abc', 6, '_-')
"_-_abc"
[]
pad_start('abc', 3)
"abc"

parse_int()#

Converts string to an integer of the specified radix. If radix is undefined or 0, a radix of 10 is used unless string value is a hexadecimal, in which case a radix of 16 is used.

parse_int(string, [radix])

Arguments#

string (String)
The string to convert.
radix (Number)
(Optional) The radix to interpret value by. Default value is 10.

Returns#

(Number)
The converted integer.

Examples#

InputExpressionResult
[]
parse_int('08')
8
[]
parse_int('0xB')
11
[]
parse_int('10', 16)
16

repeat()#

Repeats the given string n times.

repeat(string, [n])

Arguments#

string (String)
The string to repeat.
radix (Number)
(Optional) The number of times to repeat the string. Default value is 1.

Returns#

(String)
The repeated string.

Examples#

InputExpressionResult
[]
repeat('*', 3)
"***"
[]
repeat('abc', 2)
"abcabc"
[]
repeat('abc', 0)
""

replace()#

Replaces matches for pattern in string with replacement.

replace(string, pattern, replacement)

Arguments#

string (String)
The string to modify.
pattern (String | RegExp)
The pattern to replace.
replacement (String | Expression)
The match replacement.

Returns#

(String)
The modified string.

Examples#

InputExpressionResult
[]
replace('Hi Fred', 'Fred', 'Barney')
"Hi Barney"
"The cat cat bites the dog dog."
replace(  @,  regexp('([a-zA-Z]+) \1', 'g'),  &[1])
"The cat bites the dog."

snake_case()#

Converts string to snake case.

snake_case(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The snake cased string.

Examples#

InputExpressionResult
[]
snake_case('Foo Bar')
"foo_bar"
[]
snake_case('fooBar')
"foo_bar"
[]
snake_case('--FOO-BAR--')
"foo_bar"

split()#

Splits string by separator.

split(string, separator, [limit])

Arguments#

string (String)
The string to split.
separator (String | RegExp)
The separator pattern to split by.
limit (Number)
The length to truncate results to.

Returns#

(Array)
The string segments.

Examples#

InputExpressionResult
[]
split('a-b-c', '-', 2)
["a", "b"]

start_case()#

Converts string to start case.

start_case(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The start cased string.

Examples#

InputExpressionResult
[]
start_case('--foo-bar--')
"Foo Bar"
[]
start_case('fooBar')
"Foo Bar"
[]
start_case('__FOO_BAR__')
"Foo Bar"

starts_with()#

Checks if string starts with the given target string.

starts_with(string, target, [position])

Arguments#

string (String)
The string to inspect.
target (String)
The string to search for.
position (Number)
(Optional) The position to search from. Default value is 0.

Returns#

(Boolean)
true if string starts with target, else false.

Examples#

InputExpressionResult
[]
starts_with('abc', 'a')
true
[]
starts_with('abc', 'b')
false
[]
starts_with('abc', 'b', 1)
true

template()#

Compiles and executes template that can interpolate data properties or expressions. data properties may be accessed as free variables and placed as text in between double curly braces in the template. KelpQL finds the property matching the text in the data object and replaces the text with the property value or the result of expression evaluation.

template(string, [data])

Arguments#

string (String)
The template string.
data (Object | Expression)
(Optional) The data object. Default value is {}.

Returns#

(String)
The interpolated template string.

Examples#

InputExpressionResult
{    "name": "Chris"}
template('Hello {{name}}!', @)
"Hello Chris!"
{    "value": 85,    "tax": 0.05}
template('Tax: ${{&multiply(value, tax)}}', @)
"Tax: $4.25"

to_lower()#

Converts string, as a whole, to lower case.

to_lower(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The lower cased string.

Examples#

InputExpressionResult
[]
to_lower('--Foo-Bar--')
"--foo-bar--"
[]
to_lower('fooBar')
"foobar"
[]
to_lower('__FOO_BAR__')
"__foo_bar__"

to_upper()#

Converts string, as a whole, to upper case.

to_upper(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The upper cased string.

Examples#

InputExpressionResult
[]
to_upper('--foo-bar--')
"--FOO-BAR--"
[]
to_upper('fooBar')
"FOOBAR"
[]
to_upper('__foo_bar__')
"__FOO_BAR__"

trim()#

Removes leading and trailing whitespace or specified characters from string.

trim(string, [chars])

Arguments#

string (String)
The string to trim.
chars (String)
(Optional) The characters to trim. Defualt value is whitespace characters (RegExp \s).

Returns#

(String)
The trimmed string.

Examples#

InputExpressionResult
[]
trim('  abc  ')
"abc"
[]
trim('-_-abc-_-', '_-')
"abc"

trim_end()#

Removes trailing whitespace or specified characters from string.

trim_end(string, [chars])

Arguments#

string (String)
The string to trim.
chars (String)
(Optional) The characters to trim. Defualt value is whitespace characters (RegExp \s).

Returns#

(String)
The trimmed string.

Examples#

InputExpressionResult
[]
trim_end('  abc  ')
"  abc"
[]
trim_end('-_-abc-_-', '_-')
"-_-abc"

trim_start()#

Removes leading whitespace or specified characters from string.

trim_start(string, [chars])

Arguments#

string (String)
The string to trim.
chars (String)
(Optional) The characters to trim. Defualt value is whitespace characters (RegExp \s).

Returns#

(String)
The trimmed string.

Examples#

InputExpressionResult
[]
trim_start('  abc  ')
"abc  "
[]
trim_start('-_-abc-_-', '_-')
"abc-_-"

truncate()#

Truncates string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to ....

truncate(string, [options])

Arguments#

string (String)
The string to truncate.
options (Object)
(Optional) The options object. Defualt value is {"length": 30, "omission": "..."}.
options.length (Number) - The maximum string length. Defualt value is 30.
options.omission (String) - The string to indicate text is omitted. Defualt value is ....
options.separator (String | RegExp) - The separator pattern to truncate to.

Returns#

(String)
The truncated string.

Examples#

InputExpressionResult
"Who lives in a pineappleunder the sea?"
truncate(@)
"Who lives in a pineapple un..."
{    "length": 25,    "omission": "***"}
truncate(  'Who lives in a pineapple  under the sea?',  @)
"Who lives in a pineapp***"
[]
truncate(  'Who lives  in a pineapple  under the sea?',  {    length: 25,    omission: ' [...]',    separator: regexp('\n +')  })
"Who lives [...]"

unescape()#

The inverse of escape(); this function converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in string to their corresponding characters.

unescape(string)

Arguments#

string (String)
The string to unescape.

Returns#

(String)
The unescaped string.

Examples#

InputExpressionResult
[]
unescape('fred, barney, &amp; pebbles')
"fred, barney, & pebbles"

upper_case()#

Converts string, as space separated words, to upper case.

upper_case(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The upper cased string.

Examples#

InputExpressionResult
[]
upper_case('--foo-bar')
"FOO BAR"
[]
upper_case('fooBar')
"FOO BAR"
[]
upper_case('__foo_bar__')
"FOO BAR"

upper_first()#

Converts the first character of string to upper case.

upper_first(string)

Arguments#

string (String)
The string to convert.

Returns#

(String)
The converted string.

Examples#

InputExpressionResult
[]
upper_first('kelp')
"Kelp"
[]
upper_first('KELP')
"KELP"

words()#

Splits string into an array of its words.

words(string, [pattern])

Arguments#

string (String)
The string to inspect.
pattern (String | RegExp)
(Optional) The pattern to match words.

Returns#

(String)
The words of string.

Examples#

InputExpressionResult
[]
words('fred, barney, & pebbles')
["fred", "barney", "pebbles"]
[]
words(  'fred, barney, & pebbles',  regexp('[^, ]+', 'g'))
["fred", "barney", "&", "pebbles"]

  • camel_case()
  • capitalize()
  • deburr()
  • decode_uri_component()
  • encode_uri_component()
  • ends_with()
  • escape()
  • escape_reg_exp()
  • kebab_case()
  • lower_case()
  • lower_first()
  • pad()
  • pad_end()
  • pad_start()
  • parse_int()
  • repeat()
  • replace()
  • snake_case()
  • split()
  • start_case()
  • starts_with()
  • template()
  • to_lower()
  • to_upper()
  • trim()
  • trim_end()
  • trim_start()
  • truncate()
  • unescape()
  • upper_case()
  • upper_first()
  • words()