find-primordials 1.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## 1.0.0
9
+
10
+ ### Commits
11
+
12
+ - Initial implementation of find-primordials monorepo [`565e4ac`](https://github.com/ljharb/find-primordials/commit/565e4ac4bc99d16d65559fc9d901c1ebabfc62b9)
13
+ - [lib] [deps] update `minimatch` [`22dd390`](https://github.com/ljharb/find-primordials/commit/22dd390f5a960c616e907aba02388d461374fa0a)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jordan Harband
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 whom the Software is
10
+ furnished to do so, subject to the 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,178 @@
1
+ # find-primordials <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
+
3
+ [![github actions][actions-image]][actions-url]
4
+ [![License][license-image]][license-url]
5
+ [![Downloads][downloads-image]][downloads-url]
6
+
7
+ [![npm badge][npm-badge-png]][package-url]
8
+
9
+ Core library for finding primordials in use in JavaScript/TypeScript files.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install find-primordials
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Analyzing a Single File
20
+
21
+ ```js
22
+ import { analyzeFile } from 'find-primordials';
23
+
24
+ const result = await analyzeFile('./src/index.js', {
25
+ includeGlobals: true, // Include global primordial usage (Array, Object, etc.)
26
+ includeStatic: true, // Include static method usage (Object.keys, Array.isArray)
27
+ includeSpread: true, // Include spread syntax (...arr, {...obj})
28
+ includeUncertain: true, // Include findings where type cannot be determined
29
+ });
30
+
31
+ console.log(result.findings);
32
+ // [
33
+ // { type: 'instanceMethod', name: 'push', category: 'Array', ... },
34
+ // { type: 'staticMethod', name: 'keys', category: 'Object', ... },
35
+ // ]
36
+ ```
37
+
38
+ ### Analyzing Multiple Files
39
+
40
+ ```js
41
+ import { analyzeFiles, analyzeFilesParallel } from 'find-primordials';
42
+
43
+ // Sequential analysis
44
+ const result = await analyzeFiles(['./src/a.js', './src/b.js'], options);
45
+
46
+ // Parallel analysis (recommended for many files)
47
+ const result = await analyzeFilesParallel(['./src/a.js', './src/b.js'], options);
48
+
49
+ console.log(result.findings);
50
+ console.log(result.errors);
51
+ ```
52
+
53
+ ### Accessing Primordials Data
54
+
55
+ ```js
56
+ import { primordials, allGlobals, allInstanceMethods, allStaticMethods } from 'find-primordials/primordials';
57
+
58
+ // All tracked primordial categories
59
+ console.log(Object.keys(primordials));
60
+ // ['Array', 'Object', 'String', 'Number', 'Boolean', 'Symbol', 'BigInt', ...]
61
+
62
+ // All global constructor names
63
+ console.log([...allGlobals]);
64
+ // ['Array', 'Object', 'String', 'Map', 'Set', ...]
65
+
66
+ // All instance methods and which types they belong to
67
+ console.log(allInstanceMethods.get('push'));
68
+ // Set { 'Array' }
69
+
70
+ console.log(allInstanceMethods.get('slice'));
71
+ // Set { 'Array', 'String', 'ArrayBuffer' }
72
+ ```
73
+
74
+ ### Formatting Output
75
+
76
+ ```js
77
+ import { formatAsTAP, formatFindingAsTAP, groupByCategory } from 'find-primordials';
78
+
79
+ // Format all findings as TAP
80
+ const tap = formatAsTAP(result.findings);
81
+ console.log(tap);
82
+
83
+ // Group findings by category
84
+ const grouped = groupByCategory(result.findings);
85
+ // { Array: [...], Object: [...], String: [...] }
86
+ ```
87
+
88
+ ### Ignore Configuration
89
+
90
+ ```js
91
+ import { normalizeIgnoreConfig, filterFindings, shouldIgnoreFile, shouldIgnoreFinding } from 'find-primordials';
92
+
93
+ const ignoreConfig = normalizeIgnoreConfig({
94
+ files: ['vendor/**'],
95
+ types: ['spread', 'global'],
96
+ categories: ['RegExp'],
97
+ names: ['test', 'exec'],
98
+ rules: [
99
+ { files: ['src/*.js'], types: ['instanceMethod'] },
100
+ ],
101
+ });
102
+
103
+ // Check if file should be skipped entirely
104
+ if (!shouldIgnoreFile(filePath, ignoreConfig)) {
105
+ // Analyze and filter findings
106
+ const filtered = filterFindings(findings, ignoreConfig);
107
+ }
108
+ ```
109
+
110
+ ## API
111
+
112
+ ### `analyzeFile(filePath, options)`
113
+
114
+ Analyzes a single file and returns findings.
115
+
116
+ **Options:**
117
+ - `includeGlobals` - Include global primordial usage (default: `false`)
118
+ - `includeStatic` - Include static method usage (default: `false`)
119
+ - `includeSpread` - Include spread syntax usage (default: `false`)
120
+ - `includeUncertain` - Include uncertain findings (default: `true`)
121
+ - `isSafeFile` - Function to determine if file is "safe" (default: checks for bin/test files)
122
+
123
+ ### `analyzeFiles(files, options)`
124
+
125
+ Analyzes multiple files sequentially.
126
+
127
+ ### `analyzeFilesParallel(files, options)`
128
+
129
+ Analyzes multiple files in parallel using worker threads.
130
+
131
+ ### `applyFixes(filePath, findings)`
132
+
133
+ Rewrites the findings that have a primordial-free equivalent, and returns `{ fixed, output, fixCount, fixCounts }` without writing to disk.
134
+ Only the findings passed in are fixed, so filtering them first is how you control what gets rewritten.
135
+
136
+ ```js
137
+ import { analyzeFiles, applyFixes } from 'find-primordials';
138
+ import fs from 'fs';
139
+
140
+ const { findings } = analyzeFiles(['./src/index.js'], { includeGlobals: true });
141
+ const result = applyFixes('./src/index.js', findings);
142
+ if (result.fixed) {
143
+ fs.writeFileSync('./src/index.js', result.output);
144
+ }
145
+ ```
146
+
147
+ `fixCounts` breaks the total down by kind: `at`, `constructor`, `isNaN`,
148
+ `push`, and `undefined`.
149
+
150
+ A fix is only applied where the result is equivalent, so a rewrite that would name an operand twice is skipped when that operand is a call, which would then run twice.
151
+
152
+ Property accesses are read through freely: `Number.isNaN(o.v)` becomes `(o.v !== o.v)`, reaching `v` twice where the original reached it once.
153
+ That is equivalent for a getter that behaves like a property - same value each read, no side effects - and not for one that returns something new per read or counts its reads.
154
+ Getters like that are deliberately not accounted for.
155
+
156
+ Each call is a single pass, and a fix can hide another one nested inside it, so re-analyze the output and call again until nothing changes.
157
+
158
+ ### `applyPushFixes(filePath, findings)` / `applyUndefinedFixes(filePath, findings)`
159
+
160
+ Like `applyFixes`, but limited to the `push` and `undefined` rewrites respectively.
161
+
162
+ ### Finding Types
163
+
164
+ - `instanceMethod` - Instance method calls like `arr.push()`
165
+ - `staticMethod` - Static method calls like `Object.keys()`
166
+ - `global` - Global constructor usage like `new Array()`
167
+ - `spread` - Spread syntax usage
168
+ - `prototypeAccess` - Direct prototype access like `Array.prototype.push`
169
+
170
+ [package-url]: https://npmjs.org/package/find-primordials
171
+ [npm-version-svg]: https://versionbadg.es/ljharb/find-primordials.svg
172
+ [npm-badge-png]: https://nodei.co/npm/find-primordials.png?downloads=true&stars=true
173
+ [license-image]: https://img.shields.io/npm/l/find-primordials.svg
174
+ [license-url]: LICENSE
175
+ [downloads-image]: https://img.shields.io/npm/dm/find-primordials.svg
176
+ [downloads-url]: https://npm-stat.com/charts.html?package=find-primordials
177
+ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/find-primordials
178
+ [actions-url]: https://github.com/ljharb/find-primordials/actions