svelte-common 4.11.0 → 4.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "4.11.0",
3
+ "version": "4.12.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,7 +42,7 @@
42
42
  "@sveltejs/vite-plugin-svelte": "^1.0.2",
43
43
  "ava": "^4.3.1",
44
44
  "documentation": "^14.0.0",
45
- "mf-styling": "^1.3.1",
45
+ "mf-styling": "^1.4.0",
46
46
  "npm-pkgbuild": "^10.14.8",
47
47
  "semantic-release": "^19.0.4",
48
48
  "stylelint": "^14.11.0",
package/src/index.svelte CHANGED
@@ -45,6 +45,7 @@
45
45
  formatSecondsSinceEpoch
46
46
  } from "./util.mjs";
47
47
  export {
48
+ sorter,
48
49
  sortable,
49
50
  toggleOrderBy,
50
51
  orderByCycle,
package/src/sorting.mjs CHANGED
@@ -21,9 +21,9 @@ export function toggleOrderBy(orderBy) {
21
21
 
22
22
  /**
23
23
  * Add sortable toggle to a node.
24
- * Synchronizes store value with node sortable attribute.
24
+ * Synchronizes store value with node "aria-sort" attribute.
25
25
  * @param {Node} node
26
- * @param {Store} where to keep in sync with sorting properties
26
+ * @param {Store} to keep in sync with sorting properties
27
27
  */
28
28
  export function sortable(node, store) {
29
29
  node.setAttribute("aria-sort", SORT_NONE);
@@ -60,3 +60,20 @@ export function sortable(node, store) {
60
60
  store.set(orderBy);
61
61
  };
62
62
  }
63
+
64
+ /**
65
+ * Generate a sort function for a given sort by set.
66
+ * @param {Object} sortBy
67
+ * @return {Function} sorter
68
+ */
69
+ export function sorter(sortBy)
70
+ {
71
+ for(const [key,value] of Object.entries(sortBy)) {
72
+ switch(value) {
73
+ case SORT_ASCENDING:
74
+ return (a,b) => a[key].localeCompare(b[key]);
75
+ case SORT_DESCENDING:
76
+ return (b,a) => a[key].localeCompare(b[key]);
77
+ }
78
+ }
79
+ }