permalink |
---|
/ |
local lm = import "github.com/cakehappens/lonely-mountain/main.libsonnet"
random useful functions
all(fn, arr)
all
passes each element of the collection to the given function.
all
returns true if the function provided never returns false.
PARAMETERS
fn (function(x) bool)
- wherex
is a value from the array; and a boolean is returnedo (object)
- the object to evaluate
RETURNS
bool
any(fn, arr)
any
passes each element of the collection to the given function.
any
returns true if the function provided ever returns true.
PARAMETERS
fn (function(x) bool)
- wherex
is a value from the array; and a boolean is returnedo (object)
- the object to evaluate
RETURNS
bool
array(x)
array
takes a single argument of any type.
If it is an array, it returns it, otherwise it is wrapped in an array.
keyValuePairs(o)
keyValuePairs
takes a single argument of type object
.
It returns an array, where each element is in the form of {k: v}
where k
is the field, and v
is the value of the field.
manifestJsonOneLine(o)
manifestJsonOneLine
takes a value of any type, and returns the json representation in a single non-prettified line.
all(fn, o)
all
returns true when the function provided returns true for all values in an object
PARAMETERS
fn (function(x) bool)
- wherex
is the value of a field in the root object; and a boolean is returnedo (object)
- the object to evaluate
RETURNS
bool
allFields(fn, o)
allFields
returns true when the function provided returns true for all field names in an object
PARAMETERS
fn (function(x) bool)
- wherex
is the field name of a field in the root object; and a boolean is returnedo (object)
- the object to evaluate
RETURNS
bool
keysAfterPrune(o)
keysAfterPrune
is shorthand for std.objectFields(std.prune(o))
lookup(obj, field, default)
lookup
retrieves the value of a single element from an object, given its field. If the given field does not exist, a the given default value is returned instead.
lookupAll(obj, field, default)
lookupAll
is like lookup
but includes hidden fields.
values(o)
values
takes an object and returns an array where each element of the array are the field values in the object.
valuesPruned(o)
valuesPruned
is shorthand for std.prune(lm.object.values(o))
arrayOfType(arr, arr)
arrayOfType
takes an array and a type as a string (see std.type(x)).
Returns true if all elements in the array of the desired type, otherwise false.
Example usage:
assert assertion.arrayOfType(["a", 1], "string") : "not all items are strings";
capitalize(o)
capitalize
takes an string and capitalizes the first letter.