Code coverage report for string/truncate.js

Statements: 91.67% (11 / 12)      Branches: 87.5% (7 / 8)      Functions: 100% (3 / 3)      Lines: 90.91% (10 / 11)     

All files » string/ » truncate.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 211         1 11 11   11 11     11   11 11   1    
define(['./trim'], function(trim){
    /**
    * Limit number of chars.
    * @version 0.3.0 (2011/10/31)
    */
    function truncate(str, maxChars, append, onlyFullWords){
        append = append || '...';
        maxChars = onlyFullWords? maxChars + 1 : maxChars;
 
        str = trim(str);
        Iif(str.length <= maxChars){
            return str;
        }
        str = str.substr(0, maxChars - append.length);
        //crop at last space or remove trailing whitespace
        str = onlyFullWords? str.substr(0, str.lastIndexOf(' ')) : trim(str);
        return str + append;
    }
    return truncate;
});