Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to convert string to pascal case in javascript

const pascalCase = (string) => {
  function toPascalCase(string) {
    return `${string}`
      .replace(new RegExp(/[-_]+/, "g"), " ")
      .replace(new RegExp(/[^ws]/, "g"), "")
      .replace(
        new RegExp(/s+(.)(w*)/, "g"),
        ($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`
      )
      .replace(new RegExp(/w/), (s) => s.toUpperCase());
  }
  const newText = toPascalCase(string);
  
  return newText
};
Source by www.textbotonline.com #
 
PREVIOUS NEXT
Tagged: #convert #string #pascal #case #javascript
ADD COMMENT
Topic
Name
1+3 =