+19
-5
@@ -5,10 +5,16 @@ #!/usr/bin/env node | ||
| var singleQuote = require('singlequote'); | ||
| var verbose = false; | ||
| var args = process.argv.splice(2).filter(function (param) { | ||
| return param === '-v' ? !(verbose = true) : true | ||
| }); | ||
| if (!process.argv[2]) { | ||
| console.log('USAGE: jsq fileOrDirectory [fileOrDirectory [fileOrDirectory [..]]]'); | ||
| if (!args.length) { | ||
| console.log('USAGE: jsq fileOrDirectory [fileOrDirectory [fileOrDirectory [..]]] [-v]'); | ||
| } else { | ||
| process.argv.splice(2).forEach(function (dirOrFile) { | ||
| var replaceCount = 0, skipCount = 0, fileCount = 0; | ||
| args.forEach(function (dirOrFile) { | ||
| var finder = findit(dirOrFile); | ||
| finder.on('file', function (file) { | ||
| if (/\.js$/.test(file)) { | ||
| fileCount++; | ||
| var code = fs.readFileSync(file, 'utf-8'); | ||
@@ -19,7 +25,9 @@ var codeWithSingleQuotes; | ||
| } catch (ex) { | ||
| console.log('Error parsing %s', file, ex); | ||
| skipCount++; | ||
| verbose && console.log('Skipping file because of error parsing file or bug in jsq %s', file, ex); | ||
| return; | ||
| } | ||
| if (code !== codeWithSingleQuotes) { | ||
| console.log('replacing double quoted strings with single quoted strings in %s', file); | ||
| replaceCount++; | ||
| verbose && console.log('Replacing double quoted strings with single quoted strings in %s', file); | ||
| fs.writeFileSync(file, codeWithSingleQuotes, 'utf-8'); | ||
@@ -29,3 +37,9 @@ } | ||
| }); | ||
| finder.on('end', function () { | ||
| console.log('%d .js files were scanned by jsq', fileCount); | ||
| skipCount && console.log('%s of those were skipped because of error parsing file or bug in jsq', skipCount, | ||
| verbose ? '' : '(use -v param to see details)'); | ||
| console.log('%s of those had double quoted JavaScript strings replaced', replaceCount || 'None'); | ||
| }); | ||
| }); | ||
| } |
+1
-1
| { | ||
| "name": "jsq", | ||
| "version": "0.0.3", | ||
| "version": "0.0.4", | ||
| "description": "Command line tool for repacing all double quoted strings with single quoted strings in a file or directory. Usage: jsq fileOrDirectory [fileOrDirectory [..]]", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+42
-1
@@ -13,3 +13,44 @@ jsq | ||
| ``` | ||
| jsq fileOrDirectory [fileOrDirectory [...]] | ||
| jsq fileOrDirectory [fileOrDirectory [...]] [-v] | ||
| ``` | ||
| `-v` will give you verbose output. | ||
| effect | ||
| ------ | ||
| A file containing the code: | ||
| ```js | ||
| var y = "hello"; | ||
| function x(){ | ||
| return "hello\" I am a string's for sure"; | ||
| } | ||
| ``` | ||
| Will contain this, after `jsq` is run on it: | ||
| ```js | ||
| var y = 'hello'; | ||
| function x(){ | ||
| return 'hello" I am a string\'s for sure'; | ||
| } | ||
| ``` | ||
| jsq prints errors when running it with `-v` parameter, should I worry? | ||
| ---------------------------------------------------------------------- | ||
| TLDR; No don't worry. Files are just skipped. | ||
| When in verbose mode `jsq` prints an error for one of two reasons: | ||
| - The JavaScript code is invalid and can not be parsed correctly: The file is skipped. | ||
| - There is a bug in `jsq` that would cause it to produce malformed JavaScript: The file is skipped. | ||
| So basically, `jsq` is just letting you know that some files are beeing skipped. | ||
| why create jsq? | ||
| --------------- | ||
| I created this tool because we where initially using both single quoted and double quoted strings in our JavaScript code | ||
| on a project. | ||
| Then we decided that our coding-standard should be single-quotes JavaSctipt strings, but the codebase was a mix. | ||
| With `jsq` I was able to clean up the entire project in a jiff. |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
12909
16.61%41
51.85%56
273.33%