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-pull-lines

v1.14.2

Published

A powerful, configurable tool to scan JavaScript/ESM files and pull structured line matches using custom regular expressions.

Readme

pattern-collector-anyjs-pull-lines 🔍

A powerful, configurable tool to scan JavaScript/ESM files and pull structured line matches using custom regular expressions.

npm version license

🔗 Quick Links:


📖 Overview

pattern-collector-anyjs-pull-lines is a modular ES module that allows you to static-analyze JavaScript or ESM source code. It scans file contents to identify specific patterns (such as import statements or routing configurations) and extracts line details, line numbers, variable names, and directory paths.

This library is particularly useful for building automated routing trees, generating bundle maps, or auditing source code patterns.


✨ Features

  • 🧩 Modular Design: Leveraging clean, focused sub-modules for flexible ESM pattern extraction.
  • 🏷️ Line Tracking: Identifies exactly which line number each pattern appears on.
  • 🧩 Custom Extraction Regex: Extracts variables, directories, and paths using flexible capturing groups in your regular expressions.
  • 📦 ESM Native: Built for modern ES module environments.

🔗 Dependency Chain


🚀 Installation

npm install pattern-collector-anyjs-pull-lines

💻 Usage Example

Here is a quick example showing how to extract import and route usage patterns:

import pullLines from 'pattern-collector-anyjs-pull-lines';

const code = `
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);
`;

const result = pullLines({
  fileContent: code,
  importRegex: {
    // Captures the router variable alias and the module folder name
    parseRegex: /import\s*\{[^}]*router\s+as\s+(\w+)[^}]*\}\s*from\s*['"]\.\/([^/]+)\/.*['"]/,
    // Search regex to identify import lines
    searchString: /^[ \t]*import\b.*from\s+['"]\.[^'"]*['"];/gm
  },
  consumptionRegex: {
    // Captures routing paths and the associated router variable names
    parseRegex: /router\.use\s*\(\s*['"`]\/?([^'"`]+)['"`]\s*,\s*(\w+)/,
    // Search regex to identify route usage lines
    searchString: /^[ \t]*router\.use\b.*?;/gm
  }
});

console.log(result);
/*
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: [
    {
      variable: 'v1',
      folderName: 'routerFromv1',
      line: 'router.use("/v1", routerFromv1);',
      lineNumber: 7
    }
  ]
}
*/

🛠️ API Reference

default(options)

The default export is a function that parses the provided content and returns matching pattern details.

Parameters

An options object containing:

  • fileContent (string): The raw javascript source code string to analyze.
  • importRegex (object): Config for parsing import statements:
    • searchRegex / searchString (RegExp): Regular expression with g flag to search for import statements in the code.
    • parseRegex (RegExp): Regular expression with capture groups to extract specific variables (variable) and folder names (folderName).
  • consumptionRegex (object): Config for parsing route consumption statements:
    • searchRegex / searchString (RegExp): Regular expression with g flag to search for route usage patterns.
    • parseRegex (RegExp): Regular expression with capture groups to extract paths and variables.
  • showLog (boolean) (optional): When set to true, outputs intermediate matching arrays to the console.
  • showLogStep1 (boolean) (optional): When set to true, outputs step-by-step extraction details.

Returns

  • Object:
    • importLines (Array<Object>): Extracted import matching objects.
    • useLines (Array<Object>): Extracted usage matching objects.

Each item in the lists has the following shape:

{
  variable: string;    // Captured variable name from parseRegex
  folderName: string;  // Captured directory or value from parseRegex
  line: string;        // Full original line matching the search regex
  lineNumber: number;  // 1-indexed line number in the source file
}

⚖️ License

MIT License. Designed with ❤️ by KeshavSoft.