-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
214 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,5 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules/* | ||
|
||
# added automatically by precommit-hook as defaults | ||
.jshint* | ||
.DS_Store | ||
.npm | ||
node_modules | ||
npm-debug.log* | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- "4.3" | ||
- "4" | ||
- "6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @param {function} compile | ||
* @param {string} extension | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
|
||
const {assign, camelCase, reduce} = require('lodash'); | ||
|
||
const camelizeKeys = (acc, value, key) => { | ||
const camelizedKey = camelCase(key); | ||
if (camelizedKey !== key) acc[camelizedKey] = value; | ||
return acc; | ||
}; | ||
|
||
const camelizeDashedKeys = (acc, value, key) => { | ||
const camelizedKey = camelizeDashes(key); | ||
if (camelizedKey !== key) acc[camelizedKey] = value; | ||
return acc; | ||
}; | ||
|
||
const camelizeOnlyKeys = (acc, value, key) => { | ||
const camelizedKey = camelCase(key); | ||
if (camelizedKey !== key) acc[camelizedKey] = value | ||
else acc[key] = value; | ||
return acc; | ||
}; | ||
|
||
const camelizeOnlyDashedKeys = (acc, value, key) => { | ||
const camelizedKey = camelizeDashes(key); | ||
if (camelizedKey !== key) acc[camelizedKey] = value | ||
else acc[key] = value; | ||
return acc; | ||
}; | ||
|
||
exports.camelizeDashes = camelizeDashes; | ||
exports.transformTokens = transformTokens; | ||
|
||
/** | ||
* @param {string} str | ||
* @return {string} | ||
*/ | ||
function camelizeDashes(str) { | ||
return str.replace(/-(\w)/g, (m, letter) => letter.toUpperCase()); | ||
} | ||
|
||
/** | ||
* @param {object} tokens | ||
* @param {boolean|string} camelCase 'dashes|dashesOnly|only' | ||
* @return {object} | ||
*/ | ||
function transformTokens(tokens, camelCase) { | ||
switch (camelCase) { | ||
case true: | ||
return reduce(tokens, camelizeKeys, assign({}, tokens)); | ||
|
||
case 'dashes': | ||
return reduce(tokens, camelizeDashedKeys, assign({}, tokens)); | ||
|
||
case 'dashesOnly': | ||
return reduce(tokens, camelizeOnlyDashedKeys, {}); | ||
|
||
case 'only': | ||
return reduce(tokens, camelizeOnlyKeys, {}); | ||
} | ||
|
||
return tokens; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
|
||
const {camelizeDashes, transformTokens} = require('../../lib/transformTokens'); | ||
|
||
suite('lib/transformTokens', () => { | ||
test('camelizeDashes', () => { | ||
assert.equal(camelizeDashes(''), ''); | ||
assert.equal(camelizeDashes('a-a'), 'aA'); | ||
assert.equal(camelizeDashes('a-a-b'), 'aAB'); | ||
assert.equal(camelizeDashes('a-'), 'a-'); | ||
}); | ||
|
||
suite('transformTokens', () => { | ||
test('`true -> should transform all the keys to CC, keeps original keys', () => { | ||
assert.deepEqual(transformTokens({ | ||
'k-e-bab': 'kebab case', | ||
's_na_ke': 'snake case', | ||
'simple': 'aaa', | ||
}, true), { | ||
'k-e-bab': 'kebab case', | ||
's_na_ke': 'snake case', | ||
'simple': 'aaa', | ||
'kEBab': 'kebab case', | ||
'sNaKe': 'snake case', | ||
}); | ||
}); | ||
|
||
test('`dashes` -> should transform the keys with dashed, keeps original keys', () => { | ||
assert.deepEqual(transformTokens({ | ||
'k-e-bab': 'kebab case', | ||
's_na_ke': 'snake case', | ||
'simple': 'aaa', | ||
}, 'dashes'), { | ||
'k-e-bab': 'kebab case', | ||
's_na_ke': 'snake case', | ||
'simple': 'aaa', | ||
'kEBab': 'kebab case', | ||
}); | ||
}); | ||
|
||
test('`dashesOnly` -> should transform only keys with dashes', () => { | ||
assert.deepEqual(transformTokens({ | ||
'k-e-bab': 'kebab case', | ||
's_na_ke': 'snake case', | ||
'simple': 'aaa', | ||
}, 'dashesOnly'), { | ||
's_na_ke': 'snake case', | ||
'simple': 'aaa', | ||
'kEBab': 'kebab case', | ||
}); | ||
}); | ||
|
||
test('`only` -> should camelize keys', () => { | ||
assert.deepEqual(transformTokens({ | ||
'k-e-bab': 'kebab case', | ||
's_na_ke': 'snake case', | ||
'simple': 'aaa', | ||
}, 'only'), { | ||
'simple': 'aaa', | ||
'kEBab': 'kebab case', | ||
'sNaKe': 'snake case', | ||
}); | ||
}); | ||
}); | ||
}); |