Util functions
Various utility functions.
assert()
Returns an Error with message
if the value
is false. If the value
is true, nothing happens.
assert(value, [message])
Arguments
Returns
- (Error)
- Error if the
value
is false, else return nothing.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
attempt()
Attempts to invoke func
, returning either the result or the caught error object. Any additional arguments are provided to func as when it's invoked.
attempt(func, [arg1 [, arg2 [...]]])
Arguments
func
(Expression)- The function to attempt.
args
(Any)- (Optional) The arguments to invoke
func
with.
Returns
- (Any)
- The
func
result or error object.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
cond()
Iterates over predicate-function pairs
and invokes the corresponding function of the first predicate to return truthy. The predicate and function expressions are invoked with one argument (value
).
cond(value, [pair1 [, [pair1 [...]]])
Arguments
value
(Any)- The input value.
pairs
(Array)The predicate-function pairs [
predicate
,function
].predicate
(Expression | Array | Object | String) - an expression, if returns truthy the correspondingfunction
is invoked. Optional for the last pair (default condition).function
(Expression | Array | Object | String) - The expression to be invoked.
Returns
- (Any)
- The result of the corresponding function.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
default_to()
Checks value
to determine whether a default value should be returned in its place. The defaultValue
is returned if value
is NaN, null, or undefined.
default_to(value, [defaultValue])
Arguments
Returns
- (Any)
- The resolved value.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
json_parse()
Parses a well-formed JSON string
, constructing the value or object described by the string
.
Aliases: parse_json().
json_parse(string)
Arguments
string
(String)- The string to parse as JSON. See the JavaScript Object Notation (JSON) for a description of JSON syntax.
Returns
- (Array)
- The value (Object, Array, String, Number, Boolean, or null) corresponding to the given JSON
string
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json_stringify()
Converts a value
to a JSON string.
Aliases: to_json().
json_stringify(value, [space])
Arguments
value
(Any)- The value to convert to a JSON string.
space
(String | Number)A String or Number object that's used to insert white space into the output JSON string for readability purposes.
If this is a Number, it indicates the number of space characters to use as white space for indenting purposes; this number is capped at 10 (if it is greater, the value is just 10). Values less than 1 indicate that no space should be used.
If this is a String, the string (or the first 10 characters of the string, if it's longer than that) is used as white space. If this parameter is not provided (or is null), no white space is used.
Returns
- (Array)
- The JSON string representing the given
value
.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parse_json()
Alias for json_parse().
range()
Creates an array of numbers (positive and/or negative) progressing from start
up to, but not including, end
. If step
is not specified, the default 1
or -1
is used.
range(start, end, [step])
Arguments
start
(Number)- The start of the range.
end
(Number)- The end of the range.
step
(Number)- (Optional) The value to increment or decrement by. The default value is
1
or-1
Returns
- (Array)
- The range of numbers.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
range_right()
This method is like range() except that it populates values in descending order.
range_right(start, end, [step])
Arguments
start
(Number)- The start of the range.
end
(Number)- The end of the range.
step
(Number)- (Optional) The value to increment or decrement by. The default value is
1
or-1
Returns
- (Array)
- The range of numbers.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repl()
Evaluates KelpQL expression represented as a string. This function makes possible to build REPL style interfaces in Kelp. See KelpQL Playground.
repl(expression, [data])
Arguments
expression
(String)- The string representing a KelpQL expression, or sequence of expression.
data
(Any)- (Optional) The arguments to invoke the
expression
with.
Returns
- (Object)
The object with the completion result or error of evaluating the given
expression
.status
(String) - The status of the evaluation:success
orerror
.result
(Any) - The completion value of evaluating the given code.kind
(String) - The kind of error occured during the evaluation.reason
(Error) - The Error object.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
times()
Invokes the iteratee
n
times, returning an array of the results of each invocation. The iteratee
is invoked with one argument: (index
).
times(n, [iteratee])
Arguments
n
(Number)- The number of times to invoke
iteratee
. iteratee
(Expression)- (Optional) The expression invoked per iteration. The default value is
&@
. Theiteratee
is invoked with one argument: (index
). Theindex
starts from0
.
Returns
- (Array)
- The array of results.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
to_json()
Alias for json_stringify().
to_path()
Converts value
to a property path array.
to_path(value)
Arguments
value
(Any)- The value to convert.
Returns
- (Array)
- The new property path array.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
uuid_nil()
The "nil" UUID, a special case, is the UUID 00000000-0000-0000-0000-000000000000
; that is, all bits set to zero.
uuid_nil()
Returns
- (String)
- The "nil" UUID string.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
uuid_v1()
Generates a universally unique identifier (UUID) string, version 1 (timestamp).
uuid_v1()
Returns
- (String)
- The UUID string.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
uuid_v4()
Generates pseudo-random universally unique identifier (UUID) string, version 4 (random).
uuid_v4()
Returns
- (String)
- The random UUID string.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
uuid_v5()
Generates a name-based UUID, as described in RFC 4122 section 4.3, also known as a "version 5" UUID. Unlike the pseudo-random UUIDs generated by uuid_v4(), name-based UUIDs derive from namespace
and an name
, producing the same UUID value every time if the namespace
and name
are unchanged.
uuid_v5(name, namespace)
Arguments
name
(String)- The name of UUID.
namespace
(String)- The namespace of UUID. Use uuid_v5_ns_url() or uuid_v5_ns_dns() to generate custom URL or DNS namespace.
Returns
- (String)
- The UUID string.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
uuid_v5_ns_dns()
Returns DNS UUID namespace string (6ba7b810-9dad-11d1-80b4-00c04fd430c8
).
uuid_v5_ns_dns()
Returns
- (String)
- The DNS UUID namespace.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
uuid_v5_ns_url()
Returns URL UUID namespace string (6ba7b811-9dad-11d1-80b4-00c04fd430c8
).
uuid_v5_ns_url()
Returns
- (String)
- The URL UUID namespace.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
uuid_validate()
Checks is string
is a valid UUID.
uuid_validate(value)
Arguments
value
(String)- The value to inspect.
Returns
- (String)
- true if
value
is a valid UUID, false otherwise.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
uuid_version()
Detect version of a valid UUID string.
uuid_version(value)
Arguments
value
(String)- The value to inspect.
Returns
Examples
Input | Expression | Result |
---|---|---|
|
|
|
|
|
|
|
|
|
dataurl_to_blob()
Given a string in Data URL format, returns a File object that can be submitted with the HTTP Connector using multipart/form-data
encoding type.
dataurl_to_blob(dataURL)
Arguments
dataURL
(String)- String, in Data URL format.
Returns
- (Blob)
- The File object.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
to_blob()
Creates a File from a plain string, blob, file, array buffer or typed array that can be submitted with an HTTP Connector using multipart/form-data
encoding type. If the fileName
is not provided, it returns a Blob object. If the input
is already Blob or File, will use provided fileName and mimeType to override original values.
to_blob(input, [fileName, [mimeType]])
Arguments
input
(String, Blob, Array, ArrayBuffer, TypedArray)- String, Blob, Array, ArrayBuffer or TypedArray, that will be converted to Blob object.
fileName
(String)- (Optional) Filename to attach to Blob object.
mimeType
(String)- (Optional) Mime-Type to associate with a string, i.e. text/plain.
Returns
- (Blob)
- The Blob or File object.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
to_formdata()
Given plain object or array of key-value pairs creates FormData object that can be submitted with an HTTP Connector using multipart/form-data
encoding type.
to_formdata(pairs)
Arguments
Returns
- (FormData)
- The FormData object.
Examples
Input | Expression | Result |
---|---|---|
|
|
|
See Also
from_formdata()
Given FormData object returns array of key-value pairs.
from_formdata(formData)
Arguments
formData
(FormData)- The FormObject data to convert.
Returns
- (Array)
- The key-value pairs.
Examples
Input | Expression | Result |
---|---|---|
|
|
|