How to use slice method in Cypress

Best JavaScript code snippet using cypress

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

group-pictures.js

Source: group-pictures.js Github

copy
1/* global hexo */
2// Usage: {% grouppicture group-layout %}{% endgrouppicture %}
3// Alias: {% gp group-layout %}{% endgp %}
4
5function groupPicture(args, content) {
6  args = args[0].split('-');
7  var group = parseInt(args[0]);
8  var layout = parseInt(args[1]);
9
10  content = hexo.render.renderSync({text: content, engine: 'markdown'});
11
12  var pictures = content.match(/<img[\s\S]*?>/g);
13
14  return '<div class="group-picture">' +
15            templates.dispatch(pictures, group, layout) +
16         '</div>';
17}
18
19var templates = {
20
21  dispatch: function (pictures, group, layout) {
22    var fn = 'group' + group + 'Layout' + layout;
23    fn = templates[fn] || templates.defaults;
24    return fn.call(templates, pictures);
25  },
26
27  /**
28   * 2-1
29   *
30   *  □
31   *  □
32   *
33   * @param pictures
34   * @returns {string}
35   */
36  group2Layout1: function (pictures) {
37    return this.getHTML([
38      pictures.slice(0, 1),
39      pictures.slice(1)
40    ]);
41  },
42
43  /**
44   * 2-2
45   *
46   * □ □
47   *
48   * @param pictures
49   */
50  group2Layout2: function (pictures) {
51    return this.getHTML(pictures);
52  },
53
54  /**
55   * 3-1
56   *
57   * □ □ □
58   *
59   * @param pictures
60   */
61  group3Layout1: function (pictures) {
62    return this.getHTML(pictures);
63  },
64
65  /**
66   * 3-2
67   *
68   *  □
69   * □ □
70   *
71   * @param pictures
72   */
73  group3Layout2: function (pictures) {
74    return this.getHTML([
75      pictures.slice(0, 1),
76      pictures.slice(1)
77    ]);
78  },
79
80  /**
81   * 3-3
82   *
83   * □ □
84   *  □
85   *
86   * @param pictures
87   */
88  group3Layout3: function (pictures) {
89    return this.getHTML([
90      pictures.slice(0, 2),
91      pictures.slice(2)
92    ]);
93  },
94
95  /**
96   * 4-1
97   *
98   *  □
99   * □ □
100   *  □
101   *
102   * @param pictures
103   */
104  group4Layout1: function (pictures) {
105    return this.getHTML([
106      pictures.slice(0, 1),
107      pictures.slice(1, 3),
108      pictures.slice(3)
109    ]);
110  },
111
112  /**
113   * 4-2
114   *
115   *   □
116   * □ □ □
117   *
118   * @param pictures
119   */
120  group4Layout2: function (pictures) {
121    return this.getHTML([
122      pictures.slice(0, 1),
123      pictures.slice(1)
124    ]);
125  },
126
127  /**
128   * 4-3
129   *
130   * □ □
131   * □ □
132   *
133   * @param pictures
134   */
135  group4Layout3: function (pictures) {
136    return this.getHTML([
137      pictures.slice(0, 2),
138      pictures.slice(2)
139    ]);
140  },
141
142  /**
143   * 4-4
144   *
145   * □ □ □
146   *   □
147   *
148   * @param pictures
149   */
150  group4Layout4: function (pictures) {
151    return this.getHTML([
152      pictures.slice(0, 3),
153      pictures.slice(3)
154    ]);
155  },
156
157  /**
158   * 5-1
159   *
160   *  □
161   * □ □
162   * □ □
163   *
164   * @param pictures
165   */
166  group5Layout1: function (pictures) {
167    return this.getHTML([
168      pictures.slice(0, 1),
169      pictures.slice(1, 3),
170      pictures.slice(3)
171    ]);
172  },
173
174  /**
175   * 5-2
176   *
177   * □ □
178   *  □
179   * □ □
180   *
181   * @param pictures
182   */
183  group5Layout2: function (pictures) {
184    return this.getHTML([
185      pictures.slice(0, 2),
186      pictures.slice(2, 3),
187      pictures.slice(3)
188    ]);
189  },
190
191  /**
192   * 5-3
193   *
194   *  □ □
195   * □ □ □
196   *
197   * @param pictures
198   */
199  group5Layout3: function (pictures) {
200    return this.getHTML([
201      pictures.slice(0, 2),
202      pictures.slice(2)
203    ]);
204  },
205
206  /**
207   * 5-4
208   *
209   * □ □ □
210   *  □ □
211   *
212   * @param pictures
213   */
214  group5Layout4: function (pictures) {
215    return this.getHTML([
216      pictures.slice(0, 3),
217      pictures.slice(3)
218    ]);
219  },
220
221  /**
222   * 6-1
223   *
224   *   □
225   *  □ □
226   * □ □ □
227   *
228   * @param pictures
229   */
230  group6Layout1: function (pictures) {
231    return this.getHTML([
232      pictures.slice(0, 1),
233      pictures.slice(1, 3),
234      pictures.slice(3)
235    ]);
236  },
237
238  /**
239   * 6-2
240   *
241   *   □
242   * □ □ □
243   *  □ □
244   *
245   * @param pictures
246   */
247  group6Layout2: function (pictures) {
248    return this.getHTML([
249      pictures.slice(0, 1),
250      pictures.slice(1, 4),
251      pictures.slice(4)
252    ]);
253  },
254
255  /**
256   * 6-3
257   *
258   *  □ □
259   *   □
260   * □ □ □
261   *
262   * @param pictures
263   */
264  group6Layout3: function (pictures) {
265    return this.getHTML([
266      pictures.slice(0, 2),
267      pictures.slice(2, 3),
268      pictures.slice(3)
269    ]);
270  },
271
272  /**
273   * 6-4
274   *
275   * □ □
276   * □ □
277   * □ □
278   *
279   * @param pictures
280   */
281  group6Layout4: function (pictures) {
282    return this.getHTML([
283      pictures.slice(0, 2),
284      pictures.slice(2, 4),
285      pictures.slice(4)
286    ]);
287  },
288
289  /**
290   * 6-5
291   *
292   * □ □ □
293   * □ □ □
294   *
295   * @param pictures
296   */
297  group6Layout5: function (pictures) {
298    return this.getHTML([
299      pictures.slice(0, 3),
300      pictures.slice(3)
301    ]);
302  },
303
304  /**
305   * 7-1
306   *
307   *  □
308   * □ □
309   * □ □
310   * □ □
311   *
312   * @param pictures
313   */
314  group7Layout1: function (pictures) {
315    return this.getHTML([
316      pictures.slice(0, 1),
317      pictures.slice(1, 3),
318      pictures.slice(3, 5),
319      pictures.slice(5)
320    ]);
321  },
322
323  /**
324   * 7-2
325   *
326   *   □
327   * □ □ □
328   * □ □ □
329   *
330   * @param pictures
331   */
332  group7Layout2: function (pictures) {
333    return this.getHTML([
334      pictures.slice(0, 1),
335      pictures.slice(1, 4),
336      pictures.slice(4)
337    ]);
338  },
339
340  /**
341   * 7-3
342   *
343   *  □ □
344   *  □ □
345   * □ □ □
346   *
347   * @param pictures
348   */
349  group7Layout3: function (pictures) {
350    return this.getHTML([
351      pictures.slice(0, 2),
352      pictures.slice(2, 4),
353      pictures.slice(4)
354    ]);
355  },
356
357  /**
358   * 7-4
359   *
360   *  □ □
361   * □ □ □
362   *  □ □
363   *
364   * @param pictures
365   */
366  group7Layout4: function (pictures) {
367    return this.getHTML([
368      pictures.slice(0, 2),
369      pictures.slice(2, 5),
370      pictures.slice(5)
371    ]);
372  },
373
374  /**
375   * 7-5
376   *
377   * □ □ □
378   *  □ □
379   *  □ □
380   *
381   * @param pictures
382   */
383  group7Layout5: function (pictures) {
384    return this.getHTML([
385      pictures.slice(0, 3),
386      pictures.slice(3, 5),
387      pictures.slice(5)
388    ]);
389  },
390
391  /**
392   * 8-1
393   *
394   *   □
395   *  □ □
396   *  □ □
397   * □ □ □
398   *
399   * @param pictures
400   */
401  group8Layout1: function (pictures) {
402    return this.getHTML([
403      pictures.slice(0, 1),
404      pictures.slice(1, 3),
405      pictures.slice(3, 5),
406      pictures.slice(5)
407    ]);
408  },
409
410  /**
411   * 8-2
412   *
413   *   □
414   *  □ □
415   * □ □ □
416   *  □ □
417   *
418   * @param pictures
419   */
420  group8Layout2: function (pictures) {
421    return this.getHTML([
422      pictures.slice(0, 1),
423      pictures.slice(1, 3),
424      pictures.slice(3, 6),
425      pictures.slice(6)
426    ]);
427  },
428
429  /**
430   * 8-3
431   *
432   *   □
433   * □ □ □
434   *  □ □
435   *  □ □
436   * @param pictures
437   */
438  group8Layout3: function (pictures) {
439    return this.getHTML([
440      pictures.slice(0, 1),
441      pictures.slice(1, 4),
442      pictures.slice(4, 6),
443      pictures.slice(6)
444    ]);
445  },
446
447  /**
448   * 8-4
449   *
450   * □ □
451   * □ □
452   * □ □
453   * □ □
454   *
455   * @param pictures
456   */
457  group8Layout4: function (pictures) {
458    return this.getHTML([
459      pictures.slice(0, 2),
460      pictures.slice(2, 4),
461      pictures.slice(4, 6),
462      pictures.slice(6)
463    ]);
464  },
465
466  /**
467   * 8-5
468   *
469   *  □ □
470   * □ □ □
471   * □ □ □
472   *
473   * @param pictures
474   */
475  group8Layout5: function (pictures) {
476    return this.getHTML([
477      pictures.slice(0, 2),
478      pictures.slice(2, 5),
479      pictures.slice(5)
480    ]);
481  },
482
483  /**
484   * 8-6
485   *
486   * □ □ □
487   *  □ □
488   * □ □ □
489   *
490   * @param pictures
491   */
492  group8Layout6: function (pictures) {
493    return this.getHTML([
494      pictures.slice(0, 3),
495      pictures.slice(3, 5),
496      pictures.slice(5)
497    ]);
498  },
499
500  /**
501   * 8-7
502   *
503   * □ □ □
504   * □ □ □
505   *  □ □
506   *
507   * @param pictures
508   */
509  group8Layout7: function (pictures) {
510    return this.getHTML([
511      pictures.slice(0, 3),
512      pictures.slice(3, 6),
513      pictures.slice(6)
514    ]);
515  },
516
517  /**
518   * 9-1
519   *
520   *   □
521   *  □ □
522   * □ □ □
523   * □ □ □
524   *
525   * @param pictures
526   */
527  group9Layout1: function (pictures) {
528    return this.getHTML([
529      pictures.slice(0, 1),
530      pictures.slice(1, 3),
531      pictures.slice(3, 6),
532      pictures.slice(6)
533    ]);
534  },
535
536  /**
537   * 9-2
538   *
539   *   □
540   * □ □ □
541   *  □ □
542   * □ □ □
543   *
544   * @param pictures
545   */
546  group9Layout2: function (pictures) {
547    return this.getHTML([
548      pictures.slice(0, 1),
549      pictures.slice(1, 4),
550      pictures.slice(4, 6),
551      pictures.slice(6)
552    ]);
553  },
554
555  /**
556   * 9-3
557   *
558   *  □ □
559   *  □ □
560   *  □ □
561   * □ □ □
562   *
563   * @param pictures
564   */
565  group9Layout3: function (pictures) {
566    return this.getHTML([
567      pictures.slice(0, 2),
568      pictures.slice(2, 4),
569      pictures.slice(4, 6),
570      pictures.slice(6)
571    ]);
572  },
573
574  /**
575   * 9-4
576   *
577   *  □ □
578   *  □ □
579   * □ □ □
580   *  □ □
581   *
582   * @param pictures
583   */
584  group9Layout4: function (pictures) {
585    return this.getHTML([
586      pictures.slice(0, 2),
587      pictures.slice(2, 4),
588      pictures.slice(4, 7),
589      pictures.slice(7)
590    ]);
591  },
592
593  /**
594   * 9-5
595   *
596   *  □ □
597   * □ □ □
598   *  □ □
599   *  □ □
600   *
601   * @param pictures
602   */
603  group9Layout5: function (pictures) {
604    return this.getHTML([
605      pictures.slice(0, 2),
606      pictures.slice(2, 5),
607      pictures.slice(5, 7),
608      pictures.slice(7)
609    ]);
610  },
611
612  /**
613   * 9-6
614   *
615   * □ □ □
616   *  □ □
617   *  □ □
618   *  □ □
619   *
620   * @param pictures
621   */
622  group9Layout6: function (pictures) {
623    return this.getHTML([
624      pictures.slice(0, 3),
625      pictures.slice(3, 5),
626      pictures.slice(5, 7),
627      pictures.slice(7)
628    ]);
629  },
630
631  /**
632   * 9-7
633   *
634   * □ □ □
635   * □ □ □
636   * □ □ □
637   *
638   * @param pictures
639   */
640  group9Layout7: function (pictures) {
641    return this.getHTML([
642      pictures.slice(0, 3),
643      pictures.slice(3, 6),
644      pictures.slice(6)
645    ]);
646  },
647
648  /**
649   * 10-1
650   *
651   *   □
652   * □ □ □
653   * □ □ □
654   * □ □ □
655   *
656   * @param pictures
657   */
658  group10Layout1: function (pictures) {
659    return this.getHTML([
660      pictures.slice(0, 1),
661      pictures.slice(1, 4),
662      pictures.slice(4, 7),
663      pictures.slice(7)
664    ]);
665  },
666
667  /**
668   * 10-2
669   *
670   *  □ □
671   *  □ □
672   * □ □ □
673   * □ □ □
674   *
675   * @param pictures
676   */
677  group10Layout2: function (pictures) {
678    return this.getHTML([
679      pictures.slice(0, 2),
680      pictures.slice(2, 4),
681      pictures.slice(4, 7),
682      pictures.slice(7)
683    ]);
684  },
685
686  /**
687   * 10-3
688   *
689   *  □ □
690   * □ □ □
691   *  □ □
692   * □ □ □
693   *
694   * @param pictures
695   */
696  group10Layout3: function (pictures) {
697    return this.getHTML([
698      pictures.slice(0, 2),
699      pictures.slice(2, 5),
700      pictures.slice(5, 7),
701      pictures.slice(7)
702    ]);
703  },
704
705  /**
706   * 10-4
707   *
708   *  □ □
709   * □ □ □
710   * □ □ □
711   *  □ □
712   *
713   * @param pictures
714   */
715  group10Layout4: function (pictures) {
716    return this.getHTML([
717      pictures.slice(0, 2),
718      pictures.slice(2, 5),
719      pictures.slice(5, 8),
720      pictures.slice(8)
721    ]);
722  },
723
724  /**
725   * 10-5
726   *
727   * □ □ □
728   *  □ □
729   *  □ □
730   * □ □ □
731   *
732   * @param pictures
733   */
734  group10Layout5: function (pictures) {
735    return this.getHTML([
736      pictures.slice(0, 3),
737      pictures.slice(3, 5),
738      pictures.slice(5, 7),
739      pictures.slice(7)
740    ]);
741  },
742
743  /**
744   * 10-6
745   *
746   * □ □ □
747   *  □ □
748   * □ □ □
749   *  □ □
750   *
751   * @param pictures
752   */
753  group10Layout6: function (pictures) {
754    return this.getHTML([
755      pictures.slice(0, 3),
756      pictures.slice(3, 5),
757      pictures.slice(5, 8),
758      pictures.slice(8)
759    ]);
760  },
761
762  /**
763   * 10-7
764   *
765   * □ □ □
766   * □ □ □
767   *  □ □
768   *  □ □
769   *
770   * @param pictures
771   */
772  group10Layout7: function (pictures) {
773    return this.getHTML([
774      pictures.slice(0, 3),
775      pictures.slice(3, 6),
776      pictures.slice(6, 8),
777      pictures.slice(8)
778    ]);
779  },
780
781  /**
782   * Defaults Layout
783   *
784   * □ □ □
785   * □ □ □
786   * ...
787   *
788   * @param pictures
789   */
790  defaults: function (pictures) {
791    var ROW_SIZE = 3;
792    var rows = pictures.length / ROW_SIZE + 1;
793    var pictureArr = [];
794
795    for (var i = 0; i < rows; i++) {
796      pictureArr.push(pictures.slice(i * ROW_SIZE, (i + 1) * ROW_SIZE));
797    }
798
799    return this.getHTML(pictureArr);
800  },
801
802  getHTML: function (rows) {
803    var rowHTML = '';
804
805    for (var i = 0; i < rows.length; i++) {
806      rowHTML += this.getRowHTML(rows[i]);
807    }
808
809    return '<div class="group-picture-container">' + rowHTML + '</div>';
810  },
811
812  getRowHTML: function (pictures) {
813    return (
814      '<div class="group-picture-row">' +
815        this.getColumnHTML(pictures) +
816      '</div>'
817    );
818  },
819
820  getColumnHTML: function (pictures) {
821    var columns = [];
822    var columnWidth = 100 / pictures.length;
823    var columnStyle = ' style="width: ' + columnWidth + '%;"';
824
825    for (var i = 0; i < pictures.length; i++) {
826      columns.push('<div class="group-picture-column" ' + columnStyle + '>' + pictures[i] + '</div>');
827    }
828    return columns.join('');
829  }
830};
831
832hexo.extend.tag.register('grouppicture', groupPicture, {ends: true});
833hexo.extend.tag.register('gp', groupPicture, {ends: true});
834
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Cypress on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)