@jamesrock/rockjs 1.16.0 → 1.18.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 +8 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,7 +1,4 @@
1
- const formatMinutes = (time) => Math.floor((time % (1000 * 60 * 60)) / (1000 * 60));
2
- const formatSeconds = (time) => Math.floor((time % (1000 * 60)) / 1000);
3
- const pad = (time) => time.toString().padStart(2, '0');
4
- const formatter = new Intl.NumberFormat('en-GB');
1
+ const numberFormatter = new Intl.NumberFormat('en-GB');
5
2
  const currencyFormatter = new Intl.NumberFormat('en-GB', {style: 'currency', currency: 'GBP'});
6
3
 
7
4
  export const random = (min, max) => (Math.floor(Math.random()*((max-min)+1))+min);
@@ -17,10 +14,14 @@ export const isTiny = () => !window.matchMedia('(min-width: 450px)').matches;
17
14
  export const isDarkMode = () => window.matchMedia('(prefers-color-scheme: dark)').matches;
18
15
  export const makeEven = (value) => value % 2 === 1 ? value - 1 : value;
19
16
  export const limit = (value, max) => value > max ? max : value;
20
- export const formatTime = (t) => `${pad(formatMinutes(t))}:${pad(formatSeconds(t))}`;
21
- export const formatNumber = (n) => formatter.format(n);
17
+ 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
+ export const formatNumber = (n) => numberFormatter.format(n);
22
22
  export const formatCurrency = (n) => currencyFormatter.format(n);
23
- export const getDateString = (type = 'short') => new Date().toLocaleDateString('en-GB', { dateStyle: type });
23
+ export const formatDate = (date, type = 'short') => date.toLocaleDateString('en-GB', { dateStyle: type });
24
+ export const getDateString = (type = 'short') => formatDate(new Date(), 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)}`;
26
27
  export const isValidKey = (key, options) => options.includes(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",