1 | /** global: UB */ |
||
2 | |||
3 | /*! STRING ARRAY UTILS */ |
||
4 | |||
5 | var arrayFuncs = { |
||
6 | |||
7 | View Code Duplication | indexOfCI: function(value){ |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
8 | var list = this; |
||
9 | if (list.length === 0) { |
||
10 | return -1; |
||
11 | } |
||
12 | for (var i = 0, il = list.length;i<il;i++){ |
||
13 | var str = list[i]; |
||
14 | if (str && str.constructor === String) { |
||
15 | if (str.equalsCI(value)){ |
||
16 | return i; |
||
17 | } |
||
18 | } |
||
19 | } |
||
20 | return -1; |
||
21 | }, |
||
22 | |||
23 | View Code Duplication | lastIndexOfCI: function(value){ |
|
0 ignored issues
–
show
|
|||
24 | var list = this; |
||
25 | if (list.length === 0) { |
||
26 | return -1; |
||
27 | } |
||
28 | for (var i = list.length-1;i>=0;i--){ |
||
29 | var str = list[i]; |
||
30 | if (str && str.constructor === String) { |
||
31 | if (str.equalsCI(value)){ |
||
32 | return i; |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 | return -1; |
||
37 | }, |
||
38 | |||
39 | removeCI: function(value, stringReplace = false){ |
||
40 | var list = this; |
||
41 | for (var i = 0, il = list.length;i<il;i++){ |
||
42 | var str = list[i]; |
||
43 | if (str && str.constructor === String) { |
||
44 | if (stringReplace){ |
||
45 | |||
46 | // remove substring within string items |
||
47 | list[i] = str.removeAll(value, false, false); |
||
48 | |||
49 | }else{ |
||
50 | |||
51 | // remove entire items |
||
52 | if (str.equalsCI(value)) { |
||
53 | list.splice(i, 1); |
||
54 | i--; |
||
55 | il--; |
||
56 | } |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | }, |
||
61 | |||
62 | removeIfContains: function(value, caseSensitive = true){ |
||
63 | var list = this; |
||
64 | for (var i = 0, il = list.length;i<il;i++){ |
||
65 | |||
66 | // remove entire items if string item contains the given substring |
||
67 | var str = list[i]; |
||
68 | if (str && str.constructor === String && str.smartContains(value, caseSensitive)) { |
||
69 | list.splice(i, 1); |
||
70 | i--; |
||
71 | il--; |
||
72 | } |
||
73 | } |
||
74 | }, |
||
75 | removeIfBeginsWith: function(value, caseSensitive = true, trimAndCheck = false){ |
||
76 | return this.removeIfStartsWith(value, caseSensitive, trimAndCheck); |
||
77 | }, |
||
78 | removeIfStartsWith: function(value, caseSensitive = true, trimAndCheck = false){ |
||
79 | var list = this; |
||
80 | for (var i = 0, il = list.length;i<il;i++){ |
||
81 | |||
82 | // remove entire items if string item starts with the given substring |
||
83 | var str = list[i]; |
||
84 | if (str && str.constructor === String && str.smartStartsWith(value, null, caseSensitive, trimAndCheck)) { |
||
85 | list.splice(i, 1); |
||
86 | i--; |
||
87 | il--; |
||
88 | } |
||
89 | } |
||
90 | }, |
||
91 | removeIfEndsWith: function(value, caseSensitive = true, trimAndCheck = false){ |
||
92 | var list = this; |
||
93 | for (var i = 0, il = list.length;i<il;i++){ |
||
94 | |||
95 | // remove entire items if string item ends with the given substring |
||
96 | var str = list[i]; |
||
97 | if (str && str.constructor === String && str.smartEndsWith(value, null, caseSensitive, trimAndCheck)) { |
||
98 | list.splice(i, 1); |
||
99 | i--; |
||
100 | il--; |
||
101 | } |
||
102 | } |
||
103 | }, |
||
104 | |||
105 | |||
106 | none:null |
||
107 | }; |
||
108 | |||
109 | // register funcs |
||
110 | UB.registerFuncs(Array.prototype, arrayFuncs); |
||
111 |