UNPKG

1.5 kBJavaScriptView Raw
1"use strict";
2var Utils;
3(function (Utils) {
4 function exists(list, predicate) {
5 if (list != null) {
6 for (var i = 0; i < list.length; i++) {
7 var obj = list[i];
8 if (predicate(obj)) {
9 return true;
10 }
11 }
12 }
13 return false;
14 }
15 Utils.exists = exists;
16 function contains(list, element) {
17 return exists(list, function (item) {
18 return item === element;
19 });
20 }
21 Utils.contains = contains;
22 function removeAll(source, elementsToRemove) {
23 if (source == null || source.length === 0) {
24 return [];
25 }
26 if (elementsToRemove == null || elementsToRemove.length === 0) {
27 return [].concat(source);
28 }
29 return source.filter(function (sourceElement) {
30 return !contains(elementsToRemove, sourceElement);
31 });
32 }
33 Utils.removeAll = removeAll;
34 function remove(source, elementToRemove) {
35 return removeAll(source, [elementToRemove]);
36 }
37 Utils.remove = remove;
38 function trimTo(source, maxLength) {
39 if (source == null) {
40 return '';
41 }
42 if (source.length <= maxLength) {
43 return source;
44 }
45 return source.substr(0, maxLength - 2) + '...';
46 }
47 Utils.trimTo = trimTo;
48})(Utils = exports.Utils || (exports.Utils = {}));
49//# sourceMappingURL=Utils.js.map
\No newline at end of file