sentenceCase.js 485 B

123456789101112131415
  1. var toString = require('../lang/toString');
  2. var lowerCase = require('./lowerCase');
  3. var upperCase = require('./upperCase');
  4. /**
  5. * UPPERCASE first char of each sentence and lowercase other chars.
  6. */
  7. function sentenceCase(str){
  8. str = toString(str);
  9. // Replace first char of each sentence (new line or after '.\s+') to
  10. // UPPERCASE
  11. return lowerCase(str).replace(/(^\w)|\.\s+(\w)/gm, upperCase);
  12. }
  13. module.exports = sentenceCase;