@jamesrock/rockjs 1.33.0 → 1.35.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 +51 -61
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -33,10 +33,6 @@ export const roundTo = (number, to = 1) => (Math.round(number*to)/to);
33
33
  export const ceilTo = (number, to = 1) => (Math.ceil(number*to)/to);
34
34
  export const getXPercentOfY = (x, y) => (y*(x/100));
35
35
  export const getXAsPercentOfY = (x, y) => ((x/y)*100);
36
- // to be removed
37
- export const formatMinutes = (ms) => pad(Math.floor((ms % (1000 * 60 * 60)) / (1000 * 60)));
38
- export const formatSeconds = (ms) => pad(Math.floor((ms % (1000 * 60)) / 1000));
39
- export const formatTime = (ms) => `${formatMinutes(ms)}:${formatSeconds(ms)}`;
40
36
 
41
37
  const sortingMethods = {
42
38
  '0-9': (prop) => (a, b) => prop(a)-prop(b),
@@ -113,6 +109,23 @@ export const makeInput = (value = 0, type = 'number') => {
113
109
  return input;
114
110
  };
115
111
 
112
+ export const makeRadio = (value = 0, name = '{name}', id = '{id}', checked = false) => {
113
+ const node = makeInput(value, 'radio');
114
+ node.name = name;
115
+ node.id = id;
116
+ node.checked = checked;
117
+ return node;
118
+ };
119
+
120
+ export const makeSlider = (value, min, max, step = 1) => {
121
+ const node = makeInput(0, 'range');
122
+ node.min = min;
123
+ node.max = max;
124
+ node.step = step;
125
+ node.value = value;
126
+ return node;
127
+ };
128
+
116
129
  export const makeOutput = (rows = 7) => {
117
130
  const node = makeNode('textarea');
118
131
  node.rows = rows;
@@ -151,14 +164,6 @@ export const makeLink = (href = '{href}', label = '{label}', className) => {
151
164
  return node;
152
165
  };
153
166
 
154
- export const makeRadio = (value = 0, name = '{name}', id = '{id}', checked = false) => {
155
- const node = makeInput(value, 'radio');
156
- node.name = name;
157
- node.id = id;
158
- node.checked = checked;
159
- return node;
160
- };
161
-
162
167
  export const makeLabel = (label = '{label}', id = '{id}', className) => {
163
168
  const node = makeNode('label', className);
164
169
  node.innerHTML = label;
@@ -262,6 +267,22 @@ export const addDragListeners = (target, tolerance) => {
262
267
 
263
268
  };
264
269
 
270
+ export const append = (target) => {
271
+ const fn = (node) => {
272
+ target.appendChild(node);
273
+ return fn;
274
+ };
275
+ return fn;
276
+ };
277
+
278
+ export const appendTo = (target) => {
279
+ const fn = (node) => {
280
+ node.appendTo(target);
281
+ return fn;
282
+ };
283
+ return fn;
284
+ };
285
+
265
286
  export class Storage {
266
287
  constructor(namespace) {
267
288
 
@@ -646,60 +667,28 @@ export class Collection extends Array {
646
667
  };
647
668
 
648
669
  export class Time {
670
+ constructor(accuracy = 1) {
671
+ this.accuracy = accuracy;
672
+ };
649
673
  second = 1000;
650
674
  minute = (this.second * 60);
651
675
  hour = (this.minute * 60);
652
676
  day = (this.hour * 24);
653
677
  year = (this.day * 365);
654
- getSeconds(ms) {
655
- return floorTo(ms / this.second);
656
- };
657
- getMinutes(ms) {
658
- return floorTo(ms / this.minute);
659
- };
660
- getHours(ms) {
661
- return floorTo(ms / this.hour);
662
- };
663
- getDays(ms) {
664
- return floorTo(ms / this.day);
665
- };
666
- getYears(ms) {
667
- return floorTo(ms / this.year);
668
- };
669
- getMillisecondsInHour(ms) {
670
- return (ms % this.hour);
671
- };
672
- getMillisecondsInMinute(ms) {
673
- return (ms % this.minute);
674
- };
675
- getMillisecondsInDay(ms) {
676
- return (ms % this.day);
677
- };
678
- getMillisecondsInYear(ms) {
679
- return (ms % this.year);
680
- };
681
- getSecondsInDay(ms) {
682
- return this.getSeconds(this.getMillisecondsInDay(ms));
683
- };
684
- getMinutesInDay(ms) {
685
- return this.getMinutes(this.getMillisecondsInDay(ms));
686
- };
687
- getHoursInDay(ms) {
688
- return this.getHours(this.getMillisecondsInDay(ms));
689
- };
690
- getDaysInYear(ms) {
691
- return this.getDays(this.getMillisecondsInYear(ms));
692
- };
693
- getMinutesInHour(ms) {
694
- return this.getMinutes(this.getMillisecondsInHour(ms));
695
- };
696
- getSecondsInMinute(ms) {
697
- return this.getSeconds(this.getMillisecondsInMinute(ms));
698
- };
699
- formatSeconds = (ms) => pad(this.getSecondsInMinute(ms));
700
- formatMinutes = (ms) => pad(this.getMinutesInHour(ms));
701
- formatHours = (ms) => pad(this.getHoursInDay(ms));
702
- format = (ms) => `${this.formatMinutes(ms)}:${this.formatSeconds(ms)}`;
678
+ getSeconds = (ms) => floorTo(ms / this.second, this.accuracy);
679
+ getMinutes = (ms) => floorTo(ms / this.minute, this.accuracy);
680
+ getHours = (ms) => floorTo(ms / this.hour, this.accuracy);
681
+ getDays = (ms) => floorTo(ms / this.day, this.accuracy);
682
+ getYears = (ms) => floorTo(ms / this.year, this.accuracy);
683
+ getMillisecondsInMinute = (ms) => (ms % this.minute);
684
+ getMillisecondsInHour = (ms) => (ms % this.hour);
685
+ getMillisecondsInDay = (ms) => (ms % this.day);
686
+ getMillisecondsInYear = (ms) => (ms % this.year);
687
+ getHoursInDay = (ms) => this.getHours(this.getMillisecondsInDay(ms));
688
+ getDaysInYear = (ms) => this.getDays(this.getMillisecondsInYear(ms));
689
+ getMinutesInHour = (ms) => this.getMinutes(this.getMillisecondsInHour(ms));
690
+ getSecondsInMinute = (ms) => this.getSeconds(this.getMillisecondsInMinute(ms));
691
+ format = (ms) => `${pad(this.getMinutesInHour(ms))}:${pad(this.getSecondsInMinute(ms))}`;
703
692
  };
704
693
 
705
694
  export class PlayingCard extends DisplayObject {
@@ -921,3 +910,4 @@ export const createOption = makeOption;
921
910
  export const createHeading = makeHeading;
922
911
  export const createRadio = makeRadio;
923
912
  export const createLabel = makeLabel;
913
+ export const formatTime = (ms) => new Time().format(ms);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.33.0",
3
+ "version": "1.35.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",