dist/truncate.es.js
function substr(astralSafeCharacterArray, len) {
        // var boundary, cutted, result
        var cutted = astralSafeCharacterArray.slice(0, len).join('');
        if (!this.reserveLastWord) {
            return cutted;
        }
        var boundary = astralSafeCharacterArray.slice(len - 1, len + 1).join('');
        // if truncate at word boundary, just return
        if (/\W/.test(boundary)) {
            return cutted;
        }
        if (this.reserveLastWord < 0) {
            var result = cutted.replace(/\w+$/, '');
            // if the cutted is not the first and the only word
            //   then return result, or return the whole word
            if (!(result.length === 0 && cutted.length === this.options.length)) {
                return result;
            }
        }
        // set max exceeded to 10 if this.reserveLastWord is true or > 0
        var maxExceeded = this.reserveLastWord !== true && this.reserveLastWord > 0
            ? this.reserveLastWord
            : 10;
        var mtc = astralSafeCharacterArray.slice(len).join('').match(/(\w+)/);
        var exceeded = mtc ? mtc[1] : '';
        return cutted + exceeded.substr(0, maxExceeded);
    }
function substr(astralSafeCharacterArray, len) {
        // var boundary, cutted, result
        var cutted = astralSafeCharacterArray.slice(0, len).join('');
        if (!this.reserveLastWord) {
            return cutted;
        }
        var boundary = astralSafeCharacterArray.slice(len - 1, len + 1).join('');
        // if truncate at word boundary, just return
        if (/\W/.test(boundary)) {
            return cutted;
        }
        if (this.reserveLastWord < 0) {
            var result = cutted.replace(/\w+$/, '');
            // if the cutted is not the first and the only word
            //   then return result, or return the whole word
            if (!(result.length === 0 && cutted.length === this.options.length)) {
                return result;
            }
        }
        // set max exceeded to 10 if this.reserveLastWord is true or > 0
        var maxExceeded = this.reserveLastWord !== true && this.reserveLastWord > 0
            ? this.reserveLastWord
            : 10;
        var mtc = astralSafeCharacterArray.slice(len).join('').match(/(\w+)/);
        var exceeded = mtc ? mtc[1] : '';
        return cutted + exceeded.substr(0, maxExceeded);
    }
function substr ( astralSafeCharacterArray , len ) { // var boundary, cutted, result
 var cutted = astralSafeCharacterArray . slice ( 0 , len ) . join ( '' ) ; if ( ! this . reserveLastWord ) { return cutted ; } var boundary = astralSafeCharacterArray . slice ( len - 1 , len + 1 ) . join ( '' ) ; // if truncate at word boundary, just return
 if ( / \W / . test ( boundary ) ) { return cutted ; } if ( this . reserveLastWord < 0 ) { var result = cutted . replace ( / \w+$ / , '' ) ; // if the cutted is not the first and the only word
 //   then return result, or return the whole word
 if ( ! ( result . length === 0 && cutted . length === this . options . length ) ) { return result ; } } // set max exceeded to 10 if this.reserveLastWord is true or > 0
 var maxExceeded = this . reserveLastWord !== true && this . reserveLastWord > 0 ? this . reserveLastWord : 10 ; var mtc = astralSafeCharacterArray . slice ( len ) . join ( '' ) . match ( / (\w+) / ) ; var exceeded = mtc ? mtc [ 1 ] : '' ; return cutted + exceeded . substr ( 0 , maxExceeded ) ; }
deal with cut string in the middle of a word
deal with cut string in the middle of a word