Thursday, February 28, 2019

How do I turn Pascal Case into Title Case in TypeScript?

I think there is a way to do that with lodash, as this suggests...

_.startCase('helloThere');

 
 

If you want roll something yourself you can do something like this however my invention can't really account for characters that are not letters. If you want to account for characters that are not letters you would have to check to see if .toUpperCase() and .toLowerCase() off of a character matched up I suppose. My stuff also does not play nice with one letter words like I or A. Anyhow, this will turn this:

export enum Role {
   Administrator,
   ComplianceGroup,
   BusinessUnitSME,
   BUAggregator,
   ReadOnlyAuditor
}

 
 

...into this:

  1. Administrator
  2. Compliance Group
  3. Business Unit SME
  4. BU Aggregator
  5. Read Only Auditor

No comments:

Post a Comment