diff options
Diffstat (limited to 'scripts/style-code.js')
-rw-r--r-- | scripts/style-code.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/style-code.js b/scripts/style-code.js new file mode 100644 index 0000000000..156934a240 --- /dev/null +++ b/scripts/style-code.js @@ -0,0 +1,36 @@ +// Global functions // + +const fs = require('fs'); + +global.iff = function (condition, val) { + return condition() ? val : ""; +}; + +global.camelize = function (str) { + return str.replace(/(?:^|-)(.)/g, function (_, x) { + return x.toUpperCase(); + }); +}; + +global.camelizeWithLeadingLowercase = function (str) { + return str.replace(/-(.)/g, function (_, x) { + return x.toUpperCase(); + }); +}; + +global.snakeCaseUpper = function snakeCaseUpper(str) { + return str.replace(/-/g, "_").toUpperCase(); +}; + +global.writeIfModified = function(filename, newContent) { + try { + const oldContent = fs.readFileSync(filename, 'utf8'); + if (oldContent == newContent) { + console.warn(`* Skipping current file '${filename}'`); + return; + } + } catch(err) { + } + fs.writeFileSync(filename, newContent); + console.warn(`* Updating outdated file '${filename}'`); +}; |