@budibase/bbui 1.0.26 → 1.0.27-alpha.3

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/src/index.js CHANGED
@@ -59,6 +59,7 @@ export { default as Badge } from "./Badge/Badge.svelte"
59
59
  export { default as StatusLight } from "./StatusLight/StatusLight.svelte"
60
60
  export { default as ColorPicker } from "./ColorPicker/ColorPicker.svelte"
61
61
  export { default as InlineAlert } from "./InlineAlert/InlineAlert.svelte"
62
+ export { default as Banner } from "./Banner/Banner.svelte"
62
63
 
63
64
  // Typography
64
65
  export { default as Body } from "./Typography/Body.svelte"
@@ -76,3 +77,6 @@ export { default as clickOutside } from "./Actions/click_outside"
76
77
 
77
78
  // Stores
78
79
  export { notifications, createNotificationStore } from "./Stores/notifications"
80
+
81
+ // Utils
82
+ export * from "./utils/helpers"
@@ -6,3 +6,61 @@ export const generateID = () => {
6
6
  }
7
7
 
8
8
  export const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1)
9
+
10
+ /**
11
+ * Gets a key within an object. The key supports dot syntax for retrieving deep
12
+ * fields - e.g. "a.b.c".
13
+ * Exact matches of keys with dots in them take precedence over nested keys of
14
+ * the same path - e.g. getting "a.b" from { "a.b": "foo", a: { b: "bar" } }
15
+ * will return "foo" over "bar".
16
+ * @param obj the object
17
+ * @param key the key
18
+ * @return {*|null} the value or null if a value was not found for this key
19
+ */
20
+ export const deepGet = (obj, key) => {
21
+ if (!obj || !key) {
22
+ return null
23
+ }
24
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
25
+ return obj[key]
26
+ }
27
+ const split = key.split(".")
28
+ for (let i = 0; i < split.length; i++) {
29
+ obj = obj?.[split[i]]
30
+ }
31
+ return obj
32
+ }
33
+
34
+ /**
35
+ * Sets a key within an object. The key supports dot syntax for retrieving deep
36
+ * fields - e.g. "a.b.c".
37
+ * Exact matches of keys with dots in them take precedence over nested keys of
38
+ * the same path - e.g. setting "a.b" of { "a.b": "foo", a: { b: "bar" } }
39
+ * will override the value "foo" rather than "bar".
40
+ * If a deep path is specified and the parent keys don't exist then these will
41
+ * be created.
42
+ * @param obj the object
43
+ * @param key the key
44
+ * @param value the value
45
+ */
46
+ export const deepSet = (obj, key, value) => {
47
+ if (!obj || !key) {
48
+ return
49
+ }
50
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
51
+ obj[key] = value
52
+ return
53
+ }
54
+ const split = key.split(".")
55
+ for (let i = 0; i < split.length - 1; i++) {
56
+ const nextKey = split[i]
57
+ if (obj && obj[nextKey] == null) {
58
+ obj[nextKey] = {}
59
+ }
60
+ obj = obj?.[nextKey]
61
+ }
62
+ if (!obj) {
63
+ return
64
+ }
65
+ obj[split[split.length - 1]] = value
66
+ }