Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Moonbit Js bindings

NotificationsYou must be signed in to change notification settings

mizchi/js.mbt

Repository files navigation

Comprehensive JavaScript/ FFI bindings for MoonBit, supporting multiple runtimes and platforms.

Version Requirements

v0.10.0 requires MoonBit nightly2025-12-09 or later for ESM#module directive support:

moon 0.1.20251209 (8d6e473 2025-12-09)moonc v0.6.34+7262739a4-nightly (2025-12-09)moonrun 0.1.20251209 (8d6e473 2025-12-09)

If you need stable toolchain compatibility, usev0.8.x.

Breaking Change in v0.10.0

NPM package bindings have moved: Allmizchi/js/npm/* packages are now in a separate repository:mizchi/npm_typed

Installation

$ moon add mizchi/js

Add to yourmoon.pkg.json:

{"import": ["mizchi/js/core","mizchi/js"]}

⚠️ Future Plans: Platform-specific APIs (Node.js, Browser, Deno) will be split into separate packages in the future. The coremizchi/js package will focus on JavaScript built-ins and Web Standard APIs.

Note: Cloudflare Workers bindings have been moved to a separate package:@mizchi/cloudflare-mbt

Quick Links

📚 API Documentation by Platform

PlatformDocumentationExamplesStatus
Core JavaScriptsrc/README.mdjs_examples.mbt.md🧪 Tested
Browsersrc/browser/README.mdbrowser_examples.mbt.md🧪 Tested
Node.jssrc/node/README.mdnode_examples.mbt.md🧪 Tested
Denosrc/deno/README.md-🧪 Tested
Reactmizchi/npm_typedSee npm_typed repo📦 Moved

📖 Learning Resources

Supported Modules

Status Legend

  • 🧪Tested: Comprehensive test coverage, production ready
  • 🚧Partially: Core functionality implemented, tests incomplete
  • 🤖AI Generated: FFI bindings created, needs testing
  • 📅Planned: Scheduled for future implementation
  • Not Supported: Technical limitations

Core JavaScript APIs

mizchi/js/core - Core FFI Package

Themizchi/js/core package provides the foundation for JavaScript interoperability in MoonBit:

Type System

  • Any - Opaque type for JavaScript values
  • Nullable[T] - Representsnull | T
  • Nullish[T] - Representsnull | undefined | T
  • Union2[A,B] ~Union5[A,B,C,D,E] - TypeScript union types (A | B)
  • Promise[T] - JavaScript Promise wrapper

FFI Operations (zero-cost conversions)

  • identity[A,B](value: A) -> B - Type casting using%identity
  • any[T](value: T) -> Any - Convert to Any
  • Any::cast[T](self) -> T - Cast from Any
  • obj["key"],obj["key"] = value - Property access (or_get(key),_set(key, value))
  • Any::_call(method, args),Any::_invoke(args) - Method calls

Object & JSON

  • new_object(),new_array() - Create JS objects/arrays
  • object_keys(),object_values(),object_assign(),object_has_own()
  • json_stringify(),json_parse(),json_stringify_pretty()

Async/Promise Support

  • run_async(f) - Execute async functions (MoonBit builtin%async.run)
  • suspend(f) - Await promises (MoonBit builtin%async.suspend)
  • promisify0 ~promisify3 - Convert callbacks to promises
  • Promise utilities:resolve,reject,all,race,any,withResolvers

Error Handling

  • JsError - Generic JS error type
  • ThrowError - Wrapper for thrown errors
  • try_sync(op) - Safe wrapper converting JS exceptions to MoonBit errors
  • throwable(f) - Convert JS exceptions to ThrowError
  • export_sync(op) - Convert MoonBit errors to JS exceptions
  • throw_error(msg) - Throw JS Error

Type Checking

  • is_object(),is_array(),is_null(),is_undefined(),is_nullish()

Nullish Utilities

  • Nullish::to_option(),Nullable::to_option() - Convert to MoonBit Option
  • nullable(opt) - Convert Option to JS nullable
  • as_any(opt) - Convert Option[Any] to Any

API Summary

CategoryPackageStatusNote
Core FFI & Objects
Core FFImizchi/js/core🧪 Testedget,set,call, etc.
Objectmizchi/js/builtins/object🧪 TestedObject manipulation
Functionmizchi/js/builtins/function🧪 TestedFunction operations
Promisemizchi/js/core🧪 TestedAsync/Promise API
Errormizchi/js/builtins/error🧪 TestedError handling
JSONmizchi/js/builtins/json🧪 TestedJSON parse/stringify
Iteratormizchi/js/builtins/iterator🧪 TestedJS Iterator protocol
AsyncIteratormizchi/js/builtins/iterator🧪 TestedAsync iteration
WeakMap/Set/Refmizchi/js/builtins/weak🧪 TestedWeak references
Async Helpers
run_asyncmizchi/js/core🧪 TestedAsync execution
suspendmizchi/js/core🧪 TestedPromise suspension
sleepmizchi/js/core🧪 TestedDelay execution
promisifymizchi/js/core🧪 TestedCallback → Promise

JavaScript Built-ins

All JavaScript built-in objects are exported frommizchi/js:

CategoryPackageStatusNote
Global Functions
Globalmizchi/js/builtins/global🧪 TestedglobalThis, parseInt, parseFloat, setTimeout etc.
Core Types
Objectmizchi/js/builtins/object🧪 TestedObject manipulation
Functionmizchi/js/builtins/function🧪 TestedFunction operations
Symbolmizchi/js/builtins/symbol🧪 TestedSymbol primitive
Errormizchi/js/builtins/error🧪 TestedError types (TypeError, RangeError, etc.)
Primitives & Data
Stringmizchi/js/builtins/string🧪 TestedJsString (String methods)
Arraymizchi/js/builtins/array🧪 TestedJsArray (Array methods)
BigIntmizchi/js/builtins/bigint🧪 TestedJsBigInt (arbitrary precision)
JSONmizchi/js/builtins/json🧪 TestedJSON parse/stringify
Date & Math
Datemizchi/js/builtins/date🧪 TestedDate/time operations
Mathmizchi/js/builtins/math🧪 TestedMath operations
Collections
Map/Setmizchi/js/builtins/collection🧪 TestedJsMap, JsSet
WeakMap/Set/Refmizchi/js/builtins/weak🧪 TestedWeakMap, WeakSet, WeakRef, FinalizationRegistry
Binary Data
ArrayBuffermizchi/js/builtins/arraybuffer🧪 TestedBinary buffers
DataViewmizchi/js/builtins/arraybuffer🧪 TestedBuffer views
memory
Pattern & Reflection
RegExpmizchi/js/builtins/regexp🧪 TestedRegular expressions
Reflectmizchi/js/builtins/reflect🧪 TestedReflection API
Proxymizchi/js/builtins/proxy🤖 AI GeneratedProxy API
Iteration & Async
Iteratormizchi/js/builtins/iterator🧪 TestedJsIterator protocol
AsyncIteratormizchi/js/builtins/iterator🧪 TestedAsync iteration
Concurrency
Atomicsmizchi/js/builtins/atomics🧪 TestedAtomic operations
Resource Management
DisposableStackmizchi/js/builtins/disposable🧪 TestedDisposable resources

Web Standard APIs

Platform-independent Web Standard APIs (browsers, Node.js, Deno, edge runtimes):

Seemizchi/js/web for detailed Web APIs documentation

CategoryPackageStatusNote
Consolemizchi/js/web/console🧪 Testedconsole.log, console.error, etc.
fetchmizchi/js/web/http🧪 TestedHTTP requests
Requestmizchi/js/web/http🧪 TestedRequest objects
Responsemizchi/js/web/http🧪 TestedResponse objects
Headersmizchi/js/web/http🧪 TestedHTTP headers
FormDatamizchi/js/web/http🧪 TestedForm data
URLmizchi/js/web/url🧪 TestedURL parsing
URLSearchParamsmizchi/js/web/url🧪 TestedQuery strings
URLPatternmizchi/js/web/url🧪 TestedURL pattern matching
Blobmizchi/js/web/blob🧪 TestedBinary data
ReadableStreammizchi/js/web/streams🧪 TestedStream reading
WritableStreammizchi/js/web/streams🧪 TestedStream writing
TransformStreammizchi/js/web/streams🧪 TestedStream transformation
CompressionStreammizchi/js/web/streams🧪 TestedGZIP/Deflate compression
DecompressionStreammizchi/js/web/streams🧪 TestedGZIP/Deflate decompression
TextEncodermizchi/js/web/encoding🧪 TestedString to Uint8Array
TextDecodermizchi/js/web/encoding🧪 TestedUint8Array to String
Eventmizchi/js/web/event🧪 TestedEvent objects
CustomEventmizchi/js/web/event🧪 TestedCustom events
MessageEventmizchi/js/web/event🧪 TestedMessage events
Cryptomizchi/js/web/crypto🧪 TestedWeb Crypto API
WebSocketmizchi/js/web/websocket🧪 TestedWebSocket API
Workermizchi/js/web/worker🧪 TestedWeb Workers
MessageChannelmizchi/js/web/message🧪 TestedMessage passing
MessagePortmizchi/js/web/message🧪 TestedMessage ports
WebAssemblymizchi/js/web/webassembly🤖 AI GeneratedWASM integration
Performancemizchi/js/web/performance🤖 AI GeneratedPerformance API

Runtime-Specific APIs

PlatformPackageStatusDocumentation
Node.jsmizchi/js/node/*🧪 TestedNode.js README
Browser APImizchi/js/browser/*🧪 TestedBrowser README
Denomizchi/js/deno🧪 TestedDeno README

NPM Package Bindings

Moved to separate repository: NPM package bindings are now maintained atmizchi/npm_typed

CategoryPackagesRepository
UI FrameworksReact, React DOM, React Router, Preact, Inkmizchi/npm_typed
Web FrameworksHono, better-authmizchi/npm_typed
AI / LLMVercel AI SDK, MCP SDK, Claude Code SDKmizchi/npm_typed
Cloud Services@aws-sdk/client-s3 (S3, R2, GCS, MinIO)mizchi/npm_typed
DatabasePGlite, DuckDB, Drizzle, pgmizchi/npm_typed
ValidationZod, AJVmizchi/npm_typed
Build ToolsTerser, Vite, Unplugin, Lighthousemizchi/npm_typed
Utilitiesdate-fns, semver, chalk, dotenv, chokidar, yargs, debugmizchi/npm_typed
TestingTesting Library, Puppeteer, Playwright, Vitest, JSDOM, MSWmizchi/npm_typed
Parsinghtmlparser2, js-yamlmizchi/npm_typed
Othersimple-git, ignore, memfs, source-map, comlinkmizchi/npm_typed

Limited Support APIs

FeatureStatusNote
eval()❌ Not SupportedSecurity and type safety concerns
new Function()❌ Not SupportedSecurity and type safety concerns

Project Status

  • Node.js Core APIs -fs,path,process,child_process, etc.
  • Deno Runtime - File system, permissions, testing
  • Bun Runtime - Process, hashing, glob, file operations
  • DOM APIs - Full browser DOM manipulation
  • Web Standard APIs - fetch, URL, Streams, Crypto, WebSocket
  • 📦React/NPM Packages - Moved tomizchi/npm_typed
  • 📦Cloudflare Workers - Moved tomizchi/cloudflare.mbt

Goals

  • Provide comprehensive JavaScript FFI bindings for MoonBit
  • Platform Coverage
    • ✅ Browser DOM and Web APIs
    • ✅ Node.js/Deno/Bun runtime support
    • ✅ JavaScript built-in objects and Web Standard APIs
  • Ecosystem

Quick Start

Basic FFI Operations

// Create JavaScript objectsletobj=@js.from_entries([  ("name",@js.any("Alice")),  ("age",@js.any(30))])// Get propertyletname=obj["name"]// Set propertyobj["age"]=@js.any(31)// Call methodletresult=obj._call("toString", [])// Type castingletage:Int=obj["age"].cast()

LICENSE

MIT

About

Moonbit Js bindings

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp