#mizchi/js/builtins/collection

    JavaScript collection types (Map, Set, WeakMap, WeakSet).

    #Installation

    Add to your moon.pkg.json:

    { "import": [ "mizchi/js", "mizchi/js/builtins/collection" ] }

    #Overview

    Provides bindings for JavaScript's collection types:
    • Map - Key-value pairs with any type of key
    • Set - Collection of unique values
    • WeakMap - Weak key-value pairs (keys are objects)
    • WeakSet - Weak collection of objects

    #Usage Example

    fn main {
    // Map
    let map = @collection.JsMap::new()
    map.set("key", "value")
    let value = map._get("key")
    let has = map.has("key")

    // Set
    let set = @collection.JsSet::new()
    set.add("item")
    let has_item = set.has("item")

    // WeakMap (for objects only)
    let weak_map = @collection.WeakMap::new()

    // WeakSet (for objects only)
    let weak_set = @collection.WeakSet::new()
    }

    #Reference

    JsMap

    #external
    pub type JsMap[K, V]

    JavaScript Map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

    JsMap::_get

    #alias("_[_]")
    fn[K, V] JsMap::_get(self : JsMap[K, V], key : K) -> V?

    JsMap::clear

    fn[K, V] JsMap::clear(self : JsMap[K, V]) -> Unit

    JS: map.clear()

    JsMap::delete

    fn[K, V] JsMap::delete(self : JsMap[K, V], key : K) -> Bool

    JS: map.delete(key)

    JsMap::entries

    fn[K, V] JsMap::entries(self : JsMap[K, V]) ->
    JsIterator
    [(K, V)]

    JS: map.entries()

    JsMap::forEach

    fn[K, V] JsMap::forEach(self : JsMap[K, V], callback : (V, K) -> Unit) -> Unit

    JS: map.forEach(callback)

    JsMap::from_entries

    fn[K, V] JsMap::from_entries(entries : Array[(K, V)]) -> JsMap[K, V]

    JS: new Map(entries)

    JsMap::get

    fn[K, V] JsMap::get(self : JsMap[K, V], key : K) -> V?

    JS: map._get(key)

    JsMap::has

    fn[K, V] JsMap::has(self : JsMap[K, V], key : K) -> Bool

    JS: map.has(key)

    JsMap::keys

    JS: map.keys()

    JsMap::new

    fn[K, V] JsMap::new() -> JsMap[K, V]

    JS: new Map()

    JsMap::set

    fn[K, V] JsMap::set(self : JsMap[K, V], key : K, value : V) -> JsMap[K, V]

    JS: map.set(key, value)

    JsMap::size

    fn[K, V] JsMap::size(self : JsMap[K, V]) -> Int

    JS: map.size

    JsMap::to_any

    fn[K, V] JsMap::to_any(self : JsMap[K, V]) ->
    Any

    JsMap::values

    JS: map.values()

    JsSet

    #external
    pub type JsSet[T]

    JavaScript Set https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set

    JsSet::add

    fn[T] JsSet::add(self : JsSet[T], value : T) -> JsSet[T]

    JS: set.add(value)

    JsSet::clear

    fn[T] JsSet::clear(self : JsSet[T]) -> Unit

    JS: set.clear()

    JsSet::delete

    fn[T] JsSet::delete(self : JsSet[T], value : T) -> Bool

    JS: set.delete(value)

    JsSet::entries

    JS: set.entries() - Returns [value, value] pairs for compatibility

    JsSet::forEach

    fn[T] JsSet::forEach(self : JsSet[T], callback : (T) -> Unit) -> Unit

    JS: set.forEach(callback)

    JsSet::from_array

    fn[T] JsSet::from_array(values : Array[T]) -> JsSet[T]

    JS: new Set(values)

    JsSet::has

    fn[T] JsSet::has(self : JsSet[T], value : T) -> Bool

    JS: set.has(value)

    JsSet::keys

    JS: set.keys() - Same as values() for Set

    JsSet::new

    fn[T] JsSet::new() -> JsSet[T]

    JS: new Set()

    JsSet::size

    fn[T] JsSet::size(self : JsSet[T]) -> Int

    JS: set.size

    JsSet::to_any

    fn[T] JsSet::to_any(self : JsSet[T]) ->
    Any

    JsSet::values

    JS: set.values()

    Source Files