Skip to content

nervosnetwork/moleculec-es

master
Switch branches/tags
Code

Latest commit

* feat: generate types for serialize paramters

* feat: add type declaration for vetor fields

* feat: add snapshot test for generator

* test: add test case for embedded vectors and optional fields

* chore: add mol file to make it more human readable

* fix: fix union type declaration error

* test: add test case for complex data type
c6a5db8

Git stats

Files

Permalink
Failed to load latest commit information.

moleculec-es

ECMAScript plugin for the molecule serialization system

Usage

First, download precompiled binary from releases page, and put the binary in our PATH. You could also clone and build the project from source. The only dependency is Golang here.

$ cargo install moleculec
$ moleculec --language - --schema-file "your schema file" --format json > /tmp/schema.json
$ moleculec-es -inputFile /tmp/schema.json -outputFile "your JS file"

Generated file from this project follows latest ECMAScript standard, it is also orgnaized as an ECMAScript module to allow for tree shaking.

Options

Usage of moleculec-es:
  -generateTypeScriptDefinition
        True to generate TypeScript definition
  -hasBigInt
        True to generate BigInt related functions
  -inputFile string
        Input file to use
  -outputFile string
        Output file to generate, use '-' to print to stdout (default "-")

ESM to CommonJS

Since moleculec-es generates ECMAScript modules, if you are using TS (< 4.5) or NodeJS(without ESM support) then you can convert ESM to CommonJS first. For example

npm i @babel/core @babel/cli @babel/plugin-transform-modules-commonjs
./node_modules/.bin/babel --plugins @babel/plugin-transform-modules-commonjs generated.js

About

ECMAScript plugin for the molecule serialization system

Resources

License

Stars

Watchers

Forks

Packages

No packages published