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

kernel-js-lite

v2.38.0

Published

Embedded JavaScript kernel — pure Node.js JS runtime for safe execution of untrusted code. Tokenizer, parser, interpreter with scopes, closures, built-in objects, host API bindings, and resource limits. (中文 / English / 日本語 / 한국어)

Readme

kernel-js-lite

嵌入式 JavaScript 内核 — 纯 Node.js 实现的 JavaScript 运行时,用于安全执行不可信代码。

类似 QuickJS 但用纯 Node 实现:词法分析 → 语法分析 → AST → 树遍历解释器。零依赖。

npm install kernel-js-lite

快速开始

const { run, Kernel } = require('kernel-js-lite')

// 一步执行
run('1 + 2 * 3') // 7

// 使用 Kernel 实例(支持宿主函数绑定)
const k = new Kernel()
k.hostFunction('double', (x) => x * 2)
k.run('double(21)') // 42

功能特性

| 特性 | 状态 | |------|------| | 词法分析器 | ✓ | | 递归下降语法分析器 | ✓ | | 算术运算 (+ - * / %) | ✓ | | 比较运算 (=== !== < > <= >=) | ✓ | | 逻辑运算 (&& \|\| !) | ✓ | | 变量声明 (var let const) | ✓ | | 赋值 | ✓ | | 条件语句 (if/else) | ✓ | | 循环 (while for) | ✓ | | 函数声明与调用 | ✓ | | 递归 | ✓ | | 闭包(词法作用域) | ✓ | | 数组 ([1,2,3]) | ✓ | | 对象 ({a:1}) | ✓ | | 内置对象 (Array, Object, String, Number, Boolean) | ✓ | | Arraypush pop join indexOf includes slice splice forEach map filter reduce reverse | ✓ | | Stringlength charAt indexOf includes slice split toUpperCase toLowerCase trim replace | ✓ | | Objectkeys values entries assign | ✓ | | Mathabs ceil floor round max min pow sqrt random PI E | ✓ | | console.log/warn/error | ✓ | | 宿主函数绑定 | ✓ | | 资源限制(CPU 指令数、调用深度、内存) | ✓ | | 注释 (// /* */) | ✓ |

资源限制

const result = run(code, {
  maxInstructions: 10000,  // 最大 AST 节点数(默认 100000)
  maxDepth: 500,           // 最大调用栈深度(默认 1000)
  maxMemory: 4194304,      // 最大内存字节数(默认 8MB)
})

超出限制时抛出 Error('Script execution timeout: ...')

Kernel API

run(code, options?)

一步完成解析和执行,返回最后一个表达式的值。

new Kernel(options?)

创建一个可复用的内核实例。

kernel.hostFunction(name, fn)

注册一个宿主(Node.js)函数,沙箱内代码可直接调用。

const k = new Kernel()
k.hostFunction('fetchUser', (id) => ({ id, name: 'Alice' }))
k.run('fetchUser(1).name') // 'Alice'

kernel.compile(code)

将代码编译为 AST,用于重复执行。

kernel.execute(ast, options?)

执行预编译的 AST。

支持的语法

// 变量
var x = 1
let y = 2
const z = 3

// 算术
1 + 2 * (3 - 4) / 5

// 比较
a === b, a !== b, a < b, a > b, a <= b, a >= b

// 逻辑
true && false, true || false, !true

// 条件
if (x > 0) { ... } else { ... }

// 循环
while (i < 10) { i = i + 1 }
for (var i = 0; i < 10; i = i + 1) { ... }

// 函数
function add(a, b) { return a + b }
add(1, 2)

// 闭包
function makeCounter() {
  var count = 0
  return function() { count = count + 1; return count }
}

// 数组
var arr = [1, 2, 3]
arr.push(4)
arr.map(function(x) { return x * 2 })

// 对象
var obj = { a: 1, b: 2 }
obj.a
Object.keys(obj)

许可证

MIT