diff --git a/lib/compile-exports.js b/lib/compile-exports.js index 5ce93e17..06904fac 100644 --- a/lib/compile-exports.js +++ b/lib/compile-exports.js @@ -1,5 +1,11 @@ var camelCase = require("lodash.camelcase"); +function dashesCamelCase(str) { + return str.replace(/-(\w)/g, function(match, firstLetter) { + return firstLetter.toUpperCase(); + }); +} + module.exports = function compileExports(result, importItemMatcher, camelCaseKeys) { if (!Object.keys(result.exports).length) { return ""; @@ -9,9 +15,13 @@ module.exports = function compileExports(result, importItemMatcher, camelCaseKey var valueAsString = JSON.stringify(result.exports[key]); valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher); res.push("\t" + JSON.stringify(key) + ": " + valueAsString); - if (camelCaseKeys) { + + if (camelCaseKeys === true) { res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString); + } else if (camelCaseKeys === 'dashes') { + res.push("\t" + JSON.stringify(dashesCamelCase(key)) + ": " + valueAsString); } + return res; }, []).join(",\n"); diff --git a/test/camelCaseTest.js b/test/camelCaseTest.js index 08bf76bb..86803005 100644 --- a/test/camelCaseTest.js +++ b/test/camelCaseTest.js @@ -3,17 +3,22 @@ var test = require("./helpers").test; describe("camelCase", function() { - var css = ".btn-info { color: blue; }"; + var css = ".btn-info_is-disabled { color: blue; }"; var exports = { with: [ - [1, ".Vh87YsUQA8A0EbntSqs6 { color: blue; }", ""] + [1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""] ], without: [ - [1, ".Vh87YsUQA8A0EbntSqs6 { color: blue; }", ""] + [1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""] + ], + dashes: [ + [1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""] ] }; - exports.with.locals = {'btn-info': 'Vh87YsUQA8A0EbntSqs6'}; - exports.without.locals = {btnInfo: 'Vh87YsUQA8A0EbntSqs6', 'btn-info': 'Vh87YsUQA8A0EbntSqs6'}; + exports.with.locals = {'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'}; + exports.without.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'}; + exports.dashes.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'}; test("with", css, exports.with, "?modules"); test("without", css, exports.without, "?modules&camelCase"); + test("dashes", css, exports.dashes, "?modules&camelCase=dashes"); });