Created
June 19, 2012 15:45
-
-
Save domenic/2954904 to your computer and use it in GitHub Desktop.
Adding BOM
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
var fs = require("fs"); | |
var path = require("path"); | |
var wrench = require("wrench"); | |
var BOM_CHAR_CODE = 65279; | |
var BOM = String.fromCharCode(BOM_CHAR_CODE); | |
var fileNames = wrench.readdirSyncRecursive(process.cwd()).filter(function (fileName) { | |
return path.extname(fileName) === ".js"; | |
}); | |
fileNames.forEach(function (fileName) { | |
fs.readFile(fileName, "utf8", function (err, fileContents) { | |
if (err) { throw err; } | |
if (fileContents.charCodeAt(0) !== BOM_CHAR_CODE) { | |
fs.writeFile(fileName, BOM + fileContents, "utf8", function (err) { | |
if (err) { throw err; } | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment