toCamelCase function to
includes an optional boolean parameter to output PascalCase instead of CamelCase.
This "pollutes" the
String prototype which may or may not be an issue for you. It will not, however, overwrite
String.prototype.toCamelCase if it is already defined.
If performance is an issue and you're running this over millions of strings, there are probably faster modules out there. This one uses three Regex passes over the string. For the majority of cases, however, this is not an issue.
npm install @dfoverdx/tocamelcase
/dist/index.min.jsfrom this repository and name it something like
Place it somewhere your webpage can access (e.g.
Add it to your HTML file<!-- ... --><!-- scripts that use .toCamelCase() -->
;console; // outputs: 'thisIsCamelCase'console; // outputs 'ThisIsPascalCase'
import '@dfoverdx/tocamelcase';console.log('This is camel-case'.toCamelCase()); // outputs: 'thisIsCamelCase'console.log('This is pascal-case'.toCamelCase(true)); // outputs 'ThisIsPascalCase'