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

code-slicer

v0.5.0

Published

Extract minimal, dependency-aware code context from an entry file for use in AI prompts.

Downloads

1,266

Readme

code-slicer

npm version Code Quality Code Coverage Socket

Extract minimal, dependency-aware code context from an entry file for use in AI prompts.

code-slicer is a CLI that traverses local imports from an entry file and outputs relevant code in traversal order. It is designed for AI workflows where precise context matters more than full repository dumps.

Quickstart

Installation

npm install --save-dev code-slicer

Usage

code-slicer <entry-file>
code-slicer <entry-file> --format <plain|markdown|html|xml>

Example

code-slicer src/bin.ts

What it does

  • Starts from a single entry file
  • Follows local imports and dependencies
  • Supports JavaScript, TypeScript, JSX, TSX, React, and Vue
  • Outputs files in traversal order
  • Includes full source code for each file
  • Excludes external packages and unresolved modules

Output formats

Supported formats:

  • plain (default)
  • markdown
  • html
  • xml

Plain (default)

code-slicer src/bin.ts
relative/path/to/file.ts
<source code>

relative/path/to/another-file.ts
<source code>

Markdown

code-slicer src/bin.ts --format markdown
### relative/path/to/file.ts

```
<source code>
```

### relative/path/to/another-file.ts

```
<source code>
```

HTML

code-slicer src/bin.ts --format html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>code-slicer output</title>
</head>
<body>
  <main class="code-slicer-output">
    <section class="code-slicer-file">
      <h3>relative/path/to/file.ts</h3>
      <pre><code>&lt;source code&gt;</code></pre>
    </section>
  </main>
</body>
</html>

XML

code-slicer src/bin.ts --format xml
<?xml version="1.0" encoding="UTF-8"?>
<files>
  <file path="relative/path/to/file.ts">
    <source>&lt;source code&gt;</source>
  </file>
</files>

Constraints

  • Only local file dependencies are included
  • node_modules is ignored
  • No bundling or code transformation
  • No runtime evaluation
  • Output is deterministic and file-based

Requirements

  • Node.js >= 22

How it works

  1. Detect file type (JavaScript, TypeScript, Vue)
  2. Parse source
    • TypeScript AST for JS/TS/JSX/TSX
    • Vue SFC parser for .vue files
  3. Extract imports (import, export ... from, import())
  4. Resolve modules using TypeScript resolution with fallback logic
  5. Recursively traverse dependencies
  6. Track visited files to avoid cycles
  7. Skip external and unresolved modules

Use cases

  • AI prompt generation with relevant code context
  • Dependency inspection
  • Minimal reproduction cases
  • Code review context extraction

Contributing

See CONTRIBUTING.md for process, standards, and testing expectations.

License

MIT