@jamesrock/rockjs 1.3.0 → 1.4.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.
- package/index.js +14 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const formatMinutes = (time) => Math.floor((time % (1000 * 60 * 60)) / (1000 * 60));
|
|
2
|
+
const formatSeconds = (time) => Math.floor((time % (1000 * 60)) / 1000);
|
|
3
3
|
const pad = (time) => time.toString().padStart(2, '0');
|
|
4
4
|
const formatter = new Intl.NumberFormat('en-GB');
|
|
5
|
+
const currencyFormatter = new Intl.NumberFormat('en-GB', {style: 'currency', currency: 'GBP'});
|
|
5
6
|
|
|
6
7
|
export const random = (min, max) => (Math.floor(Math.random()*((max-min)+1))+min);
|
|
7
8
|
export const randomIndex = (a) => random(0, a.length-1);
|
|
@@ -11,10 +12,11 @@ export const pluckLast = (a) => a.splice(a.length-1, 1)[0];
|
|
|
11
12
|
export const getRandom = (a) => a[randomIndex(a)];
|
|
12
13
|
export const isLandscape = () => window.matchMedia('(orientation: landscape)').matches;
|
|
13
14
|
export const isTiny = () => !window.matchMedia('(min-width: 450px)').matches;
|
|
14
|
-
export const timeToDisplay = (time) => `${pad(timeToMinutes(time))}:${pad(timeToSeconds(time))}`;
|
|
15
15
|
export const makeEven = (value) => value % 2 === 1 ? value - 1 : value;
|
|
16
16
|
export const limit = (value, max) => value > max ? max : value;
|
|
17
|
+
export const formatTime = (t) => `${pad(formatMinutes(t))}:${pad(formatSeconds(t))}`;
|
|
17
18
|
export const formatNumber = (n) => formatter.format(n);
|
|
19
|
+
export const formatCurrency = (n) => currencyFormatter.format(n);
|
|
18
20
|
export const shuffle = (array) => {
|
|
19
21
|
for(let i = array.length - 1; i > 0; i--) {
|
|
20
22
|
const j = Math.floor(Math.random() * (i + 1));
|
|
@@ -26,7 +28,7 @@ export const shuffle = (array) => {
|
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
export const makeArray = (length, mapper = (a, i) => i) => {
|
|
29
|
-
return Array.from({length}
|
|
31
|
+
return Array.from({length}, mapper);
|
|
30
32
|
};
|
|
31
33
|
|
|
32
34
|
export const createNode = (type, className) => {
|
|
@@ -44,24 +46,24 @@ export const createButton = (label = '{label}', className) => {
|
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
export const createInput = (value = 0, type = 'number') => {
|
|
47
|
-
const input =
|
|
49
|
+
const input = createNode('input');
|
|
48
50
|
input.type = type;
|
|
49
51
|
input.value = value;
|
|
50
52
|
return input;
|
|
51
53
|
};
|
|
52
54
|
|
|
53
|
-
export const createOutput = () => {
|
|
54
|
-
const textarea =
|
|
55
|
-
textarea.rows =
|
|
55
|
+
export const createOutput = (rows = 7) => {
|
|
56
|
+
const textarea = createNode('textarea');
|
|
57
|
+
textarea.rows = rows;
|
|
56
58
|
return textarea;
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
export const createContainer = (className
|
|
61
|
+
export const createContainer = (className) => {
|
|
60
62
|
return createNode('div', className);
|
|
61
63
|
};
|
|
62
64
|
|
|
63
65
|
export const createSelect = (options) => {
|
|
64
|
-
const node =
|
|
66
|
+
const node = createNode('select');
|
|
65
67
|
options.forEach(([label, value]) => {
|
|
66
68
|
const option = createOption(label, value);
|
|
67
69
|
node.appendChild(option);
|
|
@@ -69,8 +71,8 @@ export const createSelect = (options) => {
|
|
|
69
71
|
return node;
|
|
70
72
|
};
|
|
71
73
|
|
|
72
|
-
const createOption = (label = '', value =
|
|
73
|
-
const node =
|
|
74
|
+
const createOption = (label = '{label}', value = 0) => {
|
|
75
|
+
const node = createNode('option');
|
|
74
76
|
node.innerText = label;
|
|
75
77
|
node.value = value;
|
|
76
78
|
return node;
|