Skip to content

Commit 05089ab

Browse files
committed
Introduce option adding camelize keys to token
1 parent 1451a2d commit 05089ab

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

lib/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const genericNames = require('generic-names');
55
const globToRegex = require('glob-to-regexp');
66
const identity = require('lodash').identity;
77
const negate = require('lodash').negate;
8+
const camelCaseFunc = require('lodash').camelCase;
89
const readFileSync = require('fs').readFileSync;
910
const relative = require('path').relative;
1011
const resolve = require('path').resolve;
@@ -27,6 +28,7 @@ module.exports = function setupHook({
2728
preprocessCss = identity,
2829
processCss,
2930
processorOpts,
31+
camelCase,
3032
append = [],
3133
prepend = [],
3234
createImportedName,
@@ -103,6 +105,11 @@ module.exports = function setupHook({
103105

104106
tokens = lazyResult.root.tokens;
105107

108+
if (camelCase) {
109+
tokens = Object.assign({}, tokens,
110+
...Object.keys(tokens).map(key => ({ [camelCaseFunc(key)]: tokens[key] })))
111+
}
112+
106113
if (!debugMode) {
107114
// updating cache
108115
tokensByFile[filename] = tokens;

lib/validate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const rules = {
1010
preprocessCss: 'function',
1111
processCss: 'function',
1212
processorOpts: 'object',
13+
camelCase: 'boolean',
1314
// plugins
1415
append: 'array',
1516
prepend: 'array',

test/api/camelCase.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const detachHook = require('../sugar').detachHook;
2+
const dropCache = require('../sugar').dropCache;
3+
const identity = require('lodash').lodash;
4+
5+
suite('api/camelCase', () => {
6+
test('should add camel case keys in token', () => {
7+
const tokens = require('./fixture/bem.css');
8+
assert.deepEqual(tokens, {
9+
blockElementModifier: '_test_api_fixture_bem__block__element--modifier',
10+
'block__element--modifier': '_test_api_fixture_bem__block__element--modifier',
11+
});
12+
});
13+
14+
setup(() => hook({ camelCase: true }));
15+
16+
teardown(() => {
17+
detachHook('.css');
18+
dropCache('./api/fixture/bem.css');
19+
});
20+
});

test/api/fixture/bem.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.block__element--modifier {
2+
background: #1e2a35;
3+
}

0 commit comments

Comments
 (0)