Skip to content

davidtorosyan/ti-js

Repository files navigation

TI-JS

Table of contents

Introduction

TI-JS lets you run TI-Basic programs in the browser (by acting as a compiler/runtime, not through emulation).

Currently working on expanding the grammar, so this is in prerelease.

Check out the project page and the test suite, or playground.

Setup

TI-JS releases are available via npm.

For developing, see the CONTRIBUTING.md.

Node

If you've got a package.json, you'll want to install first:

npm install ti-js

How you then import it depends on the platform you're developing for. See the table below:

platform CommonJS ES6
node require('ti-js') import * as ti from 'ti-js'
web const ti = require('ti-js/dist/web/ti') import * as ti from 'ti-js/dist/web/ti'

See sample directories for examples.

Static

If you've just got a static webpage, you can import the library like so:

<script
    src="https://cdn.jsdelivr.net/npm/ti-js@latest/dist/web/ti.min.js"
    crossorigin="anonymous"></script>

Note that you can specify the version you want instead of using latest.

Then just declare ti as global in your scripts and use it:

/* global ti */

See the docs directory for example webpages.

Usage

Note: In progress! This library is still in pre-release.

Writing TI-BASIC code

This library doesn't support TI-BASIC exactly, but an ASCII-fied version of it.

Furthermore, not all commands are implemented yet.

To see which commands are available, refer to the table in ROADMAP.md.

API

The interface is still in progress, but here's two ways you can use the library.

Porcelain

The simplest way to use the library is the exec command, which runs a TI-Basic program, collects the output, and passes it to a specified callback.

ti.exec('Disp "hello world"', output => {
  document.body.innerHTML += output
})

Plumbing

If you want more control over the runtime, use the parse and run commands directly. This will let you inspect the running program and redirect the output wherever you like.

const lines = ti.parse(source)
program = ti.run(lines, {
    elem: $output,
})

License

MIT

About

TI-Basic interpreter written in JavaScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published