Created
August 10, 2018 12:17
-
-
Save bitdivine/27a313cea5fdd26ea5464d25fe7cb379 to your computer and use it in GitHub Desktop.
Strip comments from JSON
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
| #!/usr/bin/env node | |
| const RECIPE = process.argv[2] || process.env.RECIPE || '/dev/stdin' | |
| const doubleslash=/^(("([^"\\]|\\.)*"|([^\/]|\/[^\/]))*).*/gm | |
| const multiline=/(("([^"\\]|\\.)*"|[^\/"]|\/[^*])*)\/[*]([^*]|[*][^\/])*[*]\//g | |
| var x,y; | |
| for ([x,y]=[require("fs").readFileSync(RECIPE,{encoding:"utf8"}).replace(doubleslash,"$1"), ""]; x.length != y.length; [x,y]=[x.replace(multiline,"$1"),x] ); | |
| console.log(JSON.stringify(JSON.parse(x), null, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment