How to convert a string to sentence case

This is a small script to make your string Sentence Case this also can easily be modified to use string to convert to CamelCase, PascalCase or Title Case.

 

const camelSentence = string =>
  string
    .toLowerCase()
    .trim()
    .split(/[.\-_\s]/g)
    .reduce(
      (str, word) =>
        `${str[0].toUpperCase()}${str.slice(
          1,
        )} ${word[0].toUpperCase()}${word.slice(1)}`,
    );