js_builtin

    javascript built-in object bindings (Object, Array, JSON, RegExp, Symbol, Proxy, ...)

    js
    builtins
    object
    array
    json
    Download zip
    Author
    Version
    0.13.1
    License
    MIT
    Last updated
    3 days ago
    Downloads
    5K

    #mizchi/js_builtin

    MoonBit bindings for JavaScript's built-in global objects — the things that exist in every JS runtime, browser or server.

    Depends only on mizchi/js_core. One package per built-in, so you import just the ones you use.

    #Packages

    PackageBindsNote
    arrayJsArrayJS Array as a non-generic Array[Any]; converts to MoonBit Array[T]
    arraybufferArrayBuffer, SharedArrayBuffer, DataView, TypedArrayAll typed arrays (Uint8Array, Float64Array, BigInt64Array, …); zero-cost Bytes ⇔ Uint8Array
    atomicsAtomicsadd/load/store/wait/notify on shared memory
    bigintJsBigIntArbitrary-precision integers
    collectionJsMap, JsSetJS Map and Set
    dateDateTimestamps, components, formatting
    disposableDisposableStack, AsyncDisposableStackExplicit resource management
    errorJsError, TypeError, RangeError, ReferenceError, SyntaxError, URIError, EvalError, AggregateErrorThe error hierarchy
    functionFunctioncall/apply/bind
    globalTimer and the global functionssetTimeout, setInterval, queueMicrotask, globalThis, undefined, parseInt, atob/btoa, encodeURIComponent, structuredClone, dynamic_import, …
    iteratorJsIterator, AsyncIteratorThe iteration protocols
    jsonJSONJSON.parse / JSON.stringify
    mathMathThe Math namespace
    objectObject, PropertyDescriptorkeys/values/entries/assign/freeze/defineProperty, …
    proxyProxyProxy traps
    reflectReflectThe Reflect namespace
    regexpRegExp, RegExpMatchArray, RegExpResultNative JS regex
    stringJsStringJS String methods not in MoonBit's String
    symbolSymbolWell-known and user symbols
    weakWeakMap, WeakSet, WeakRef, FinalizationRegistryWeak references

    Several packages have their own README with fuller API tables: arraybuffer, bigint, collection, date, error, global, math, proxy, reflect, regexp, weak.

    #Usage

    # moon.mod import { "mizchi/js_core@0.13.0", "mizchi/js_builtin@0.13.0", }

    # moon.pkg import { "mizchi/js_core" @core, "mizchi/js_builtin/json", "mizchi/js_builtin/object", }

    Package aliases are the last path segment, so these are @json and @object.

    ///|
    pub fn describe() -> String {
    let o = @core.new_object()
    o["k"] = @core.any(1)
    let any : @core.Any = o |> @core.identity
    let _ = @object.Object::entries(any)
    @json.JSON::stringify(any)
    }

    If you would rather have one import for core plus all the built-ins, depend on mizchi/js — it re-exports both.

    See the User Guide for picking modules and aliases.