Front end of the Slack clone application.

index.js 323B

1234567891011121314
  1. 'use strict';
  2. module.exports = function (str, sep) {
  3. if (typeof str !== 'string') {
  4. throw new TypeError('Expected a string');
  5. }
  6. sep = typeof sep === 'undefined' ? '_' : sep;
  7. return str
  8. .replace(/([a-z\d])([A-Z])/g, '$1' + sep + '$2')
  9. .replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + sep + '$2')
  10. .toLowerCase();
  11. };