Registry / serialization / scheme2js

scheme2js

JSON →
library1.4.2jsnpmunverified

Version 1.4.2. A simple Scheme-to-JavaScript transpiler that converts Scheme expressions into JavaScript code. It supports basic Lisp constructs such as define, lambda, if, binary operations, and boolean expressions. The package includes a CLI tool (s2j) and a Node.js API. It features optional polyfill for pairs (cons, car, cdr). The library is lightweight and designed for educational purposes or small Scheme snippets. Release cadence is low, with no recent updates on GitHub.

npm install scheme2js
INSTALL
IMPORT
SIG · SCHEME2JS
S
scheme2js
serializationjavascriptv1.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import s2j from 'scheme2js'
const s2j = require('scheme2js')
ESM default import; CJS require works but is not the recommended pattern for modern usage.
default as named
import s2j from 'scheme2js'
import { s2j } from 'scheme2js'
The module exports a single function as default; there is no named export.
type definitions
import s2j from 'scheme2js'
import { compile } from 'scheme2js'
The library does not ship TypeScript types; use its default export only.

Transpile a Scheme factorial function to JavaScript using the API.

import s2j from 'scheme2js'; const schemeCode = ` (define (factorial n) (if (eq n 0) 1 (* n (factorial (- n 1)))) `; const jsCode = s2j(schemeCode); console.log(jsCode); // Output: // function factorial(n) { // return eq(n, 0) ? 1 : n * factorial(n - 1); // }
s2j --version
Debug
Known issues
gotchaThe transpiler does not support all Scheme standards; it only handles a subset (define, lambda, if, binary ops, booleans). Complex macros or continuations will fail.
fix
Use only the documented constructs; refer to the README for supported features.
affects: *
gotchaThe `--pairs` flag adds a global polyfill for cons, car, cdr. This pollutes the global scope and may conflict with other libraries.
fix
Use the CLI without --pairs if you don't need pairs, or scope the polyfill manually.
affects: *
gotchaThe output uses `var` for definitions (e.g., `var foo = 1`). This may cause scoping issues in modern JavaScript contexts.
fix
Manually replace `var` with `let` or `const` after transpilation.
affects: *
deprecatedRequire-style usage (const s2j = require('scheme2js')) is not deprecated but is not ESM-compatible. The package does not support ESM natively.
fix
Use ESM import syntax if your environment supports it.
affects: *
Errors
Common errors & fixes
const s2j = require('scheme2js') returns undefined
The export might be a transpiled CommonJS module that does not export a default.
fix
Use `const s2j = require('scheme2js').default` or use ES module import.
s2j(code) throws 'code is not a string'
The function expects a string argument; passing a Buffer or other type will throw.
fix
Ensure the input is a string: `s2j(String(code))`.
_ is not defined (after using pairs polyfill)
The polyfill defines a helper `_` on the global object; if the code uses it before loading polyfill, references fail.
fix
Ensure `--pairs` is used at compile time and the resulting JavaScript file includes the polyfill at the top.
Upgrade
Version history
1.4.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
scheme2js — npm install scheme2js · libregistry