Skip to main content

String functions

Manipulate strings.


array_buffer_to_string()

Converts utf-8 bytes into string.

array_buffer_to_string(arrayBuffer)

Arguments

arrayBuffer (Array, ArrayBuffer, TypedArray)
The Array, ArrayBuffer or TypedArray to be converted.

Returns

(String)
The utf-8 encoded string.

Examples

InputExpressionResult
[97, 98, 99]
array_buffer_to_string(@)
"abc"

See also


base64_decode()

Decodes a base64-encoded string into utf-8 encoded string.

base64_decode(string)

Arguments

string (String)
The string to be decoded.

Returns

(String)
A utf-8 encoded string representation of decoded data.

Examples

InputExpressionResult
"YWJhYg=="
base64_decode(@)
"abab"

See also


base64_decode_binary()

Decodes a base64-encoded string into typed array (uint8).

base64_decode_binary(string)

Arguments

string (String)
The string to be decoded.

Returns

(TypedArray)
A typed array (uint8) with decoded data.

Examples

TypedArray, can't be represented as JSON Array, to display result, use to_array function.

InputExpressionResult
"YWJhYg=="
base64_decode_binary(@) | to_array(@)
[97, 98, 97, 98]
"asdasda"
base64_decode_binary(@) | to_array(@)
[106, 199, 90, 177, 214]

See also


base64_encode()

Creates a base64-encoded string from the input array or string.

base64_encode(data)

Arguments

data (String | Array | ArrayBuffer | TypedArray)
Data to be encoded.
break (Boolean)
(Optional) Break encoded string into 76 character lines.

Returns

(String)
The base64 encoded string.

Examples

InputExpressionResult
"abab"
base64_encode(@)
"YWJhYg=="
[251, 100]
base64_encode(@)
"+2Q="

See also


base64_urlsafe_encode()

Creates a base64-encoded string from the input array or string, that is safe to use as url parameter.

base64_urlsafe_encode(data)

Arguments

data (String | Array | ArrayBuffer | TypedArray)
Data to be encoded.

Returns

(String)
The base64 encoded string.

Examples

You can use a HTTP connector with Array buffer response data type as a source. Plug response output port and add following transformation.

InputExpressionResult
"abab"
base64_urlsafe_encode(@)
"YWJhYg"
[251, 100]
base64_urlsafe_encode(@)
"-2Q"

See also


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;"

regexp_escape()

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

regexp_escape(string)

Arguments

string (String)
The string to escape.

Returns

(String)
The escaped string.

Examples

InputExpressionResult
"a(bc){1,5}"
regexp_escape(@)
"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"

match()

Returns an object with the result of matching a string against a regular expression.

match(string, pattern)

Arguments

string (String)
The string against which to match the regular expression.
pattern (RegExp)
A regular expression.

Returns

(Object)
Returns a match object. The object consists of the following properties: match - matched substring; namedMatches - named matches if they are defined in the regular expression; matchStartIndex - the start position of the match; matchEndIndex - the end position of the match. No match is indicated by the empty match property and the indexes values of -1.

Examples

InputExpressionResult
"abacaba"
match(@,regexp('ab'))
{
"allMatches": [
{
"match": "ab"
}
],
"namedMatches": {},
"matchStartIndex": 0,
"matchEndIndex": 2
}
"abacaba"
match(@,regexp('cbcbc'))
{
"allMatches": [],
"namedMatches": {},
"matchStartIndex": -1,
"matchEndIndex": -1
}

See also


match_all()

Returns an array with all results matching a string against a regular expression.

match_all(string, pattern)

Arguments

string (String)
The string against which to match the regular expression.
pattern (RegExp)
A regular expression.

Returns

(Array)
Returns an array of matches or an empty array if no matches are found. Each match is an object with the following properties: match - matched substring; namedMatches - named matches if they are defined in the regular expression; matchStartIndex - the start position of the match; matchEndIndex - the end position of the match.

Examples

InputExpressionResult
"abacaba"
match_all(@, regexp('ab'))
[
{
"allMatches": [
{
"match": "ab"
}
],
"namedMatches": {},
"matchStartIndex": 0,
"matchEndIndex": 2
},
{
"allMatches": [
{
"match": "ab"
}
],
"namedMatches": {},
"matchStartIndex": 4,
"matchEndIndex": 6
}
]
"abacaba"
match_all(@,regexp('cb'))
[]

See also


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 the first match 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'), &[1])
"The cat bites the dog dog."

See also


replace_all()

Replaces all matches for pattern in string with replacement.

replace_all(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
"abacaba"
replace_all(@, 'ba', '42')
"a42ca42"
"abacaba"
replace_all(@, regexp('ba'), '42')
"a42ca42"

See also


Executes a search for a match between pattern and a specified string. Here pattern can be both a regular expression or string.

search(string, pattern)

Arguments

string (String)
The string against which to match the regular expression.
pattern (String | RegExp)
A regular expression or string to search.

Returns

(Number)
The index of the first match or -1 if no match was found.

Examples

InputExpressionResult
"abacaba"
search(@,'bac')
1
"abacaba"
search(@, regexp('cab'))
3
"abacaba"
search(@, regexp('123'))
-1

See also


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)
(Optional) The length to truncate the resulting array to. Default value is Infinity.

Returns

(Array)
The string segments.

Examples

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

string_to_array_buffer()

Converts string into typed array (uint8) with utf-8 bytes.

string_to_array_buffer(string)

Arguments

string (String)
The string to be converted.

Returns

(TypedArray)
The typed array (uint8) with utf-8 bytes.

Examples

TypedArray, can't be represented as JSON Array, to display result, use to_array function.

InputExpressionResult
"abc"
string_to_array_buffer(@) | to_array(@)
[97, 98, 99]

See also


substring()

Extracts a substring of string from start char up to, but not including end char'

substring(string, [start], [end])

Arguments

source (String)
The source string.
start (Number)
The start char index.
end (Number)
The end char index.

Returns

(Surbstrng)
A substring of source string.

Examples

InputExpressionResult
"abacaba"
substring('abacaba', 1, 4)
["bac"]

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"

regexp_test()

Tests if there is a match between a regular expression and a specified string.

regexp_test(pattern, string)

Arguments

string (String)
The string against which to match the regular expression.
pattern (RegExp)
A regular expression.

Returns

(Boolean)
Returns true if there is a match between the regular expression and the string. Otherwise, false.

Examples

InputExpressionResult
"foo"
regexp_test(@, regexp('foo'))
true
"barfo"
regexp_test(@, regexp('foo'))
false

See also


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. Default 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. Default 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. Default 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. Default value is {"length": 30, "omission": "..."}.

options.length (Number) - The maximum string length. Default value is 30.
options.omission (String) - The string to indicate text is omitted. Default value is ....
options.separator (String | RegExp) - The separator pattern to truncate to.

Returns

(String)
The truncated string.

Examples

InputExpressionResult
"Who lives in a pineapple under 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 a specified string into an array of its words.

words(string)

Arguments

string (String)
The string to split.

Returns

(Array)
The words of string.

Examples

InputExpressionResult
[]
words('fred, barney, & pebbles')
["fred", "barney", "pebbles"]