Class: List

@lumjs/core/arrays.List(obj, optsopt)

A wrapper class to abstract functionality of various kinds of lists.

Supports Array, Set, and Map explicitly. Other classes may be supported. YMMV.

Constructor

new List(obj, optsopt)

Build a new List wrapper.

Parameters:
Name Type Attributes Description
obj object

The list object.

Typically an Array, Set, Map, or something similar. Not all of types will support all features. YMMV.

opts object <optional>

Options for advanced use.

Properties
Name Type Attributes Default Description
allowRaw bool <optional>
false

Attempt to support raw objects?

Treat regular Javascript objects as lists, as they are a kind of map after all. This may lead to unusual results. YMMV.

closures mixed <optional>
true

Create closure methods?

If true or "*" we will create all known closure properties.

If an Array it's the list of closure names we want to create. Possible values can be found in List.KNOWN_CLOSURES.

If it's a string it's treated as a whitespace separated list of closure names and split into an Array.

If false we won't create any closure properties.

Source:

Members

(static) KNOWN_CLOSURES

A list of known closure properties.

Corresponding wrap_${closure} methods will be used to generate the closure properties.

Source:

Methods

containsAll(…items) → {boolean}

See if our list contains all of the specified items.

Parameters:
Name Type Attributes Description
items any <repeatable>
Source:
Returns:
Type
boolean

containsAny(…items) → {boolean}

See if our list object contains any of the specified items.

Parameters:
Name Type Attributes Description
items any <repeatable>
Source:
Returns:
Type
boolean

removeAll(…items) → {number}

Remove items from our list object.

Passed any number of items, it will see if any of those items are found in the array, and if they are, will remove them from the array.

Parameters:
Name Type Attributes Description
items any <repeatable>
Source:
Returns:

Number of items actually removed.

Type
number

wrap_contains(obj) → {function}

Return a closure that returns if an item is in a list object.

Parameters:
Name Type Description
obj object

The list object the closure will be for.

May be an Array, Set, Map, or TypedArray or any object that has either an includes() or has() method.

Source:
Throws:
TypeError
Returns:
Type
function

wrap_remove(obj) → {function}

Return a closure that removes an item from a list.

Parameters:
Name Type Description
obj object

The list object the closure will be for.

May be an Array, Set, Map, or anything with a delete() method.

Source:
Throws:
TypeError
Returns:
Type
function

(static) for(obj, optsopt)

Return a List instance for the passed object.

If the object is already a List it is returned as is.

Parameters:
Name Type Attributes Description
obj object

The list object.

opts object <optional>

Passed to constructor.

Source: