@@ -94,12 +94,12 @@ describe("OrderPipe", () => {
94
94
const array = [
95
95
{ values : [ 10 , 0 ] } ,
96
96
{ values : [ 1 , 2 ] } ,
97
- { values : [ 0 , - 1 , 1 ] }
97
+ { values : [ 0 , - 1 , 1 ] } ,
98
98
] ;
99
99
const arraySorted = [
100
100
{ values : [ 0 , - 1 , 1 ] } ,
101
101
{ values : [ 1 , 2 ] } ,
102
- { values : [ 10 , 0 ] }
102
+ { values : [ 10 , 0 ] } ,
103
103
] ;
104
104
105
105
expect ( pipe . transform ( array , "values" ) ) . toEqual ( arraySorted ) ;
@@ -111,16 +111,16 @@ describe("OrderPipe", () => {
111
111
c : [ 2 , 1 , 3 ] ,
112
112
d : [ "h" , "ch" ] ,
113
113
e : [ { } , { f : "g" } ] ,
114
- f : "i"
115
- }
114
+ f : "i" ,
115
+ } ,
116
116
} ;
117
117
const sortedObject = {
118
118
b : {
119
119
c : [ 1 , 2 , 3 ] ,
120
120
d : [ "h" , "ch" ] ,
121
121
e : [ { } , { f : "g" } ] ,
122
- f : "i"
123
- }
122
+ f : "i" ,
123
+ } ,
124
124
} ;
125
125
126
126
expect ( pipe . transform ( object , "b.c" ) ) . toEqual ( sortedObject ) ;
@@ -131,8 +131,8 @@ describe("OrderPipe", () => {
131
131
it ( 'should not throw error on ordering "undefined" deep element' , ( ) => {
132
132
const object = {
133
133
b : {
134
- e : [ { } , { f : "g" } ]
135
- }
134
+ e : [ { } , { f : "g" } ] ,
135
+ } ,
136
136
} ;
137
137
138
138
expect ( pipe . transform ( object , "b.e[2].f" ) ) . toEqual ( object ) ;
@@ -141,13 +141,13 @@ describe("OrderPipe", () => {
141
141
it ( "should sort deep elements" , ( ) => {
142
142
const object = {
143
143
lists : {
144
- users : [ { id : 3 } , { id : 2 } , { id : 1 } ]
145
- }
144
+ users : [ { id : 3 } , { id : 2 } , { id : 1 } ] ,
145
+ } ,
146
146
} ;
147
147
const objectSorted = {
148
148
lists : {
149
- users : [ { id : 1 } , { id : 2 } , { id : 3 } ]
150
- }
149
+ users : [ { id : 1 } , { id : 2 } , { id : 3 } ] ,
150
+ } ,
151
151
} ;
152
152
153
153
expect ( pipe . transform ( object , "lists.users.id" ) ) . toEqual ( objectSorted ) ;
@@ -158,14 +158,14 @@ describe("OrderPipe", () => {
158
158
{ customer : { name : "test" } } ,
159
159
{ customer : { name : "b" } } ,
160
160
{ customer : { name : "a" } } ,
161
- { customer : { name : "c" } }
161
+ { customer : { name : "c" } } ,
162
162
] ;
163
163
164
164
const res = [
165
165
{ customer : { name : "a" } } ,
166
166
{ customer : { name : "b" } } ,
167
167
{ customer : { name : "c" } } ,
168
- { customer : { name : "test" } }
168
+ { customer : { name : "test" } } ,
169
169
] ;
170
170
171
171
expect ( pipe . transform ( arr , "customer.name" ) ) . toEqual ( res ) ;
@@ -175,15 +175,15 @@ describe("OrderPipe", () => {
175
175
{ customer : { number : 5 } } ,
176
176
{ customer : { number : 0 } } ,
177
177
{ customer : { number : 15 } } ,
178
- { customer : { number : 1 } }
178
+ { customer : { number : 1 } } ,
179
179
] ;
180
180
181
181
const result = [
182
182
{ customer : { number : 0 } } ,
183
183
{ customer : { number : 1 } } ,
184
184
{ customer : { number : 5 } } ,
185
185
{ customer : { number : 15 } } ,
186
- { customer : { number : 25 } }
186
+ { customer : { number : 25 } } ,
187
187
] ;
188
188
189
189
expect ( pipe . transform ( array , "customer.number" ) ) . toEqual ( result ) ;
@@ -194,14 +194,14 @@ describe("OrderPipe", () => {
194
194
{ customer : { name : "test" } } ,
195
195
{ customer : { name : "B" } } ,
196
196
{ customer : { name : "a" } } ,
197
- { customer : { name : "c" } }
197
+ { customer : { name : "c" } } ,
198
198
] ;
199
199
200
200
const res = [
201
201
{ customer : { name : "a" } } ,
202
202
{ customer : { name : "B" } } ,
203
203
{ customer : { name : "c" } } ,
204
- { customer : { name : "test" } }
204
+ { customer : { name : "test" } } ,
205
205
] ;
206
206
207
207
expect ( pipe . transform ( arr , "customer.name" , false , true ) ) . toEqual ( res ) ;
@@ -248,7 +248,7 @@ describe("OrderPipe", () => {
248
248
const arr = [ "$10,0" , "$2,0" , "$100,0" ] ;
249
249
const res = [ "$2,0" , "$10,0" , "$100,0" ] ;
250
250
251
- const parse = value => parseInt ( value . replace ( / [ ^ 0 - 9 ] / g, "" ) , 10 ) ;
251
+ const parse = ( value ) => parseInt ( value . replace ( / [ ^ 0 - 9 ] / g, "" ) , 10 ) ;
252
252
253
253
expect (
254
254
pipe . transform ( arr , null , false , true , ( a , b ) => {
@@ -283,13 +283,13 @@ describe("OrderPipe", () => {
283
283
const array = [
284
284
{ name : "qwe" , age : 1 } ,
285
285
{ name : "asd" , age : 3 } ,
286
- { name : "asd" , age : 2 }
286
+ { name : "asd" , age : 2 } ,
287
287
] ;
288
288
289
289
const result = [
290
290
{ name : "asd" , age : 2 } ,
291
291
{ name : "asd" , age : 3 } ,
292
- { name : "qwe" , age : 1 }
292
+ { name : "qwe" , age : 1 } ,
293
293
] ;
294
294
295
295
expect ( pipe . transform ( array , [ "name" , "age" ] ) ) . toEqual ( result ) ;
@@ -301,7 +301,7 @@ describe("OrderPipe", () => {
301
301
{ group : 1 , value : 1 } ,
302
302
{ group : 3 , value : 1 } ,
303
303
{ group : 2 , value : 2 } ,
304
- { group : 2 , value : 1 }
304
+ { group : 2 , value : 1 } ,
305
305
] ;
306
306
307
307
it ( "should sort by multiple fields and preserve priority" , ( ) => {
@@ -310,7 +310,7 @@ describe("OrderPipe", () => {
310
310
{ group : 1 , value : 2 } ,
311
311
{ group : 2 , value : 1 } ,
312
312
{ group : 2 , value : 2 } ,
313
- { group : 3 , value : 1 }
313
+ { group : 3 , value : 1 } ,
314
314
] ;
315
315
316
316
expect ( pipe . transform ( array , [ "group" , "value" ] ) ) . toEqual ( result ) ;
@@ -322,7 +322,7 @@ describe("OrderPipe", () => {
322
322
{ group : 2 , value : 1 } ,
323
323
{ group : 3 , value : 1 } ,
324
324
{ group : 1 , value : 2 } ,
325
- { group : 2 , value : 2 }
325
+ { group : 2 , value : 2 } ,
326
326
] ;
327
327
328
328
expect ( pipe . transform ( array , [ "value" , "group" ] ) ) . toEqual ( result ) ;
@@ -333,16 +333,22 @@ describe("OrderPipe", () => {
333
333
const array = [
334
334
{ name : "q" , age : 1 } ,
335
335
{ name : "a" , age : 3 } ,
336
- { name : "a" , age : 2 }
336
+ { name : "a" , age : 2 } ,
337
337
] ;
338
338
339
339
expect ( pipe . transform ( array , [ ] ) ) . toEqual ( array ) ;
340
340
} ) ;
341
341
342
342
it ( "should not modify original array" , ( ) => {
343
- const array = [ { key : "a" , value : 3 } , { key : "a" , value : 1 } ] ;
343
+ const array = [
344
+ { key : "a" , value : 3 } ,
345
+ { key : "a" , value : 1 } ,
346
+ ] ;
344
347
345
- const result = [ { key : "a" , value : 1 } , { key : "a" , value : 3 } ] ;
348
+ const result = [
349
+ { key : "a" , value : 1 } ,
350
+ { key : "a" , value : 3 } ,
351
+ ] ;
346
352
347
353
expect ( pipe . transform ( array , [ "key" , "value" ] ) ) . toEqual ( result ) ;
348
354
expect ( array [ 0 ] ) . toEqual ( { key : "a" , value : 3 } ) ;
@@ -367,26 +373,26 @@ describe("OrderPipe", () => {
367
373
} ) ;
368
374
} ) ;
369
375
370
- it ( "should keep same order" , function ( ) {
376
+ it ( "should keep same order" , function ( ) {
371
377
const collection = [
372
378
{
373
379
name : "John" ,
374
380
age : "25" ,
375
381
score : 12 ,
376
- percent : "5.2%"
382
+ percent : "5.2%" ,
377
383
} ,
378
384
{
379
385
name : "Mark" ,
380
386
age : "19" ,
381
387
score : 12 ,
382
- percent : "No Value"
388
+ percent : "No Value" ,
383
389
} ,
384
390
{
385
391
name : "Peter" ,
386
392
age : "21" ,
387
393
score : 12 ,
388
- percent : "1.8%"
389
- }
394
+ percent : "1.8%" ,
395
+ } ,
390
396
] ;
391
397
392
398
expect ( pipe . transform ( collection , "score" ) ) . toEqual ( collection ) ;
@@ -397,14 +403,14 @@ describe("OrderPipe", () => {
397
403
{ a : { b : 3 } } ,
398
404
{ a : { b : 1 } } ,
399
405
{ a : undefined } ,
400
- { a : { b : 2 } }
406
+ { a : { b : 2 } } ,
401
407
] ;
402
408
403
409
const result = [
404
410
{ a : { b : 1 } } ,
405
411
{ a : { b : 2 } } ,
406
412
{ a : { b : 3 } } ,
407
- { a : undefined }
413
+ { a : undefined } ,
408
414
] ;
409
415
410
416
expect ( pipe . transform ( collection , "a.b" ) ) . toEqual ( result ) ;
0 commit comments