angularjs left xx characters

Solutions on MaxInterview for angularjs left xx characters by the best coders in the world

showing results for - "angularjs left xx characters"
Mya
27 May 2020
1angular.module('ng').filter('cut', function () {
2        return function (value, wordwise, max, tail) {
3            if (!value) return '';
4
5            max = parseInt(max, 10);
6            if (!max) return value;
7            if (value.length <= max) return value;
8
9            value = value.substr(0, max);
10            if (wordwise) {
11                var lastspace = value.lastIndexOf(' ');
12                if (lastspace !== -1) {
13                  //Also remove . and , so its gives a cleaner result.
14                  if (value.charAt(lastspace-1) === '.' || value.charAt(lastspace-1) === ',') {
15                    lastspace = lastspace - 1;
16                  }
17                  value = value.substr(0, lastspace);
18                }
19            }
20
21            return value + (tail || ' …');
22        };
23    });