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

pattern-collector-anyjs

v1.9.12

Published

pull lines and build story for any js from supplied regex

Readme

pattern-collector-anyjs 🔍

A high-performance pattern collector and ESM import statement analyzer for JavaScript, specializing in analyzing and mapping Express router imports to their registrations.

npm version license

🔗 Quick Links:


📖 Overview

pattern-collector-anyjs is a lightweight static analysis library designed to map, analyze, and cross-reference ES module route imports against Express router registrations. It helps detect unused route imports or missing router imports in express route setup files.


⚡ Features

  • 🧩 ESM Import Extraction: Automatically identifies and pulls ES module imports with local paths.
  • 🛣️ Router Registration Audit: Extracts router.use() routes and matching variable names.
  • 🔍 Validation Checks: Cross-references imports against usage to generate detailed reports of unused or missing declarations.
  • 📦 Extensible & Versioned: Uses an internal folder-based versioning structure for core modules.

🔗 Dependency Chain


🚀 Installation

npm install pattern-collector-anyjs

🛠️ API Reference

default(options)

The default export is a function that parses a router file's content and builds a registration story.

Parameters

An options object containing:

  • fileContent (string): The raw string content of the Express routes file to parse.
  • parseRegex (RegExp): Regular expression used to parse import statements and extract the router variable name (first capture group) and subfolder path (second capture group).
  • searchRegex (RegExp): Regular expression used to locate ESM import lines in the content.
  • inShowLog (boolean, optional): Enables logging outputs for internal steps. Defaults to false.
  • showLogStep1 (boolean, optional): Enables logging outputs for step 1 extraction details. Defaults to false.
  • showLogStep2 (boolean, optional): Enables logging outputs for step 2 extraction details. Defaults to false.

Returns

  • (Object): The comparison story object containing:
    • importLines: Array of ESM import statements found and parsed.
    • useLines: Array of router registrations parsed from router.use().
    • importMissInUse: List of imports that are declared but never registered via router.use().
    • useMissInImport: List of registrations that do not have a matching import declaration.

💻 Usage Example

Here is how you can use pattern-collector-anyjs to analyze a routes file:

import patternCollectorAnyJS from 'pattern-collector-anyjs';

const fileContent = `
import express from 'express';

import { router as routerFromv1 } from "./v1/routes.js";
import { router as routerFromv2 } from "./v2/routes.js";

const router = express.Router()

router.use("/v1", routerFromv1);

export { router };
`;

// Extract variable name & folder name from route imports
const parseRegex = /import\s*\{[^}]*router\s+as\s+(\w+)[^}]*\}\s*from\s*['"]\.\/([^/]+)\/.*['"]/;
// Match local import lines
const searchRegex = /^[ \t]*import\b.*from\s+['"]\.[^'"]*['"];/gm;

const story = patternCollectorAnyJS({
    fileContent,
    parseRegex,
    searchRegex
});

console.log(story);

Output:

{
  "importLines": [
    {
      "variable": "routerFromv1",
      "folderName": "v1",
      "line": "import { router as routerFromv1 } from \"./v1/routes.js\";",
      "lineNumber": 3
    },
    {
      "variable": "routerFromv2",
      "folderName": "v2",
      "line": "import { router as routerFromv2 } from \"./v2/routes.js\";",
      "lineNumber": 4
    }
  ],
  "useLines": [
    {
      "routeName": "v1",
      "variableName": "routerFromv1",
      "line": "router.use(\"/v1\", routerFromv1);",
      "lineNumber": 8
    }
  ],
  "importMissInUse": [
    {
      "variable": "routerFromv1",
      "folderName": "v1",
      "line": "import { router as routerFromv1 } from \"./v1/routes.js\";",
      "lineNumber": 3,
      "isFound": true,
      "usedLine": {
        "routeName": "v1",
        "variableName": "routerFromv1",
        "line": "router.use(\"/v1\", routerFromv1);",
        "lineNumber": 8
      }
    },
    {
      "variable": "routerFromv2",
      "folderName": "v2",
      "line": "import { router as routerFromv2 } from \"./v2/routes.js\";",
      "lineNumber": 4,
      "isFound": false,
      "usedLine": null
    }
  ],
  "useMissInImport": [
    {
      "routeName": "v1",
      "variableName": "routerFromv1",
      "line": "router.use(\"/v1\", routerFromv1);",
      "lineNumber": 8,
      "isFound": true,
      "usedLine": {
        "variable": "routerFromv1",
        "folderName": "v1",
        "line": "import { router as routerFromv1 } from \"./v1/routes.js\";",
        "lineNumber": 3
      }
    }
  ]
}

🧹 Cleaning Workflow Runs

To keep your GitHub Actions dashboard clean and free of old runs, you can delete them in bulk using the included utility script:

  1. Run the script:
    node clean-runs.js
  2. Paste your GitHub Personal Access Token (PAT) with actions:write (or repo) permissions when prompted.

⚖️ License

MIT License. Designed with ❤️ by KeshavSoft.