No Description

index.js 586B

123456789101112131415161718192021
  1. /*!
  2. * pascalcase <https://github.com/jonschlinkert/pascalcase>
  3. *
  4. * Copyright (c) 2015, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. function pascalcase(str) {
  8. if (typeof str !== 'string') {
  9. throw new TypeError('expected a string.');
  10. }
  11. str = str.replace(/([A-Z])/g, ' $1');
  12. if (str.length === 1) { return str.toUpperCase(); }
  13. str = str.replace(/^[\W_]+|[\W_]+$/g, '').toLowerCase();
  14. str = str.charAt(0).toUpperCase() + str.slice(1);
  15. return str.replace(/[\W_]+(\w|$)/g, function (_, ch) {
  16. return ch.toUpperCase();
  17. });
  18. }
  19. module.exports = pascalcase;