@onsvisual/svelte-components 0.1.106 → 0.1.107
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/dist/js/utils.js +32 -20
- package/package.json +1 -1
package/dist/js/utils.js
CHANGED
|
@@ -55,31 +55,43 @@ export const formatter = (dp = null) => {
|
|
|
55
55
|
: new Intl.NumberFormat("en-GB").format;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
// Functions for natural sorting, regardless of type
|
|
59
|
+
// Less performant than d3.ascending and d3.descending, but handles mixed types
|
|
60
|
+
const collator = new Intl.Collator("en", { numeric: true });
|
|
61
|
+
const isSortable = (a, b) =>
|
|
62
|
+
typeof a === typeof b &&
|
|
63
|
+
(["number", "string", "boolean"].includes(typeof a) ||
|
|
64
|
+
(typeof a.getMonth === "function" && typeof b.getMonth === "function"));
|
|
65
|
+
|
|
58
66
|
export const ascending = (a, b) =>
|
|
59
|
-
a
|
|
67
|
+
a === b
|
|
68
|
+
? 0
|
|
69
|
+
: a == null
|
|
70
|
+
? 1
|
|
71
|
+
: b == null
|
|
72
|
+
? -1
|
|
73
|
+
: !isSortable(a, b)
|
|
74
|
+
? collator.compare(a, b)
|
|
75
|
+
: a < b
|
|
76
|
+
? -1
|
|
77
|
+
: a > b
|
|
60
78
|
? 1
|
|
61
|
-
:
|
|
62
|
-
? -1
|
|
63
|
-
: a < b
|
|
64
|
-
? -1
|
|
65
|
-
: a > b
|
|
66
|
-
? 1
|
|
67
|
-
: a >= b
|
|
68
|
-
? 0
|
|
69
|
-
: NaN;
|
|
79
|
+
: 0;
|
|
70
80
|
|
|
71
81
|
export const descending = (a, b) =>
|
|
72
|
-
a
|
|
82
|
+
a === b
|
|
83
|
+
? 0
|
|
84
|
+
: a == null
|
|
85
|
+
? 1
|
|
86
|
+
: b == null
|
|
87
|
+
? -1
|
|
88
|
+
: !isSortable(a, b)
|
|
89
|
+
? collator.compare(b, a)
|
|
90
|
+
: b < a
|
|
91
|
+
? -1
|
|
92
|
+
: b > a
|
|
73
93
|
? 1
|
|
74
|
-
:
|
|
75
|
-
? -1
|
|
76
|
-
: b < a
|
|
77
|
-
? -1
|
|
78
|
-
: b > a
|
|
79
|
-
? 1
|
|
80
|
-
: b >= a
|
|
81
|
-
? 0
|
|
82
|
-
: NaN;
|
|
94
|
+
: 0;
|
|
83
95
|
|
|
84
96
|
export const sleep = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
85
97
|
|