-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- takes a path, regex, and regex flags and returns the captured group - probably needs some refinement - add an example changelog entry
- Loading branch information
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"use strict"; | ||
const { readFileSync } = require("fs"); | ||
const { resolve } = require("path"); | ||
|
||
// get the args | ||
const [path, regex, flags] = process.argv.slice(2); | ||
// throw if necessary args are missing | ||
if (!path) { | ||
throw new Error("Please provide a path to the file to parse"); | ||
} | ||
if (!regex) { | ||
throw new Error("Please provide a regex to parse the file"); | ||
} | ||
|
||
const filePath = resolve(__dirname,'..', path); | ||
const fileContent = fs.readFileSync(filePath, "utf8"); | ||
const rx = new RegExp(regex, flags); | ||
Check failure Code scanning / CodeQL Regular expression injection High
This regular expression is constructed from a
command-line argument Error loading related location Loading |
||
const matches = fileContent.matchAll(rx); | ||
|
||
console.log([...matches][0][1].trim()); |