src/helper.js
function fitWidth(s, len)
{
    s = s.trim();
    if(s.length <= len) return [s];

    var result = [];
    while(s.length > len)
    {
        var i = len
        for(; s[i] != ' ' && i >= 0; i--) 
            /* empty loop */ ;

        if(i == -1)
        {
            for(i = len + 1; s[i] != ' ' && i < s.length; i++) 
                /* empty loop */ ;
            
            if(i == s.length)
            {
                result.push(s);
                return result;
            }
        }
        result.push(s.substr(0, i));
        s = s.substr(i).trimLeft();
    }
    result.push(s);
    return result;
}
function fitWidth(s, len)
{
    s = s.trim();
    if(s.length <= len) return [s];

    var result = [];
    while(s.length > len)
    {
        var i = len
        for(; s[i] != ' ' && i >= 0; i--) 
            /* empty loop */ ;

        if(i == -1)
        {
            for(i = len + 1; s[i] != ' ' && i < s.length; i++) 
                /* empty loop */ ;
            
            if(i == s.length)
            {
                result.push(s);
                return result;
            }
        }
        result.push(s.substr(0, i));
        s = s.substr(i).trimLeft();
    }
    result.push(s);
    return result;
}
function fitWidth ( s , len ) { s = s . trim ( ) ; if ( s . length <= len ) return [ s ] ; var result = [ ] ; while ( s . length > len ) { var i = len for ( ; s [ i ] != ' ' && i >= 0 ; i -- ) /* empty loop */ ; if ( i == - 1 ) { for ( i = len + 1 ; s [ i ] != ' ' && i < s . length ; i ++ ) /* empty loop */ ; if ( i == s . length ) { result . push ( s ) ; return result ; } } result . push ( s . substr ( 0 , i ) ) ; s = s . substr ( i ) . trimLeft ( ) ; } result . push ( s ) ; return result ; }
Break a string into lines of len characters and break on spaces
@param {String} s
@param {Number} len
@return {Array.<String>}
@remarks it might return longers lines if s contains words longer than len
Break a string into lines of len characters and break on spaces