-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
35 lines (31 loc) · 706 Bytes
/
util.js
File metadata and controls
35 lines (31 loc) · 706 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const R = require('ramda');
const createCamel = (acc, split) => {
let newAcc;
acc === ''
? newAcc = acc + split
: newAcc = acc + split.charAt(0).toUpperCase() + split.substring(1);
return newAcc;
};
const createNewCamelObj = (obj) => {
const newKeys = R.pipe(
R.map(
key => key.split(/[-_]+/),
),
R.map(
splitArr => R.reduce(
createCamel,
'',
splitArr,
),
),
)(Object.keys(obj));
const newObj = R.zipObj(newKeys, Object.values(obj));
return newObj;
};
const toCamel = R.curry((item) => {
if (R.is(Array, item)) return R.map(createNewCamelObj, item);
return createNewCamelObj(item);
});
module.exports = {
toCamel,
};