squiggle/packages/website/docs/Features/Javscript-Libraries.md

38 lines
1.5 KiB
Markdown
Raw Permalink Normal View History

2022-02-06 18:40:28 +00:00
---
2022-03-25 02:08:46 +00:00
sidebar_position: 3
2022-02-06 18:40:28 +00:00
---
2022-03-25 02:08:46 +00:00
# Javascript Libraries
2022-02-06 18:40:28 +00:00
2022-03-25 02:08:46 +00:00
There are two JavaScript packages currently available for Squiggle:
2022-04-10 23:15:46 +00:00
- [`@quri/squiggle-lang`](https://www.npmjs.com/package/@quri/squiggle-lang)
- [`@quri/squiggle-components`](https://www.npmjs.com/package/@quri/squiggle-components)
2022-02-06 18:40:28 +00:00
2022-03-25 02:08:46 +00:00
Types are available for both packages.
2022-02-09 15:22:51 +00:00
2022-03-25 02:08:46 +00:00
## Squiggle Language
2022-02-09 15:22:51 +00:00
2022-03-25 02:08:46 +00:00
The `@quri/squiggle-lang` package exports a single function, `run`, which given
a string of Squiggle code, will execute the code and return any exports and the
environment created from the squiggle code.
`run` has two optional arguments. The first optional argument allows you to set
sampling settings for Squiggle when representing distributions. The second optional
argument allows you to pass an environment previously created by another `run`
call. Passing this environment will mean that all previously declared variables
in the previous environment will be made available.
The return type of `run` is a bit complicated, and comes from auto generated js
code that comes from rescript. I highly recommend using typescript when using
this library to help navigate the return type.
## Squiggle Components
The `@quri/squiggle-components` package offers several components and utilities
for people who want to embed Squiggle components into websites. This documentation
2022-04-10 23:15:46 +00:00
relies on `@quri/squiggle-components` frequently.
2022-03-25 02:08:46 +00:00
2022-04-10 23:52:39 +00:00
We host [a storybook](https://squiggle-components.netlify.app/) with details
2022-03-25 02:08:46 +00:00
and usage of each of the components made available.