Created
April 15, 2022 19:46
-
-
Save Janiczek/7400910d3425abcf0414d78cf41b0361 to your computer and use it in GitHub Desktop.
elm-make-readable
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
import fs from 'fs/promises'; | |
const rules = [ | |
{ | |
rule: /var ([^=]+)( = F\d\([^f]+function)[^(]\(/gmi, | |
replacement: `var $1$2 __$1( `, | |
}, | |
{ | |
rule: /(\sA\d\([\s]+)([^,]+)(,[\s]+)(function[^(]+)\(/gm, | |
replacement: `$1$2$3$4___$2(`, | |
}, | |
]; | |
const inputPath = process.argv[2]; | |
const outputPath = process.argv[3]; | |
const inputContents = await fs.readFile(inputPath, 'utf8'); | |
const outputContents = rules.reduce( | |
(currentString, {rule, replacement}) => currentString.replace(rule, replacement), | |
inputContents | |
); | |
await fs.writeFile(outputPath, outputContents); |
As @lydell observed, this might produce syntax errors and is best replaced by
.replace(/var ([^=]+)( = F\d\([^f]+function)[^(]\(/gim, `var $1$2 __$1( `)
.replace(
/(\sA\d\([\s]+)([^,]+)(,[\s]+)(function[^(]+)\(/gm,
(_, $1, $2, $3, $4) =>
`${$1}${$2}${$3}${$4}___${$2.replace(/\./g, "_")}(`,
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quoting Janiczek from Slack: you use this with:
node ./elm-make-readable.mjs in.js out.js