Members
(constant) typedArrays
List of all types that are typed arrays
(constant) supports
Test if the given trait has been implemented for the given type
(constant) valueSupports
Test if the given trait has been implemented for the given value
(constant) eq
Determine whether two values are equal using the Equals trait.
This function is a bit more powerful than than the Equals trait itself:
First of all it searches for a Equals implementation for both arguments
and it falls back to === if none is found.
For this reason using eq() is usually preferred over using the Equals trait directly.
(constant) uneq
Equivalent to !eq(a, b)
(constant) get
Given a key, get a value from a container.
(constant) has
Test if a container includes an entry with the given key
(constant) assign
Set a value in a container. Always returns the given value.
(constant) del
Delete an entry with the given key from a container
(constant) setdefault
Set a default value in a container.
(constant) replace
Swap out one value in a container for another
Methods
isdef()
Checks whether a value is defined.
isdef(null) # => false
isdef(undefined) # => false
isdef(0) # => true
isdef(false) # => true
This function considers all values that are not null and not undefined to be defined.
type()
Determine type of an object.#
class Bar {};
type(null) # => null
type(undefined) # => undefined
type(42) # => Number
type(new Number(42)) # => Number
type(new Bar()) # => Bar
Like obj.constructor, but won't fail for null/undefined and just returns the value itself for those. This is a useful feature for code that is supposed to be null/undefined-safe since those need not be special cased.
typename()
Given a type, determine it's name.
class Bar {};
typename(null) # => "null"
typename(undefined) # => "undefined"
typename(42) # => "Number"
typename(new Bar()) # => "Bar"
This is useful as a replacement for val.constructor.name, since this can deal with null and undefined.
isPrimitive()
Test if a value is primitive
isPrimitive(null) # => true
isPrimitive(undefined) # => true
isPrimitive(42) # => true
isPrimitive({}) # => false
isPrimitive(new Number(42)) # => false
typeIsImmutable()
Test whether instance of a given type is immutable
isImmutable()
Test whether a given value is immutable
assertEquals()
Assert that eq(actual, expected)
assertUneq()
Assert that !eq(actual, expected)
size()
Determine the size of a container. Uses the Size trait
empty()
Determine if a container is empty. Uses size(x) === 0
shallowclone()
Shallowly clone an object
deepclone()
Recursively clone an object
pairs()
Get an iterator over any container; always returns pairs [key, value]
(generator) keys()
Get an iterator over the keys of a container. Uses pairs(c).
(generator) values()
Get an iterator over the values of a container. Uses pairs(c).