_createCompounder.js 635 B

123456789101112131415161718192021222324
  1. var arrayReduce = require('./_arrayReduce'),
  2. deburr = require('./deburr'),
  3. words = require('./words');
  4. /** Used to compose unicode capture groups. */
  5. var rsApos = "['\u2019]";
  6. /** Used to match apostrophes. */
  7. var reApos = RegExp(rsApos, 'g');
  8. /**
  9. * Creates a function like `_.camelCase`.
  10. *
  11. * @private
  12. * @param {Function} callback The function to combine each word.
  13. * @returns {Function} Returns the new compounder function.
  14. */
  15. function createCompounder(callback) {
  16. return function(string) {
  17. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  18. };
  19. }
  20. module.exports = createCompounder;