Code coverage report for string/slugify.js

Statements: 100% (10 / 10)      Branches: 100% (2 / 2)      Functions: 100% (3 / 3)      Lines: 100% (9 / 9)     

All files » string/ » slugify.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 261                       1 19 6   19 19 19     19   1    
define(['./replaceAccents', './removeNonWord', './trim'], function(replaceAccents, removeNonWord, trim){
    /**
     * Convert to lower case, remove accents, remove non-word chars and
     * replace spaces with the specified delimeter.
     * Does not split camelCase text.
     * - ported from Miller Medeiros Eclipse Monkey Scripts
     * @example slugify('loremIpsum dolor spéçïãl chârs', '_') -> 'loremipsum_dolor_special_chars'
     * @param {string} str
     * @param {string} [delimeter="-"]
     * @return {string}
     * @version 0.2.0 (2012/08/17)
     */
    function slugify(str, delimeter){
        if (delimeter == null) {
            delimeter = "-";
        }
        str = replaceAccents(str);
        str = removeNonWord(str);
        str = trim(str) //should come after removeNonWord
                .replace(/ +/g, delimeter) //replace spaces with delimeter
                .toLowerCase();
        return str;
    }
    return slugify;
});