Skip to content

Commit 45764ca

Browse files
committed
Merge pull request webpack-contrib#170 from faergeek/camelcase-options
Extend camelcase option to support 'dashes' value
2 parents 87d6eaf + 5f2d28e commit 45764ca

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

lib/compile-exports.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
var camelCase = require("lodash.camelcase");
22

3+
function dashesCamelCase(str) {
4+
return str.replace(/-(\w)/g, function(match, firstLetter) {
5+
return firstLetter.toUpperCase();
6+
});
7+
}
8+
39
module.exports = function compileExports(result, importItemMatcher, camelCaseKeys) {
410
if (!Object.keys(result.exports).length) {
511
return "";
@@ -9,9 +15,13 @@ module.exports = function compileExports(result, importItemMatcher, camelCaseKey
915
var valueAsString = JSON.stringify(result.exports[key]);
1016
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher);
1117
res.push("\t" + JSON.stringify(key) + ": " + valueAsString);
12-
if (camelCaseKeys) {
18+
19+
if (camelCaseKeys === true) {
1320
res.push("\t" + JSON.stringify(camelCase(key)) + ": " + valueAsString);
21+
} else if (camelCaseKeys === 'dashes') {
22+
res.push("\t" + JSON.stringify(dashesCamelCase(key)) + ": " + valueAsString);
1423
}
24+
1525
return res;
1626
}, []).join(",\n");
1727

test/camelCaseTest.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
var test = require("./helpers").test;
44

55
describe("camelCase", function() {
6-
var css = ".btn-info { color: blue; }";
6+
var css = ".btn-info_is-disabled { color: blue; }";
77
var exports = {
88
with: [
9-
[1, ".Vh87YsUQA8A0EbntSqs6 { color: blue; }", ""]
9+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
1010
],
1111
without: [
12-
[1, ".Vh87YsUQA8A0EbntSqs6 { color: blue; }", ""]
12+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
13+
],
14+
dashes: [
15+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
1316
]
1417
};
15-
exports.with.locals = {'btn-info': 'Vh87YsUQA8A0EbntSqs6'};
16-
exports.without.locals = {btnInfo: 'Vh87YsUQA8A0EbntSqs6', 'btn-info': 'Vh87YsUQA8A0EbntSqs6'};
18+
exports.with.locals = {'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
19+
exports.without.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
20+
exports.dashes.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
1721
test("with", css, exports.with, "?modules");
1822
test("without", css, exports.without, "?modules&camelCase");
23+
test("dashes", css, exports.dashes, "?modules&camelCase=dashes");
1924
});

0 commit comments

Comments
 (0)