Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Prepend all JavaScript files with "use strict"; that don't have it yet
// To run:
// npm install globby
// node prepend-use-strict.js
var globby = require('globby');
var fs = require('fs');
globby('**/*.js', function(err, files) {
for (var i = 0, m = files.length; i < m; i++) {
var fileContent = fs.readFileSync(files[i]).toString();
if (!fileContent.match("use strict")) {
fileContent = "\"use strict\";\n\n" + fileContent;
fs.writeFileSync(files[i], fileContent);
}
}
});
@KamuelaFranco

This comment has been minimized.

Copy link

KamuelaFranco commented May 10, 2016

Add this to NPM!

@davidharting

This comment has been minimized.

Copy link

davidharting commented Feb 20, 2019

You're a lifesaver, thank you for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.