@@ -20,177 +20,104 @@ var __spread = (this && this.__spread) || function () {
2020 return ar ;
2121} ;
2222Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
23- try {
24- Object . defineProperties ( Array . prototype , {
25- remove : {
26- enumerable : false ,
27- writable : true ,
28- configurable : true ,
29- value : function ( elem ) {
30- // do not use filter to modify current array
31- var index = this . indexOf ( elem ) ;
32- if ( index === - 1 )
33- return this ;
34- this . splice ( index , 1 ) ;
35- return this ; //.filter((e) => e !== elem);
36- } ,
37- } ,
38- insert : {
39- enumerable : false ,
40- writable : true ,
41- configurable : true ,
42- value : function ( elem , index ) {
43- if ( ! index )
44- index = this . length ;
45- return this . splice ( index , 0 , elem ) ;
46- } ,
47- } ,
48- flat : {
49- enumerable : false ,
50- writable : true ,
51- configurable : true ,
52- value : function ( depth ) {
53- if ( depth === void 0 ) { depth = 1 ; }
54- return this . reduce ( function ( acc , val ) {
55- return ( Array . isArray ( val ) && depth >= 1 ) || depth === - 1
56- ? acc . concat ( val . flat ( depth -- ) )
57- : acc . concat ( val ) ;
58- } , [ ] ) ;
59- } ,
60- } ,
61- last : {
62- enumerable : false ,
63- writable : true ,
64- configurable : true ,
65- value : function ( ) {
66- return this [ this . length - 1 ] ;
67- } ,
68- } ,
69- first : {
70- enumerable : false ,
71- writable : true ,
72- configurable : true ,
73- value : function ( ) {
74- return this [ 0 ] ;
75- } ,
76- } ,
77- unique : {
78- enumerable : false ,
79- writable : true ,
80- configurable : true ,
81- value : function ( ) {
82- return __spread ( new Set ( this ) ) ;
83- } ,
84- } ,
85- random : {
86- enumerable : false ,
87- writable : true ,
88- configurable : true ,
89- value : function ( ) {
90- return this [ Math . floor ( Math . random ( ) * this . length ) ] ;
91- } ,
92- } ,
93- shuffle : {
94- enumerable : false ,
95- writable : true ,
96- configurable : true ,
97- value : function ( ) {
98- var _a ;
99- for ( var i = this . length - 1 ; i > 0 ; i -- ) {
100- var j = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
101- _a = __read ( [ this [ j ] , this [ i ] ] , 2 ) , this [ i ] = _a [ 0 ] , this [ j ] = _a [ 1 ] ;
102- }
103- return this ;
104- } ,
105- } ,
106- findMap : {
107- enumerable : false ,
108- writable : true ,
109- configurable : true ,
110- value : function ( predicate ) {
111- for ( var i = 0 ; i < this . length ; i ++ ) {
112- var result = predicate ( this [ i ] , i , this ) ;
113- if ( result ) {
114- return result ;
115- }
23+ var Util_1 = require ( "./Util" ) ;
24+ Util_1 . define ( Array . prototype , {
25+ remove : function ( elem ) {
26+ // do not use filter to modify current array
27+ var index = this . indexOf ( elem ) ;
28+ if ( index === - 1 )
29+ return this ;
30+ this . splice ( index , 1 ) ;
31+ return this ; //.filter((e) => e !== elem);
32+ } ,
33+ insert : function ( elem , index ) {
34+ if ( ! index )
35+ index = this . length ;
36+ this . splice ( index , 0 , elem ) ;
37+ return this ;
38+ } ,
39+ flat : function ( depth ) {
40+ if ( depth === void 0 ) { depth = 1 ; }
41+ return this . reduce ( function ( acc , val ) {
42+ return ( Array . isArray ( val ) && depth >= 1 ) || depth === - 1 ? acc . concat ( val . flat ( depth -- ) ) : acc . concat ( val ) ;
43+ } , [ ] ) ;
44+ } ,
45+ last : function ( ) {
46+ return this [ this . length - 1 ] ;
47+ } ,
48+ first : function ( ) {
49+ return this [ 0 ] ;
50+ } ,
51+ unique : function ( ) {
52+ return __spread ( new Set ( this ) ) ;
53+ } ,
54+ random : function ( ) {
55+ return this [ Math . floor ( Math . random ( ) * this . length ) ] ;
56+ } ,
57+ shuffle : function ( ) {
58+ var _a ;
59+ for ( var i = this . length - 1 ; i > 0 ; i -- ) {
60+ var j = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
61+ _a = __read ( [ this [ j ] , this [ i ] ] , 2 ) , this [ i ] = _a [ 0 ] , this [ j ] = _a [ 1 ] ;
62+ }
63+ return this ;
64+ } ,
65+ findMap : function ( predicate ) {
66+ for ( var i = 0 ; i < this . length ; i ++ ) {
67+ var result = predicate ( this [ i ] , i , this ) ;
68+ if ( result ) {
69+ return result ;
70+ }
71+ }
72+ } ,
73+ findLast : function ( predicate ) {
74+ for ( var i = this . length ; i >= 0 ; i -- ) {
75+ if ( predicate ( this [ i ] , i , this ) )
76+ return this [ i ] ;
77+ }
78+ return null ;
79+ } ,
80+ findLastIndex : function ( predicate ) {
81+ for ( var i = this . length - 1 ; i >= 0 ; i -- ) {
82+ if ( predicate ( this [ i ] , i , this ) )
83+ return i ;
84+ }
85+ return - 1 ;
86+ } ,
87+ count : function ( search ) {
88+ var nativeTypes = [ "string" , "number" , "object" , "array" ] ;
89+ var count = 0 ;
90+ this . forEach ( function ( element ) {
91+ if ( element === search ) {
92+ count ++ ;
93+ return ;
94+ }
95+ // check if searchparam is a native class (l: 99)
96+ if ( typeof search == "function" ) {
97+ var className = search . name . toLowerCase ( ) ;
98+ if ( nativeTypes . includes ( className ) && typeof element === className ) {
99+ count ++ ;
100+ return ;
116101 }
117- } ,
118- } ,
119- findLast : {
120- enumerable : false ,
121- writable : true ,
122- configurable : true ,
123- value : function ( predicate ) {
124- for ( var i = this . length ; i >= 0 ; i -- ) {
125- if ( predicate ( this [ i ] , i , this ) )
126- return this [ i ] ;
102+ else if ( element instanceof search ) {
103+ count ++ ;
104+ return ;
127105 }
128- return null ;
129- } ,
130- } ,
131- findLastIndex : {
132- enumerable : false ,
133- writable : true ,
134- configurable : true ,
135- value : function ( predicate ) {
136- for ( var i = this . length - 1 ; i >= 0 ; i -- ) {
137- if ( predicate ( this [ i ] , i , this ) )
138- return i ;
106+ }
107+ // if element of array is a string: allow regex patterns
108+ if ( typeof element === "string" ) {
109+ if ( element . match ( search ) ) {
110+ count ++ ;
111+ return ;
139112 }
140- return - 1 ;
141- } ,
142- } ,
143- count : {
144- enumerable : false ,
145- writable : true ,
146- configurable : true ,
147- value : function ( search ) {
148- var nativeTypes = [ "string" , "number" , "object" , "array" ] ;
149- var count = 0 ;
150- this . forEach ( function ( element ) {
151- if ( element === search ) {
152- count ++ ;
153- return ;
154- }
155- // check if searchparam is a native class (l: 99)
156- if ( typeof search == "function" ) {
157- var className = search . name . toLowerCase ( ) ;
158- if ( nativeTypes . includes ( className ) && typeof element === className ) {
159- count ++ ;
160- return ;
161- }
162- else if ( element instanceof search ) {
163- count ++ ;
164- return ;
165- }
166- }
167- // if element of array is a string: allow regex patterns
168- if ( typeof element === "string" ) {
169- if ( element . match ( search ) ) {
170- count ++ ;
171- return ;
172- }
173- }
174- } ) ;
175- return count ;
176- } ,
177- } ,
178- missing : {
179- enumerable : false ,
180- writable : true ,
181- configurable : true ,
182- value : function ( arr ) {
183- return this . filter ( function ( x ) { return ! arr . includes ( x ) ; } ) ;
184- } ,
185- } ,
186- similarities : {
187- enumerable : false ,
188- writable : true ,
189- configurable : true ,
190- value : function ( arr ) {
191- return this . filter ( function ( x ) { return arr . includes ( x ) ; } ) ;
192- } ,
193- } ,
194- } ) ;
195- }
196- catch ( error ) { }
113+ }
114+ } ) ;
115+ return count ;
116+ } ,
117+ missing : function ( arr ) {
118+ return this . filter ( function ( x ) { return ! arr . includes ( x ) ; } ) ;
119+ } ,
120+ similarities : function ( arr ) {
121+ return this . filter ( function ( x ) { return arr . includes ( x ) ; } ) ;
122+ } ,
123+ } ) ;
0 commit comments