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

cjs-module-lexer-rs

v0.2.6

Published

[![npm](https://img.shields.io/npm/v/cjs-module-lexer-rs)](https://www.npmjs.com/package/cjs-module-lexer-rs) ![NPM](https://img.shields.io/npm/l/cjs-module-lexer-rs)

Downloads

11

Readme

npm NPM

CJS Module Lexer (Rust)

This is a rewrite of cjs-module-lexer in Rust. It is a CommonJS lexer used to detect the most likely list of named exports of a CommonJS module.

Online Playground

CJS Module Lexer Playground

Installation

WebAssembly JS Wrapper

With Package Managers

npm i cjs-module-lexer-rs
yarn add cjs-module-lexer-rs
pnpm add cjs-module-lexer-rs

With esm.sh

import { init, parse } from "https://esm.sh/cjs-module-lexer-rs";

Rust

Coming soon...

Get Started

Node

// example.js
const { init, parse } = require("cjs-module-lexer-rs");

const code = `
    module.exports.asdf = 'asdf';
    exports = 'asdf';
    module.exports = require('./asdf');
    if (maybe)
    module.exports = require("./another");
`;

init().then(() => console.log(parse(code, 'filename.js')));
{
  imports: [ './asdf', './another'],
  exports: [ 'asdf' ],
  reexports: [ './another' ],
  errors: []
}

Web

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Lexer Example</title>
    </head>
    <body>
        <script type="module">
            import { init, parse } from "https://esm.sh/cjs-module-lexer-rs";

            const code = `
                module.exports.asdf = 'asdf';
                exports = 'asdf';
                module.exports = require('./asdf');
                if (maybe)
                module.exports = require("./another");
            `;

            init().then(() => console.log(parse(code, 'filename.js')));
        </script>
    </body>
</html>
{
    "imports": [
        "./asdf",
        "./another",
    ],
    "exports": [
        "asdf"
    ],
    "reexports": [
        "./another"
    ],
    "errors": []
}

The Why

The frontend tooling has migrated to usage of moderm native languages to accelerate development and improve developer experience. cjs-module-lexer remains useful in many scenes, but it assumes the code is UTF16 and only allows single-thread. Making cjs-module-lexer working with Rust requires FFI and unsafe code. Hopefully this Rust library will be useful for Rust tooling authors to interop between CJS and ESM.

Features

| Feature | Status | Since | Note | |---|---|---|---| | exports.asdf = x | 👌 | 0.1.0 | | exports['asdf'] = x | 👌 | 0.1.0 | | module.exports = { ... } | 👌 | 0.1.0 | { ... } is like { a, b, c: d }, where d is Literal or Identifier | | require('module') | 👌 | 0.1.0 | | Object.defineProperty(exports, 'q', { enumerable: true, get() { return q } }) | 👷 | | TypeScript: export {colorFactory} from './color-factory'; | __export, __exportStar | 👷 | | TypeScript: export * from 'external' | | Skip StringLiteral | 👌 | 0.1.0 | | Skip RegularExpressionLiteral | 👌 | 0.1.0 | Skip Template | 👌 | 0.1.0 | Non-unicode Named Export | ❌ | | Not supported due to std::str only allows unicode strings

Reference

https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs

Benchmarks

Native

cargo bench

test tests::bench_angular          ... bench:   5,176,437 ns/iter (+/- 260,598)
test tests::bench_angular_min      ... bench:   2,321,468 ns/iter (+/- 939,693)
test tests::bench_d3               ... bench:   3,155,154 ns/iter (+/- 182,490)
test tests::bench_d3_min           ... bench:   1,897,146 ns/iter (+/- 100,576)
test tests::bench_magic_string     ... bench:     209,630 ns/iter (+/- 11,577)
test tests::bench_magic_string_min ... bench:     145,834 ns/iter (+/- 7,527)
test tests::bench_rollup           ... bench:   3,918,989 ns/iter (+/- 130,726)
test tests::bench_rollup_min       ... bench:   2,637,478 ns/iter (+/- 74,449)