@jamesrock/rockjs 1.15.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +91 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -62,9 +62,7 @@ const sortingMethods = {
62
62
  }
63
63
  };
64
64
 
65
- export const sort = (target, prop, method) => {
66
- return target.sort(sortingMethods[method](prop));
67
- };
65
+ export const sort = (target, prop, method) => target.sort(sortingMethods[method](prop));
68
66
 
69
67
  export const setDocumentHeight = () => {
70
68
  document.documentElement.style.height = window.navigator.standalone ? '100vh' : '100svh';
@@ -433,3 +431,93 @@ export class BrickMaker extends DisplayObject {
433
431
  };
434
432
  value = null;
435
433
  };
434
+
435
+ export class Collection extends Array {
436
+ constructor() {
437
+
438
+ super();
439
+
440
+ };
441
+ getItemByKeyValue(key, value) {
442
+
443
+ return this.filter((item) => item[key]===value)[0];
444
+
445
+ };
446
+ getItemsByKeyValue(key, value) {
447
+
448
+ return this.filter((item) => item[key]===value);
449
+
450
+ };
451
+ append(item) {
452
+
453
+ this.push(item);
454
+ return item;
455
+
456
+ };
457
+ prepend(item) {
458
+
459
+ this.unshift(item);
460
+ return item;
461
+
462
+ };
463
+ exists(value) {
464
+
465
+ return (this.indexOf(value)>-1);
466
+
467
+ };
468
+ random() {
469
+
470
+ return getRandom(this);
471
+
472
+ };
473
+ remove(item) {
474
+
475
+ return this.removeAt(this.getIndexOf(item));
476
+
477
+ };
478
+ removeAt(index) {
479
+
480
+ this.splice(index, 1);
481
+ return this;
482
+
483
+ };
484
+ addAt(item, index) {
485
+
486
+ this.splice(index, 0, item);
487
+ return item;
488
+
489
+ };
490
+ first() {
491
+
492
+ return this[0];
493
+
494
+ };
495
+ last() {
496
+
497
+ return this[this.length-1];
498
+
499
+ };
500
+ swap(aIndex, bIndex) {
501
+
502
+ var
503
+ aProp = this[aIndex],
504
+ bProp = this[bIndex];
505
+
506
+ this[aIndex] = bProp;
507
+ this[bIndex] = aProp;
508
+
509
+ return this;
510
+
511
+ };
512
+ pushift() {
513
+
514
+ this.push(this.shift());
515
+ return this;
516
+
517
+ };
518
+ shuffle() {
519
+
520
+ return shuffle(this);
521
+
522
+ };
523
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",