npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

seval.js

v1.2.1

Published

S-expression evaluator for TypeScript/JavaScript

Readme

seval.js

S-expression evaluator for TypeScript/JavaScript

CI Codecov npm version License: MIT

seval.js is a safe, sandboxed S-expression parser and evaluator. It's designed to be easily extensible and embeddable in JavaScript/TypeScript applications.

Installation

npm install seval.js
# or
bun add seval.js

Quick Start

import { evalString, createEvaluator } from 'seval.js'

// Simple evaluation
evalString('(+ 1 2 3)')     // 6
evalString('(* 2 (+ 3 4))') // 14

// Conditional and logic
evalString('(if (> 5 3) "yes" "no")') // "yes"
evalString('(and true (not false))')  // true

// Lambda and closures
evalString('((lambda (x) (* x x)) 5)') // 25

// Custom primitives
const evaluator = createEvaluator({
  primitives: {
    uuid: () => crypto.randomUUID(),
    greet: (args) => `Hello, ${args[0]}!`,
  }
})
evaluator.evalString('(greet "World")') // "Hello, World!"

Features

  • Safe sandboxed evaluation - No access to global scope or dangerous APIs
  • Rich primitive library - 60+ built-in functions for math, strings, arrays, objects
  • Lambda and closures - First-class functions with lexical scoping
  • Customizable - Add or override primitives easily
  • TypeScript support - Full type definitions included

Built-in Primitives

Arithmetic

+, -, *, /, %

Comparison

=, !=, <, >, <=, >=

Logical

and, or, not

Math

abs, min, max, floor, ceil, round, sqrt, pow, clamp, sin, cos, tan, log, exp, random

Strings

concat, str, strlen, substr, str-starts-with, str-ends-with, str-contains, str-replace, str-split, str-join, str-trim, str-upper, str-lower, parse-num, parse-int

Arrays

list, length, first, rest, last, nth, append, prepend, concat-lists, slice, reverse, range, empty?, contains, index-of

Objects

obj, get, set, keys, values, has-key, update-at, merge

Type checks

null?, number?, string?, bool?, list?, object?

Special Forms

; Conditionals
(if condition then-expr else-expr)
(cond (test1 expr1) (test2 expr2) (else exprN))

; Variable bindings
(let ((x 1) (y 2)) (+ x y))

; Functions
(lambda (x y) (+ x y))
(define (square x) (* x x))
(define pi 3.14159)

; Sequences
(begin expr1 expr2 ...)
(progn expr1 expr2 ...)

; Higher-order functions
(map (lambda (x) (* x 2)) (list 1 2 3))        ; (2 4 6)
(filter (lambda (x) (> x 2)) (list 1 2 3 4))   ; (3 4)
(reduce (list 1 2 3) 0 (acc x) (+ acc x))      ; 6

API

evalString(code: string): Value

Parse and evaluate an S-expression string.

evaluate(expr: SExpr, env?: Environment): Value

Evaluate a parsed S-expression AST.

parse(code: string): SExpr

Parse an S-expression string into an AST.

stringify(expr: SExpr): string

Convert an AST back to string.

createEvaluator(options?: EvaluatorOptions)

Create a custom evaluator with additional primitives.

interface EvaluatorOptions {
  primitives?: Record<string, PrimitiveFunction>
  maxDepth?: number  // default: 100
}

License

MIT