0.1.1 • Published 2 years ago
mahler-wasm v0.1.1
mahler-wasm
WASM compiled utilities for Mahler.
This module uses wasm-pack to expose some essential functions from Rust to make them accessible in Node.js.
Provided functions
diff
. Create a JSON Patch to transform between two JSON serializable objects. This function just exposes the functionality from the json-patch crate.patch
. Apply a JSON Patch to a JSON serializable object. This function just exposes the functionality from the json-patch crate.
Example
import { diff, patch } from "mahler-wasm";
const left = {
"title": "Goodbye!",
"author" : {
"givenName" : "John",
"familyName" : "Doe"
},
"tags":[ "example", "sample" ],
"content": "This will be unchanged"
};
const right = {
"title": "Hello!",
"author" : {
"givenName" : "John"
},
"tags": [ "example" ],
"content": "This will be unchanged",
"phoneNumber": "+01-123-456-7890"
};
const p = diff(left, right);
console.log(p);
// [
// { "op": "remove", "path": "/author/familyName" },
// { "op": "remove", "path": "/tags/1" },
// { "op": "replace", "path": "/title", "value": "Hello!" },
// { "op": "add", "path": "/phoneNumber", "value": "+01-123-456-7890" },
// ]
const doc = patch(left, p);
console.log(doc);
// {
// "title": "Hello!",
// "author" : {
// "givenName" : "John"
// },
// "tags": [ "example" ],
// "content": "This will be unchanged",
// "phoneNumber": "+01-123-456-7890"
// }
Installing
This module does not have any dependencies for installing, to install, you can just use
npm install mahler-wasm
Building mahler-wasm
To build the module, these are the dependencies
- Rust
- The wasm32-wasi target
- wasm-pack
Before building, you need to install the repository dependencies
# Pull the repository if you haven't done it yet
git clone https://github.com/balena-io-modules/mahler-wasm.git && cd mahler-wasm
# Install dependencies
npm install
Assuming you have all dependencies installed, you can build using
npm run build
And use the following to run tests
npm run test
License
Licensed under Apache License, Version 2.0