https://github.com/bluwy/fmu
A collection of JS module utilities written in Rust
https://github.com/bluwy/fmu
javascript module
Last synced: about 1 year ago
JSON representation
A collection of JS module utilities written in Rust
- Host: GitHub
- URL: https://github.com/bluwy/fmu
- Owner: bluwy
- License: mit
- Created: 2022-07-14T18:11:16.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-28T04:40:48.000Z (almost 2 years ago)
- Last Synced: 2025-03-28T22:23:43.689Z (over 1 year ago)
- Topics: javascript, module
- Language: Rust
- Homepage: https://bluwy.github.io/fmu
- Size: 110 KB
- Stars: 22
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A collection of JS module utilities written in Rust
## Usage
The package is published to npm as a WebAssembly module. Install with:
```bash
$ npm install fmu
```
```js
import { init, guessJsSyntax } from 'fmu'
// initialize wasm (MUST call this before any other APIs)
await init()
const code = `exports.foo = 'bar'`
console.log(await guessJsSyntax(code)) // "CJS"
```
> **Note**: For Vite, you have to pass a custom URL to `init()`. For example:
>
> ```js
> import { init } from 'fmu'
> import wasmUrl from 'fmu/wasm?url'
> await init(wasmUrl)
> ```
See [examples](./examples/) for usage with different setups.
## Development
Follow the [official guide](https://www.rust-lang.org/tools/install) to install Rust. Also install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/) to build Rust files into WebAssembly.
```bash
# Build wasm for dev (e.g. testing examples)
$ npm run dev
# Build wasm for publishing
$ npm run build
# Run unit and integration tests
$ cargo test
```
## Sponsors
## License
MIT