Skip to content

Commit

Permalink
remove logic adjustments for a smaller release
Browse files Browse the repository at this point in the history
  • Loading branch information
gwyneplaine committed Apr 8, 2021
1 parent bbab0a3 commit ad72e94
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
35 changes: 1 addition & 34 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,43 +250,10 @@ export const upcase = (str: string) => str.substr(0, 1).toUpperCase() + str.subs
*/
export const humanize = (str: string) => {
let label = str
.replace(/([a-z])([A-Z]+)/g, '$1 $2 ')
.replace(/([a-z])([A-Z]+)/g, '$1 $2')
.split(/\s|_|\-/)
.filter(i => i)
.reduce((acc: string[], curr: string): string[] => {
// If this is the first item
// just push a new item in and return

if (acc.length === 0) {
acc.push(curr);
return acc;
}
// Otherwise, grab the last in the array item;
const lastItem = acc.pop() as string;
if (lastItem.length === 1 && lastItem.toUpperCase() === lastItem) {
// If its a single capitalised letter,
// Append it to the beginning of the currentValue
acc.push(lastItem + curr);
} else if (lastItem.length > 1 && lastItem.toUpperCase() === lastItem) {
// If its multiple capitalized letters,
// Split out the last character and append it to the beginning of the current value.
// Push both the truncated lastItem and the ammended current value into the array
const newLastItem = lastItem.substring(0, lastItem.length - 1);
const newCurrItem = `${lastItem.substring(lastItem.length - 1)}${curr}`;
acc.push(newLastItem, newCurrItem);
} else {
// Otherwise push both the lastItem and the current item into the array.
acc.push(lastItem, curr);
}
return acc;
}, [] as string[])
.map(upcase)
.map(i => {
if (i === 'Id') {
return i.toUpperCase();
}
return i;
})
.join(' ');

return label;
Expand Down
2 changes: 0 additions & 2 deletions packages/utils/tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ describe('utils', () => {
expect(humanize('someHTML')).toBe('Some HTML');
expect(humanize('snake_case')).toBe('Snake Case');
expect(humanize('kebab-case')).toBe('Kebab Case');
expect(humanize('someId')).toBe('Some ID');
expect(humanize('SomeHIDDENId')).toBe('Some HIDDEN ID');
expect(humanize('multiple words here')).toBe('Multiple Words Here');
expect(humanize('Multiple Words Here')).toBe('Multiple Words Here');
});
Expand Down

0 comments on commit ad72e94

Please sign in to comment.