@jamesrock/rockjs 1.5.0 → 1.6.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 +13 -13
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -10,6 +10,8 @@ export const pluckRandom = (a) => a.splice(randomIndex(a), 1)[0];
10
10
  export const pluckFirst = (a) => a.splice(0, 1)[0];
11
11
  export const pluckLast = (a) => a.splice(a.length-1, 1)[0];
12
12
  export const getRandom = (a) => a[randomIndex(a)];
13
+ export const getFirst = (a) => a[0];
14
+ export const getLast = (a) => a[a.length-1];
13
15
  export const isLandscape = () => window.matchMedia('(orientation: landscape)').matches;
14
16
  export const isTiny = () => !window.matchMedia('(min-width: 450px)').matches;
15
17
  export const isDarkMode = () => window.matchMedia('(prefers-color-scheme: dark)').matches;
@@ -18,20 +20,18 @@ export const limit = (value, max) => value > max ? max : value;
18
20
  export const formatTime = (t) => `${pad(formatMinutes(t))}:${pad(formatSeconds(t))}`;
19
21
  export const formatNumber = (n) => formatter.format(n);
20
22
  export const formatCurrency = (n) => currencyFormatter.format(n);
21
- export const getDateString = () => new Date().toLocaleDateString('en-GB', { year: 'numeric', month: 'numeric', day: 'numeric'});
22
- export const isValidKey = (key, options) => (options.includes(key));
23
- export const shuffle = (array) => {
24
- for(let i = array.length - 1; i > 0; i--) {
25
- const j = Math.floor(Math.random() * (i + 1));
26
- const temp = array[i];
27
- array[i] = array[j];
28
- array[j] = temp;
23
+ export const getDateString = (type = 'short') => new Date().toLocaleDateString('en-GB', { dateStyle: type });
24
+ export const getTimeString = (type = 'short') => new Date().toLocaleTimeString('en-GB', { timeStyle: type });
25
+ export const getDateTimeString = (type = 'short') => `${getDateString(type)} ${getTimeString(type)}`;
26
+ export const isValidKey = (key, options) => options.includes(key);
27
+ export const makeArray = (length, mapper = (a, i) => i) => Array.from({length}, mapper);
28
+
29
+ export const shuffle = (a) => {
30
+ for(let i = 0; i < a.length; i++) {
31
+ const b = Math.floor(Math.random() * a.length);
32
+ [a[i], a[b]] = [a[b], a[i]];
29
33
  };
30
- return array;
31
- };
32
-
33
- export const makeArray = (length, mapper = (a, i) => i) => {
34
- return Array.from({length}, mapper);
34
+ return a;
35
35
  };
36
36
 
37
37
  export const createNode = (type, className) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",