pattern-collector-anyjs 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KeshavSoft
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to do so, subject to the
10
+ following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # pattern-collector 🔍
2
+
3
+ > **A high-performance pattern collector and ESM import statement analyzer for JavaScript.**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/pattern-collector.svg?style=flat-square&color=38bdf8)](https://www.npmjs.com/package/pattern-collector)
6
+ [![license](https://img.shields.io/npm/l/pattern-collector.svg?style=flat-square&color=34d399)](LICENSE)
7
+
8
+ 🔗 **Quick Links:**
9
+ * 📦 **NPM Registry**: [npmjs.com/package/pattern-collector](https://www.npmjs.com/package/pattern-collector)
10
+ * 💻 **GitHub Repo**: [github.com/keshavsoft/pattern-collector](https://github.com/keshavsoft/pattern-collector)
11
+ * 📄 **Interactive Docs**: [keshavsoft.github.io/pattern-collector](https://keshavsoft.github.io/pattern-collector/)
12
+ * ⚙️ **Publish Workflow**: [.github/workflows/npm-publish.yml](file:///d:/KeshavSoftRepos/2026-07-18/ks6/pattern-collector/.github/workflows/npm-publish.yml)
13
+
14
+ ---
15
+
16
+ ## 📖 Overview
17
+
18
+ `pattern-collector` is a zero-dependency, lightweight JavaScript library designed to scan file content and collect substrings that match a specified pattern or regular expression.
19
+
20
+ It serves as a fast and flexible engine, enabling easy parsing, extraction, and static analysis of source files (such as locating ES Module imports, decorators, function declarations, or other syntactic patterns).
21
+
22
+ ---
23
+
24
+ ## ✨ Features
25
+
26
+ * **⚡ Zero Dependencies**: Light, fast, and secure.
27
+ * **🧩 Flexible Matching**: Collects any patterns by accepting custom global Regular Expressions.
28
+ * **📦 ESM Native**: Built for modern ES module environments.
29
+ * **🏷️ Versioned Under the Hood**: Uses an extensible directory-based versioned core.
30
+
31
+ ---
32
+
33
+ ## 🚀 Installation
34
+
35
+ ```bash
36
+ npm install pattern-collector
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 🛠️ API Reference
42
+
43
+ ### `default(options)`
44
+
45
+ The default export is a function that collects all occurrences of a pattern in the given text.
46
+
47
+ #### Parameters
48
+
49
+ An options object containing:
50
+
51
+ * **`fileContent`** `(string)`: The raw text or code content to search.
52
+ * **`searchString`** `(RegExp)`: A regular expression with the global (`g`) flag to match patterns in the content.
53
+
54
+ #### Returns
55
+
56
+ * `(string[])`: An array of matches found. If no matches are found, it returns an empty array.
57
+
58
+ ---
59
+
60
+ ## 💻 Usage Example
61
+
62
+ ```javascript
63
+ import patternCollector from 'pattern-collector';
64
+
65
+ const code = `
66
+ import { exec } from "child_process";
67
+ import dotenv from 'dotenv';
68
+ import express from "express";
69
+
70
+ const PORT = 3000;
71
+ `;
72
+
73
+ // Extract all import statements
74
+ const imports = patternCollector({
75
+ fileContent: code,
76
+ searchString: /import\s+[\s\S]*?\s+from\s+['"][^'"]+['"]/g
77
+ });
78
+
79
+ console.log(imports);
80
+ /*
81
+ Output:
82
+ [
83
+ 'import { exec } from "child_process"',
84
+ "import dotenv from 'dotenv'",
85
+ 'import express from "express"'
86
+ ]
87
+ */
88
+ ```
89
+
90
+ ---
91
+
92
+ ## ⚖️ License
93
+
94
+ MIT License. Designed with ❤️ by [KeshavSoft](https://github.com/keshavsoft).
@@ -0,0 +1,13 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+
5
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
+
7
+ export default function getLatestVersion() {
8
+ const versions = fs.readdirSync(path.join(__dirname, ".."))
9
+ .filter(n => /^v\d+$/.test(n))
10
+ .sort((a, b) => parseInt(a.slice(1)) - parseInt(b.slice(1)));
11
+
12
+ return versions.at(-1);
13
+ };
@@ -0,0 +1,31 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+
4
+ import pullImportLines from "pattern-collector-routesjs-pull-lines";
5
+ import buildStory from "pattern-collector-routesjs-build-story";
6
+
7
+ const parseRegex = /import\s*\{[^}]*router\s+as\s+(\w+)[^}]*\}\s*from\s*['"]\.\/([^/]+)\/.*['"]/;
8
+
9
+ const startFunc = ({ inFilePath, inShowLog, showLogStep1, showLogStep2 }) => {
10
+ const filePath = path.join(inFilePath, "routes.js");
11
+
12
+ const fileContent = fs.readFileSync(filePath, 'utf8');
13
+
14
+ const { importLines, useLines } = pullImportLines({
15
+ fileContent,
16
+ parseRegex,
17
+ showLog: showLogStep1,
18
+ showLogStep1: showLogStep2
19
+ });
20
+
21
+ if (inShowLog) console.log("pullImportLines : ", importLines, useLines);
22
+
23
+ const story = buildStory({ importLines, useLines });
24
+
25
+ if (inShowLog) console.log("story : ", story);
26
+ // console.log("aaaaaaaa : ", JSON.stringify(story, null, 4));
27
+
28
+ return story;
29
+ };
30
+
31
+ export default startFunc;
@@ -0,0 +1,23 @@
1
+ import pullImportLines from "pattern-collector-routesjs-pull-lines";
2
+ import buildStory from "pattern-collector-routesjs-build-story";
3
+
4
+ const startFunc = ({ fileContent, parseRegex,
5
+ inShowLog, showLogStep1, showLogStep2 }) => {
6
+
7
+ const { importLines, useLines } = pullImportLines({
8
+ fileContent,
9
+ parseRegex,
10
+ showLog: showLogStep1,
11
+ showLogStep1: showLogStep2
12
+ });
13
+
14
+ if (inShowLog) console.log("pullImportLines : ", importLines, useLines);
15
+
16
+ const story = buildStory({ importLines, useLines });
17
+
18
+ if (inShowLog) console.log("story : ", story);
19
+
20
+ return story;
21
+ };
22
+
23
+ export default startFunc;
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import { createRequire } from "module";
2
+ import getLatestVersion from "./bin/core/getLatestVersion.js";
3
+
4
+ const require = createRequire(import.meta.url);
5
+
6
+ const v = getLatestVersion();
7
+ const latestModule = require(`./bin/${v}/index.js`);
8
+
9
+ const load = ({ fileContent, parseRegex,
10
+ inShowLog, showLogStep1, showLogStep2 }) => {
11
+
12
+ return latestModule.default({
13
+ fileContent, parseRegex,
14
+ inShowLog, showLogStep1, showLogStep2
15
+ });
16
+ };
17
+
18
+ export default load;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "pattern-collector-anyjs",
3
+ "version": "1.2.1",
4
+ "description": "A high-performance pattern collector and ESM import statement analyzer.",
5
+ "keywords": [
6
+ "pattern",
7
+ "regex",
8
+ "parser",
9
+ "import",
10
+ "analyzer",
11
+ "esm",
12
+ "extractor"
13
+ ],
14
+ "dependencies": {
15
+ "pattern-collector-routesjs-pull-lines": "^1.7.1",
16
+ "pattern-collector-routesjs-build-story": "^1.4.1"
17
+ },
18
+ "type": "module",
19
+ "exports": {
20
+ ".": "./index.js"
21
+ },
22
+ "files": [
23
+ "bin/",
24
+ "index.js",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "homepage": "https://github.com/keshavsoft/pattern-collector-anyjs#readme",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/keshavsoft/pattern-collector-anyjs"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/keshavsoft/pattern-collector-anyjs/issues"
35
+ }
36
+ }