-
Notifications
You must be signed in to change notification settings - Fork 0
/
camelize.ts
20 lines (20 loc) · 857 Bytes
/
camelize.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export function camelize(strToCamelize: string){
const statements = strToCamelize.split('.');
const objToMerge: {[key: string]: string[]} = {};
for(const statement of statements){
const trimmedStatement = statement.trim();
if(trimmedStatement.length === 0) continue;
if(trimmedStatement.startsWith('//')) continue;
const normalizedStatement = trimmedStatement.replace(/\s+/g, ' ');
const splitStatement = normalizedStatement.split(' ');
const head = splitStatement[0];
let bucket = objToMerge[head];
if(bucket === undefined){
bucket = [];
objToMerge[head] = bucket;
}
const tail = splitStatement.slice(1).map((s, idx) => idx === 0 ? s : s[0].toUpperCase() + s.substring(1)).join('');
bucket.push(tail);
}
return objToMerge;
}