svelte-common 4.17.7 → 4.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.
package/README.md CHANGED
@@ -70,7 +70,7 @@ Synchronizes store value with node "aria-sort" attribute.
70
70
 
71
71
  ## sorter
72
72
 
73
- Generate a sort function for a given sort by set.
73
+ Generate a sort function for a given sort-by set.
74
74
 
75
75
  ### Parameters
76
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-common",
3
- "version": "4.17.7",
3
+ "version": "4.18.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,13 +42,13 @@
42
42
  "@sveltejs/vite-plugin-svelte": "^1.0.3",
43
43
  "ava": "^4.3.3",
44
44
  "documentation": "^14.0.0",
45
- "mf-styling": "^1.7.5",
45
+ "mf-styling": "^1.7.6",
46
46
  "npm-pkgbuild": "^10.14.8",
47
47
  "semantic-release": "^19.0.5",
48
48
  "stylelint": "^14.11.0",
49
49
  "stylelint-config-standard": "^28.0.0",
50
50
  "svelte": "^3.49.0",
51
- "testcafe": "^1.20.1",
51
+ "testcafe": "^2.0.0",
52
52
  "vite": "^3.0.9"
53
53
  },
54
54
  "optionalDependencies": {
package/src/index.svelte CHANGED
@@ -38,7 +38,8 @@
38
38
  formatBytes,
39
39
  formatDuration,
40
40
  formatDurationISO,
41
- formatSecondsSinceEpoch
41
+ formatSecondsSinceEpoch,
42
+ keyPrefixStore
42
43
  } from "./util.mjs";
43
44
  export {
44
45
  sorter,
package/src/util.mjs CHANGED
@@ -94,3 +94,38 @@ function liveDuration(seconds) {
94
94
  }
95
95
 
96
96
  */
97
+
98
+ /**
99
+ * Create a store where al the object keys are prefixed
100
+ * @param {WriteableStore} store
101
+ * @param {string} prefix
102
+ * @returns {WriteableStore}
103
+ */
104
+ export function keyPrefixStore(store, prefix) {
105
+ const subscriptions = new Set();
106
+
107
+ store.subscribe(prefixedKeyObject => {
108
+ const object = Object.fromEntries(
109
+ Object.entries(prefixedKeyObject).map(([k, v]) => [
110
+ k.substring(prefix.length),
111
+ v
112
+ ])
113
+ );
114
+
115
+ subscriptions.forEach(subscription => subscription(object));
116
+ });
117
+
118
+ return {
119
+ set: object => {
120
+ const prefixedKeyObject = Object.fromEntries(
121
+ Object.entries(object).map(([k, v]) => [prefix + k, v])
122
+ );
123
+ store.set(prefixedKeyObject);
124
+ },
125
+
126
+ subscribe: s => {
127
+ subscriptions.add(s);
128
+ return () => subscriptions.delete(s);
129
+ }
130
+ };
131
+ }