Skip to content

Commit f6aeca5

Browse files
committed
feat: allow removal of original class name
1 parent 476a927 commit f6aeca5

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ By default, the exported JSON keys mirror the class names. If you want to cameli
394394
import { className } from 'file.css';
395395
```
396396

397+
#### Possible options
398+
399+
|Option|Behaviour|
400+
|:----:|:--------|
401+
|**`true`**|Class names will be camelized|
402+
|**`'dashes'`**|Only dashes in class names will be camelized|
403+
|**`'only'`** |Class names will be camelized, the original class name will be removed from the locals|
404+
|**`'dashesOnly'`**|Dashes in class names will be camelized, the original class name will be removed from the locals|
405+
397406
<h2 align="center">Maintainers</h2>
398407

399408
<table>

lib/compile-exports.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ module.exports = function compileExports(result, importItemMatcher, camelCaseKey
1717
function addEntry(k) {
1818
res.push("\t" + JSON.stringify(k) + ": " + valueAsString);
1919
}
20-
addEntry(key);
20+
if (camelCaseKeys !== 'only' && camelCaseKeys !== 'dashesOnly') {
21+
addEntry(key);
22+
}
2123

2224
var targetKey;
23-
if (camelCaseKeys === true) {
25+
if (camelCaseKeys === true || camelCaseKeys === 'only') {
2426
targetKey = camelCase(key);
2527
if (targetKey !== key) {
2628
addEntry(targetKey);
2729
}
28-
} else if (camelCaseKeys === 'dashes') {
30+
} else if (camelCaseKeys === 'dashes' || camelCaseKeys === 'dashesOnly') {
2931
targetKey = dashesCamelCase(key);
3032
if (targetKey !== key) {
3133
addEntry(targetKey);

test/camelCaseTest.js

+10
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ describe("camelCase", function() {
1414
],
1515
dashes: [
1616
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
17+
],
18+
withoutOnly: [
19+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
20+
],
21+
dashesOnly: [
22+
[1, "._1L-rnCOXCE_7H94L5XT4uB { color: blue; }", ""]
1723
]
1824
};
1925
exports.with.locals = {'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
2026
exports.without.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
2127
exports.dashes.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB', 'btn-info_is-disabled': '_1L-rnCOXCE_7H94L5XT4uB'};
28+
exports.withoutOnly.locals = {btnInfoIsDisabled: '_1L-rnCOXCE_7H94L5XT4uB'};
29+
exports.dashesOnly.locals = {btnInfo_isDisabled: '_1L-rnCOXCE_7H94L5XT4uB'};
2230
test("with", css, exports.with, "?modules");
2331
test("without", css, exports.without, "?modules&camelCase");
2432
test("dashes", css, exports.dashes, "?modules&camelCase=dashes");
33+
test("withoutOnly", css, exports.withoutOnly, "?modules&camelCase=only");
34+
test("dashesOnly", css, exports.dashesOnly, "?modules&camelCase=dashesOnly");
2535

2636
testRaw("withoutRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase");
2737
testRaw("dashesRaw", '.a {}', 'exports.locals = {\n\t"a": "_1buUQJccBRS2-2i27LCoDf"\n};', "?modules&camelCase=dashes");

0 commit comments

Comments
 (0)