@onsvisual/svelte-components 0.1.105 → 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 CHANGED
@@ -55,11 +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 == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
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
78
+ ? 1
79
+ : 0;
60
80
 
61
81
  export const descending = (a, b) =>
62
- a == null || b == null ? NaN : b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
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
93
+ ? 1
94
+ : 0;
63
95
 
64
96
  export const sleep = (ms = 1000) => new Promise((resolve) => setTimeout(resolve, ms));
65
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onsvisual/svelte-components",
3
- "version": "0.1.105",
3
+ "version": "0.1.107",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://onsvisual.github.io/svelte-components",
@@ -146,7 +146,7 @@
146
146
  "./layout/Accordion/Accordion.svelte": "./dist/layout/Accordion/Accordion.svelte",
147
147
  "./layout/Accordion/AccordionItem.svelte": "./dist/layout/Accordion/AccordionItem.svelte",
148
148
  "./layout/AnalyticsBanner/AnalyticsBanner.svelte": "./dist/layout/AnalyticsBanner/AnalyticsBanner.svelte",
149
- "./layout/Backlink/Backlink.svelte": "./dist/layout/Backlink/Backlink.svelte",
149
+ "./layout/BackLink/Backlink.svelte": "./dist/layout/BackLink/Backlink.svelte",
150
150
  "./layout/Breadcrumb/Breadcrumb.svelte": "./dist/layout/Breadcrumb/Breadcrumb.svelte",
151
151
  "./layout/Cards/Card.svelte": "./dist/layout/Cards/Card.svelte",
152
152
  "./layout/Cards/Cards.svelte": "./dist/layout/Cards/Cards.svelte",