@sprucelabs/schema 30.1.3 → 30.2.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.
@@ -3,13 +3,21 @@ export default function flattenValues(values, ignoreKeys) {
3
3
  return flattened;
4
4
  }
5
5
  function flattenValue(values, prefix = '', ignoreKeys) {
6
+ var _a;
6
7
  const keys = Object.keys(values);
7
8
  let flattened = {};
8
9
  for (const key of keys) {
9
10
  const value = values[key];
10
- const dotKey = prefix ? `${prefix}.${key}` : key;
11
- if (value && typeof value === 'object' && !(ignoreKeys === null || ignoreKeys === void 0 ? void 0 : ignoreKeys.includes(key))) {
12
- flattened = { ...flattened, ...flattenValue(value, dotKey) };
11
+ const isWildCardIgnored = (_a = ignoreKeys === null || ignoreKeys === void 0 ? void 0 : ignoreKeys.includes(`*.${key}`)) !== null && _a !== void 0 ? _a : false;
12
+ const dotKey = prefix && !isWildCardIgnored ? `${prefix}.${key}` : key;
13
+ if (shouldFlatten(value, ignoreKeys, key)) {
14
+ flattened = {
15
+ ...flattened,
16
+ ...flattenValue(value, dotKey, ignoreKeys),
17
+ };
18
+ }
19
+ else if (isWildCardIgnored) {
20
+ flattened[prefix] = { ...flattened[prefix], [key]: value };
13
21
  }
14
22
  else {
15
23
  flattened[dotKey] = value;
@@ -17,3 +25,6 @@ function flattenValue(values, prefix = '', ignoreKeys) {
17
25
  }
18
26
  return flattened;
19
27
  }
28
+ function shouldFlatten(value, ignoreKeys, key) {
29
+ return value && typeof value === 'object' && !(ignoreKeys === null || ignoreKeys === void 0 ? void 0 : ignoreKeys.includes(key));
30
+ }
@@ -10,9 +10,16 @@ function flattenValue(values, prefix = '', ignoreKeys) {
10
10
  let flattened = {};
11
11
  for (const key of keys) {
12
12
  const value = values[key];
13
- const dotKey = prefix ? `${prefix}.${key}` : key;
14
- if (value && typeof value === 'object' && !ignoreKeys?.includes(key)) {
15
- flattened = { ...flattened, ...flattenValue(value, dotKey) };
13
+ const isWildCardIgnored = ignoreKeys?.includes(`*.${key}`) ?? false;
14
+ const dotKey = prefix && !isWildCardIgnored ? `${prefix}.${key}` : key;
15
+ if (shouldFlatten(value, ignoreKeys, key)) {
16
+ flattened = {
17
+ ...flattened,
18
+ ...flattenValue(value, dotKey, ignoreKeys),
19
+ };
20
+ }
21
+ else if (isWildCardIgnored) {
22
+ flattened[prefix] = { ...flattened[prefix], [key]: value };
16
23
  }
17
24
  else {
18
25
  flattened[dotKey] = value;
@@ -20,3 +27,6 @@ function flattenValue(values, prefix = '', ignoreKeys) {
20
27
  }
21
28
  return flattened;
22
29
  }
30
+ function shouldFlatten(value, ignoreKeys, key) {
31
+ return value && typeof value === 'object' && !ignoreKeys?.includes(key);
32
+ }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "!build/__tests__",
9
9
  "esm"
10
10
  ],
11
- "version": "30.1.3",
11
+ "version": "30.2.0",
12
12
  "main": "./build/index.js",
13
13
  "types": "./build/index.d.ts",
14
14
  "module": "./build/esm/index.js",