@jamesrock/rockjs 1.22.0 → 1.23.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 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,15 +9,17 @@ export const pluckLast = (a) => a.splice(a.length-1, 1)[0];
|
|
|
9
9
|
export const getRandom = (a) => a[randomIndex(a)];
|
|
10
10
|
export const getFirst = (a) => a[0];
|
|
11
11
|
export const getLast = (a) => a[a.length-1];
|
|
12
|
-
export const
|
|
13
|
-
export const
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
16
|
-
export const
|
|
12
|
+
export const isOrientation = (orientation) => matchMedia(`(orientation: ${orientation})`).matches;
|
|
13
|
+
export const maxWidth = (width) => matchMedia(`(max-width: ${width}px)`).matches;
|
|
14
|
+
export const minWidth = (width) => matchMedia(`(min-width: ${width}px)`).matches;
|
|
15
|
+
export const isColorScheme = (colorScheme) => matchMedia(`(prefers-color-scheme: ${colorScheme})`).matches;
|
|
16
|
+
export const isLandscape = () => isOrientation('landscape');
|
|
17
|
+
export const isPortrait = () => isOrientation('portrait');
|
|
18
|
+
export const isTiny = () => !minWidth(450);
|
|
19
|
+
export const isDarkMode = () => isColorScheme('dark');
|
|
20
|
+
export const makeEven = (a) => (a % 2 === 1 ? a - 1 : a);
|
|
21
|
+
export const limit = (value, max) => (value > max ? max : value);
|
|
17
22
|
export const toDouble = (a) => a.toString().padStart(2, '0');
|
|
18
|
-
export const formatMinutes = (ms) => toDouble(Math.floor((ms % (1000 * 60 * 60)) / (1000 * 60)));
|
|
19
|
-
export const formatSeconds = (ms) => toDouble(Math.floor((ms % (1000 * 60)) / 1000));
|
|
20
|
-
export const formatTime = (ms) => `${formatMinutes(ms)}:${formatSeconds(ms)}`;
|
|
21
23
|
export const formatNumber = (n) => numberFormatter.format(n);
|
|
22
24
|
export const formatCurrency = (n) => currencyFormatter.format(n);
|
|
23
25
|
export const formatDate = (date, type = 'short') => date.toLocaleDateString('en-GB', { dateStyle: type });
|
|
@@ -31,6 +33,10 @@ export const roundTo = (number, to = 1) => (Math.round(number*to)/to);
|
|
|
31
33
|
export const ceilTo = (number, to = 1) => (Math.ceil(number*to)/to);
|
|
32
34
|
export const getXPercentOfY = (x, y) => (y*(x/100));
|
|
33
35
|
export const getXAsPercentOfY = (x, y) => ((x/y)*100);
|
|
36
|
+
// to be removed
|
|
37
|
+
export const formatMinutes = (ms) => toDouble(Math.floor((ms % (1000 * 60 * 60)) / (1000 * 60)));
|
|
38
|
+
export const formatSeconds = (ms) => toDouble(Math.floor((ms % (1000 * 60)) / 1000));
|
|
39
|
+
export const formatTime = (ms) => `${formatMinutes(ms)}:${formatSeconds(ms)}`;
|
|
34
40
|
|
|
35
41
|
const sortingMethods = {
|
|
36
42
|
'0-9': (prop) => (a, b) => prop(a)-prop(b),
|