0.1.16 • Published 4 years ago

liminoid-js v0.1.16

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Lightweight asynchonous Javascript REPL for web assembly language runtimes

Installation

$ yarn add liminoid-js

or

$ npm install --save liminoid-js

Usage

For a more comprehensive guide to using the package see the documentation or browse the examples.

// easiest to use ES6 imports from the CDN
import { Repl } from 'https://cdn.liminoid.io/liminoid-js/index.js';
// import { Repl } from https://cdn.liminoid.io/liminoid-js@x.x.x/index.js

// Repl() constuctor is synchronous
const repl = new Repl();

// each call to run() returns a promise that resolves
// to the Repl() object. The value of the executed
// expression is stored as `.value` on the Repl()
repl
  .init()
  .then((repl) => repl.load(['numpy']))
  .then((repl) => repl.run('import numpy as np'))
  .then((repl) => repl.run('a = [[1, 0], [0, 1]]'))
  .then((repl) => repl.run('b = [[4, 1], [2, 2]]'))
  .then((repl) => repl.run('np.dot(a, b)'))
  .then((repl) => console.log(repl.value)); //=> Array[ Int32Array [ 4, 1 ], Int32Array [ 2, 2 ] ]

If you want to run a chunk of code in a single call you can use Javascript template literals.

// NOTE: importing a library twice (numpy here) can cause an error
// so we leave the import out of the code chunk.
const code = `
a = [[1, 0], [0, 1]]
b = [[4, 1], [2, 2]]
np.dot(a, b)
`.trim();

// you can use await syntax as long as you are in an async function
const dotProduct = (async () => {
  const repl = await new Repl().init();
  await repl.load(['numpy']);
  await repl.run('import numpy as np');

  const result = await repl.run(code);
  console.log(result.value); //=> Array[ Int32Array [ 4, 1 ], Int32Array [ 2, 2 ] ]
})();

See how to run this example in a web page: examples/hello-liminoid.html

Contributing/Requests

Open an issue or post a message in the chatroom. If you would like to contribute to the project (code, documentation, tutorials, etc.) see the contributing guide for how to get started 🙌

Citing

While not required, when using (or extending) Liminoid for academic work, citations are appreciated 🙏

@software{liminoid,
  author = {Jonathan Dinu},
  title = {Liminoid: Web assembly toolkit for building local-first interactive analytics applications},
  month = {March},
  year = {2020},
  version = {0.0.1},
  doi = {10.5281/zenodo.3754953},
  url = {https://github.com/liminoid},
}

License

All original work licensed under either of:

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

0.1.16

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.13

4 years ago

0.1.12

4 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.0

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago