@jamesrock/rockjs 1.15.0 → 1.17.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 +92 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -20,6 +20,7 @@ export const limit = (value, max) => value > max ? max : value;
20
20
  export const formatTime = (t) => `${pad(formatMinutes(t))}:${pad(formatSeconds(t))}`;
21
21
  export const formatNumber = (n) => formatter.format(n);
22
22
  export const formatCurrency = (n) => currencyFormatter.format(n);
23
+ export const formatDate = (date, type = 'short') => date.toLocaleDateString('en-GB', { dateStyle: type });
23
24
  export const getDateString = (type = 'short') => new Date().toLocaleDateString('en-GB', { dateStyle: type });
24
25
  export const getTimeString = (type = 'short') => new Date().toLocaleTimeString('en-GB', { timeStyle: type });
25
26
  export const getDateTimeString = (type = 'short') => `${getDateString(type)} ${getTimeString(type)}`;
@@ -62,9 +63,7 @@ const sortingMethods = {
62
63
  }
63
64
  };
64
65
 
65
- export const sort = (target, prop, method) => {
66
- return target.sort(sortingMethods[method](prop));
67
- };
66
+ export const sort = (target, prop, method) => target.sort(sortingMethods[method](prop));
68
67
 
69
68
  export const setDocumentHeight = () => {
70
69
  document.documentElement.style.height = window.navigator.standalone ? '100vh' : '100svh';
@@ -433,3 +432,93 @@ export class BrickMaker extends DisplayObject {
433
432
  };
434
433
  value = null;
435
434
  };
435
+
436
+ export class Collection extends Array {
437
+ constructor() {
438
+
439
+ super();
440
+
441
+ };
442
+ getItemByKeyValue(key, value) {
443
+
444
+ return this.filter((item) => item[key]===value)[0];
445
+
446
+ };
447
+ getItemsByKeyValue(key, value) {
448
+
449
+ return this.filter((item) => item[key]===value);
450
+
451
+ };
452
+ append(item) {
453
+
454
+ this.push(item);
455
+ return item;
456
+
457
+ };
458
+ prepend(item) {
459
+
460
+ this.unshift(item);
461
+ return item;
462
+
463
+ };
464
+ exists(value) {
465
+
466
+ return (this.indexOf(value)>-1);
467
+
468
+ };
469
+ random() {
470
+
471
+ return getRandom(this);
472
+
473
+ };
474
+ remove(item) {
475
+
476
+ return this.removeAt(this.getIndexOf(item));
477
+
478
+ };
479
+ removeAt(index) {
480
+
481
+ this.splice(index, 1);
482
+ return this;
483
+
484
+ };
485
+ addAt(item, index) {
486
+
487
+ this.splice(index, 0, item);
488
+ return item;
489
+
490
+ };
491
+ first() {
492
+
493
+ return this[0];
494
+
495
+ };
496
+ last() {
497
+
498
+ return this[this.length-1];
499
+
500
+ };
501
+ swap(aIndex, bIndex) {
502
+
503
+ var
504
+ aProp = this[aIndex],
505
+ bProp = this[bIndex];
506
+
507
+ this[aIndex] = bProp;
508
+ this[bIndex] = aProp;
509
+
510
+ return this;
511
+
512
+ };
513
+ pushift() {
514
+
515
+ this.push(this.shift());
516
+ return this;
517
+
518
+ };
519
+ shuffle() {
520
+
521
+ return shuffle(this);
522
+
523
+ };
524
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",