@bikky/smart-collections
v0.0.36
Published
SmartCollections
Downloads
153
Readme
SmartCollections
Features
Non-Collections:
OpenPromise extends Promise
A promise that has a resolve and reject function on it that can be called from outside the promise.
Expanded Collections:
SmartArray extends Array
A SmartArray is an array that has a few extra features:
- remove(value) - remove an element by value.
- removeAll(value) - remove all instances of a value.
- peek() - get the first element without removing it.
- look() - get the last element without removing it.
- getRandom() - get a random element without removing it.
- callEach(...args) - call each element in the array with the given arguments.
ArrayMap extends Map
A map where each value is stored in an array, provides shortcuts for common array operations on the values.
- push(key, value)
- remove(key, value)
- removeAll(key, value)
- includes(key, value)
SetMap extends Map
`A map where each value is stored in a set, provides shortcuts for common operations on the values.
- push(key, value)
- remove(key, value)
- includes(key, value)
Chronological Collections
WaitableMap roughly implements Map
Keeps track of all get requests as pending promises which are resolved when the value is set.
ExpireMap implements Map
A map that expires values after a certain amount of time.
Provides events for when values are added or expires.
Weak Collections
WeakArray implements Array
An array whose values are weak so that they can be garbage collected if they're not held elsewhere. Automatically handles releasing their pointers as they are garbage collected.
Future: Provide events for when values are added or are garbage collected.
WeakRefMap implements Map
A map whose values are weak so that they can be garbage collected if they're not held elsewhere. Automatically handles releasing their pointers as they are garbage collected.
Called WeakRefMap because WeakMap is already taken but refers to when the keys are weak pointers, not the values.
Graph Collections
Map2D extends Map
Stores a two-dimensional map of keys and values. Contains the following bonus methods:
- has2D(key, key, value) - looks up if the value exists in the 2D map
- set2D(key, key, value) - sets the value in the 2D map
- get2D(key, key, value) - retrieves the value in the 2D map
Treemap roughly implements Map
Treemap keeps track of keys and values as Nodes in a tree. Parent nodes can have multiple children, children may only have one parent.
Metadata Collections
VersionMap original
VersionMap keeps track of a tree of inheritance values allowing for values set in later versions to override the values of earlier versions.
Uses a TreeMap as a controller to create the hierarchy.
MetadataCache original
Stores metadata about a set of objects. Metadata is not stored on the object itself.
InheritableMetastore original
Stores metadata about a set of objects. The store is stored on on the object itself and can be inherited from parent objects.
Can be used on classes to have their values inherited onto the class' objects as well as child class' objects.
Also allows child classes to remove values on the parent class.