# @stemcstudio/js-to-mathscript

> JavaScript to MathScript transpiler.

Latest version **1.0.3** (published 2023-01-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @stemcstudio/js-to-mathscript
pnpm add @stemcstudio/js-to-mathscript
yarn add @stemcstudio/js-to-mathscript
bun add @stemcstudio/js-to-mathscript
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2023-01-05 |
| First published | 2022-02-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | David Geo Holmes |
| Maintainers | geometryzen |

## Links

- npm: https://www.npmjs.com/package/@stemcstudio/js-to-mathscript
- Repository: https://github.com/geometryzen/js-to-mathscript
- Homepage: https://github.com/geometryzen/js-to-mathscript#readme
- Issues: https://github.com/geometryzen/js-to-mathscript/issues
- npm.io page: https://npm.io/package/@stemcstudio/js-to-mathscript

## Recent versions

- 1.0.3 (latest) — 2023-01-05
- 1.0.2 — 2022-02-16
- 1.0.1 — 2022-02-14
- 1.0.0 — 2022-02-12

## README

# js-to-mathscript
A transpiler and validator from JavaScript syntax to some similar syntax.

Example of replacing the name of a Binary operator:

```typescript
    it('Exponentiation', function () {
      const src = 'x**2';
      const { code } = jsToMathScript(src,
        {
          namespace: '',
          binOp: {
            '**': { kind: 'rename', value: '^' }
          },
          unaryOp: {}
        },
        {
          format: {
            semicolons: false
          }
        }
      );
      assert.strictEqual(code, 'x ^ 2');
    });
```

Example of converting a Binary operator to a function call:

```typescript
it('Bitwise XOR (^) should be turned into a function.', function () {
    const src = 'x ^ y';
    const { code } = jsToMathScript(src, {
            namespace: 'MathScript',
            binOp: {
                '**': { kind: 'rename', value: '^' },
                '^': { kind: 'function', value: 'wedge' }
            },
            unaryOp: {}
        },
        {
        format: {
            semicolons: false
        }
    });
    assert.strictEqual(code, 'MathScript.wedge(x, y)');
});
```

Example of rejecting a Unary operator:

```typescript
it("error", function () {
    try {
        const src = "const a = +b";
        jsToMathScript(src, {
            unaryOp: {
                '+': { kind: 'error', value: "Unexpected unary plus (+)" }
            }
        });
        assert.fail();
    } catch (e) {
        if (e instanceof Error) {
            assert.strictEqual(e.name, "Error");
            assert.strictEqual(e.message, "Unexpected unary plus (+)");
        } else {
            assert.fail();
        }
    }
});
```

---
_Source: https://npm.io/package/@stemcstudio/js-to-mathscript · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
