mirror of
https://github.com/nodejs/node.git
synced 2025-08-17 22:58:52 +02:00

PR-URL: https://github.com/nodejs/io.js/pull/2286 Reviewed-By: Roman Reiss <me@silverwind.io>
26 lines
652 B
JavaScript
26 lines
652 B
JavaScript
var deburr = require('../string/deburr'),
|
|
words = require('../string/words');
|
|
|
|
/**
|
|
* Creates a function that produces compound words out of the words in a
|
|
* given string.
|
|
*
|
|
* @private
|
|
* @param {Function} callback The function to combine each word.
|
|
* @returns {Function} Returns the new compounder function.
|
|
*/
|
|
function createCompounder(callback) {
|
|
return function(string) {
|
|
var index = -1,
|
|
array = words(deburr(string)),
|
|
length = array.length,
|
|
result = '';
|
|
|
|
while (++index < length) {
|
|
result = callback(result, array[index], index);
|
|
}
|
|
return result;
|
|
};
|
|
}
|
|
|
|
module.exports = createCompounder;
|