Created
March 21, 2022 15:45
-
-
Save merlox/5e0c7d90829316f72e7d1cb8d3091905 to your computer and use it in GitHub Desktop.
Adds comments in the middle of the code. Reads from a "code.txt" file
This file contains hidden or 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
const fs = require('fs') | |
const { join } = require('path') | |
function getFirstGroup(regexp, str) { | |
return Array.from(str.matchAll(regexp), m => m[1]) | |
} | |
const file = fs.readFileSync(join(__dirname, 'code.txt'), 'utf-8') | |
const myRegex = /(.*)\n/g | |
let matches = file.matchAll(myRegex) | |
let finalFile = '' | |
let counter = 1 | |
let tabs = '' | |
let myMatches = [] | |
for (const match of matches) { | |
myMatches.push(match) | |
} | |
for (const match of myMatches) { | |
console.log(match[1]) | |
const tabs = getFirstGroup(/(\t+)/g, match[1]) | |
console.log(tabs + 'console.log(' + counter + ')') | |
counter++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment