@builder.io/sdk-qwik 0.16.24 → 0.17.1
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/lib/browser/blocks/image/component-info.qwik.cjs +2 -7
- package/lib/browser/blocks/image/component-info.qwik.mjs +2 -7
- package/lib/browser/blocks/image/image.qwik.cjs +1 -1
- package/lib/browser/blocks/image/image.qwik.mjs +1 -1
- package/lib/browser/blocks/img/component-info.qwik.cjs +2 -8
- package/lib/browser/blocks/img/component-info.qwik.mjs +2 -8
- package/lib/browser/blocks/video/component-info.qwik.cjs +3 -7
- package/lib/browser/blocks/video/component-info.qwik.mjs +3 -7
- package/lib/browser/components/block/block.helpers.qwik.cjs +16 -5
- package/lib/browser/components/block/block.helpers.qwik.mjs +16 -5
- package/lib/browser/components/block/block.qwik.cjs +3 -2
- package/lib/browser/components/block/block.qwik.mjs +3 -2
- package/lib/browser/components/content/components/enable-editor.helpers.qwik.cjs +15 -0
- package/lib/browser/components/content/components/enable-editor.helpers.qwik.mjs +15 -0
- package/lib/browser/components/content/components/enable-editor.qwik.cjs +10 -4
- package/lib/browser/components/content/components/enable-editor.qwik.mjs +10 -4
- package/lib/browser/components/content/content.qwik.cjs +7 -18
- package/lib/browser/components/content/content.qwik.mjs +7 -18
- package/lib/browser/constants/file-types.qwik.cjs +72 -0
- package/lib/browser/constants/file-types.qwik.mjs +72 -0
- package/lib/browser/constants/sdk-version.qwik.cjs +1 -1
- package/lib/browser/constants/sdk-version.qwik.mjs +1 -1
- package/lib/browser/functions/extract-localized-values.qwik.cjs +37 -0
- package/lib/browser/functions/extract-localized-values.qwik.mjs +37 -0
- package/lib/browser/functions/get-content/index.qwik.cjs +10 -15
- package/lib/browser/functions/get-content/index.qwik.mjs +10 -15
- package/lib/browser/functions/get-processed-block.qwik.cjs +3 -1
- package/lib/browser/functions/get-processed-block.qwik.mjs +3 -1
- package/lib/browser/functions/register-component.qwik.cjs +1 -1
- package/lib/browser/functions/register-component.qwik.mjs +1 -1
- package/lib/browser/functions/traverse.qwik.cjs +31 -0
- package/lib/browser/functions/traverse.qwik.mjs +31 -0
- package/lib/edge/blocks/image/component-info.qwik.cjs +2 -7
- package/lib/edge/blocks/image/component-info.qwik.mjs +2 -7
- package/lib/edge/blocks/image/image.qwik.cjs +1 -1
- package/lib/edge/blocks/image/image.qwik.mjs +1 -1
- package/lib/edge/blocks/img/component-info.qwik.cjs +2 -8
- package/lib/edge/blocks/img/component-info.qwik.mjs +2 -8
- package/lib/edge/blocks/video/component-info.qwik.cjs +3 -7
- package/lib/edge/blocks/video/component-info.qwik.mjs +3 -7
- package/lib/edge/components/block/block.helpers.qwik.cjs +16 -5
- package/lib/edge/components/block/block.helpers.qwik.mjs +16 -5
- package/lib/edge/components/block/block.qwik.cjs +3 -2
- package/lib/edge/components/block/block.qwik.mjs +3 -2
- package/lib/edge/components/content/components/enable-editor.helpers.qwik.cjs +15 -0
- package/lib/edge/components/content/components/enable-editor.helpers.qwik.mjs +15 -0
- package/lib/edge/components/content/components/enable-editor.qwik.cjs +10 -4
- package/lib/edge/components/content/components/enable-editor.qwik.mjs +10 -4
- package/lib/edge/components/content/content.qwik.cjs +7 -18
- package/lib/edge/components/content/content.qwik.mjs +7 -18
- package/lib/edge/constants/file-types.qwik.cjs +72 -0
- package/lib/edge/constants/file-types.qwik.mjs +72 -0
- package/lib/edge/constants/sdk-version.qwik.cjs +1 -1
- package/lib/edge/constants/sdk-version.qwik.mjs +1 -1
- package/lib/edge/functions/extract-localized-values.qwik.cjs +37 -0
- package/lib/edge/functions/extract-localized-values.qwik.mjs +37 -0
- package/lib/edge/functions/get-content/index.qwik.cjs +10 -15
- package/lib/edge/functions/get-content/index.qwik.mjs +10 -15
- package/lib/edge/functions/get-processed-block.qwik.cjs +3 -1
- package/lib/edge/functions/get-processed-block.qwik.mjs +3 -1
- package/lib/edge/functions/register-component.qwik.cjs +1 -1
- package/lib/edge/functions/register-component.qwik.mjs +1 -1
- package/lib/edge/functions/traverse.qwik.cjs +31 -0
- package/lib/edge/functions/traverse.qwik.mjs +31 -0
- package/lib/node/blocks/image/component-info.qwik.cjs +2 -7
- package/lib/node/blocks/image/component-info.qwik.mjs +2 -7
- package/lib/node/blocks/image/image.qwik.cjs +1 -1
- package/lib/node/blocks/image/image.qwik.mjs +1 -1
- package/lib/node/blocks/img/component-info.qwik.cjs +2 -8
- package/lib/node/blocks/img/component-info.qwik.mjs +2 -8
- package/lib/node/blocks/video/component-info.qwik.cjs +3 -7
- package/lib/node/blocks/video/component-info.qwik.mjs +3 -7
- package/lib/node/components/block/block.helpers.qwik.cjs +16 -5
- package/lib/node/components/block/block.helpers.qwik.mjs +16 -5
- package/lib/node/components/block/block.qwik.cjs +3 -2
- package/lib/node/components/block/block.qwik.mjs +3 -2
- package/lib/node/components/content/components/enable-editor.helpers.qwik.cjs +15 -0
- package/lib/node/components/content/components/enable-editor.helpers.qwik.mjs +15 -0
- package/lib/node/components/content/components/enable-editor.qwik.cjs +10 -4
- package/lib/node/components/content/components/enable-editor.qwik.mjs +10 -4
- package/lib/node/components/content/content.qwik.cjs +7 -18
- package/lib/node/components/content/content.qwik.mjs +7 -18
- package/lib/node/constants/file-types.qwik.cjs +72 -0
- package/lib/node/constants/file-types.qwik.mjs +72 -0
- package/lib/node/constants/sdk-version.qwik.cjs +1 -1
- package/lib/node/constants/sdk-version.qwik.mjs +1 -1
- package/lib/node/functions/extract-localized-values.qwik.cjs +37 -0
- package/lib/node/functions/extract-localized-values.qwik.mjs +37 -0
- package/lib/node/functions/get-content/index.qwik.cjs +10 -15
- package/lib/node/functions/get-content/index.qwik.mjs +10 -15
- package/lib/node/functions/get-processed-block.qwik.cjs +3 -1
- package/lib/node/functions/get-processed-block.qwik.mjs +3 -1
- package/lib/node/functions/register-component.qwik.cjs +1 -1
- package/lib/node/functions/register-component.qwik.mjs +1 -1
- package/lib/node/functions/traverse.qwik.cjs +31 -0
- package/lib/node/functions/traverse.qwik.mjs +31 -0
- package/package.json +1 -1
- package/types/src/components/block/block.helpers.d.ts +6 -3
- package/types/src/components/content/components/enable-editor.helpers.d.ts +11 -0
- package/types/src/constants/file-types.d.ts +2 -0
- package/types/src/constants/sdk-version.d.ts +1 -1
- package/types/src/context/types.d.ts +1 -0
- package/types/src/functions/extract-localized-values.d.ts +2 -0
- package/types/src/functions/get-content/index.d.ts +1 -1
- package/types/src/functions/traverse.d.ts +34 -0
- package/types/src/types/components.d.ts +3 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { traverse } from "./traverse.qwik.mjs";
|
|
2
|
+
function isLocalizedField(value) {
|
|
3
|
+
return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
|
|
4
|
+
}
|
|
5
|
+
function containsLocalizedValues(data) {
|
|
6
|
+
if (!data || !Object.getOwnPropertyNames(data).length)
|
|
7
|
+
return false;
|
|
8
|
+
let hasLocalizedValues = false;
|
|
9
|
+
traverse(data, (value) => {
|
|
10
|
+
if (isLocalizedField(value)) {
|
|
11
|
+
hasLocalizedValues = true;
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return hasLocalizedValues;
|
|
16
|
+
}
|
|
17
|
+
function extractLocalizedValues(data, locale) {
|
|
18
|
+
if (!data || !Object.getOwnPropertyNames(data).length)
|
|
19
|
+
return {};
|
|
20
|
+
traverse(data, (value, update) => {
|
|
21
|
+
if (isLocalizedField(value))
|
|
22
|
+
update(value[locale] ?? void 0);
|
|
23
|
+
});
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
function resolveLocalizedValues(block, locale) {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
if (((_a = block.component) == null ? void 0 : _a.options) && containsLocalizedValues((_b = block.component) == null ? void 0 : _b.options)) {
|
|
29
|
+
if (!locale)
|
|
30
|
+
console.warn("[Builder.io] In order to use localized fields in Builder, you must pass a locale prop to the BuilderComponent or to options object while fetching the content to resolve localized fields. Learn more: https://www.builder.io/c/docs/localization-inline#targeting-and-inline-localization");
|
|
31
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
|
|
32
|
+
}
|
|
33
|
+
return block;
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
resolveLocalizedValues
|
|
37
|
+
};
|
|
@@ -54,22 +54,17 @@ const _processContentResult = async (options, content, url = generateContentUrl.
|
|
|
54
54
|
return content.results;
|
|
55
55
|
};
|
|
56
56
|
async function fetchEntries(options) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return _processContentResult(options, content);
|
|
69
|
-
} catch (error) {
|
|
70
|
-
logger.logger.error("Error fetching data. ", error);
|
|
71
|
-
return null;
|
|
57
|
+
const url = generateContentUrl.generateContentUrl(options);
|
|
58
|
+
const content = await _fetchContent(options);
|
|
59
|
+
if (!checkContentHasResults(content)) {
|
|
60
|
+
logger.logger.error("Error fetching data. ", {
|
|
61
|
+
url,
|
|
62
|
+
content,
|
|
63
|
+
options
|
|
64
|
+
});
|
|
65
|
+
throw content;
|
|
72
66
|
}
|
|
67
|
+
return _processContentResult(options, content);
|
|
73
68
|
}
|
|
74
69
|
exports._processContentResult = _processContentResult;
|
|
75
70
|
exports.fetchEntries = fetchEntries;
|
|
@@ -52,22 +52,17 @@ const _processContentResult = async (options, content, url = generateContentUrl(
|
|
|
52
52
|
return content.results;
|
|
53
53
|
};
|
|
54
54
|
async function fetchEntries(options) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return _processContentResult(options, content);
|
|
67
|
-
} catch (error) {
|
|
68
|
-
logger.error("Error fetching data. ", error);
|
|
69
|
-
return null;
|
|
55
|
+
const url = generateContentUrl(options);
|
|
56
|
+
const content = await _fetchContent(options);
|
|
57
|
+
if (!checkContentHasResults(content)) {
|
|
58
|
+
logger.error("Error fetching data. ", {
|
|
59
|
+
url,
|
|
60
|
+
content,
|
|
61
|
+
options
|
|
62
|
+
});
|
|
63
|
+
throw content;
|
|
70
64
|
}
|
|
65
|
+
return _processContentResult(options, content);
|
|
71
66
|
}
|
|
72
67
|
export {
|
|
73
68
|
_processContentResult,
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const target = require("../constants/target.qwik.cjs");
|
|
4
4
|
const omit = require("../helpers/omit.qwik.cjs");
|
|
5
5
|
const evaluate = require("./evaluate/evaluate.qwik.cjs");
|
|
6
|
+
const extractLocalizedValues = require("./extract-localized-values.qwik.cjs");
|
|
6
7
|
const fastClone = require("./fast-clone.qwik.cjs");
|
|
7
8
|
const set = require("./set.qwik.cjs");
|
|
8
9
|
const transformBlock = require("./transform-block.qwik.cjs");
|
|
@@ -72,7 +73,8 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
|
72
73
|
return copied;
|
|
73
74
|
};
|
|
74
75
|
function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
|
|
75
|
-
|
|
76
|
+
let transformedBlock = extractLocalizedValues.resolveLocalizedValues(block, rootState.locale);
|
|
77
|
+
transformedBlock = transformBlock.transformBlock(transformedBlock);
|
|
76
78
|
if (shouldEvaluateBindings)
|
|
77
79
|
return evaluateBindings({
|
|
78
80
|
block: transformedBlock,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TARGET } from "../constants/target.qwik.mjs";
|
|
2
2
|
import { omit } from "../helpers/omit.qwik.mjs";
|
|
3
3
|
import { evaluate } from "./evaluate/evaluate.qwik.mjs";
|
|
4
|
+
import { resolveLocalizedValues } from "./extract-localized-values.qwik.mjs";
|
|
4
5
|
import { fastClone } from "./fast-clone.qwik.mjs";
|
|
5
6
|
import { set } from "./set.qwik.mjs";
|
|
6
7
|
import { transformBlock } from "./transform-block.qwik.mjs";
|
|
@@ -70,7 +71,8 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
|
70
71
|
return copied;
|
|
71
72
|
};
|
|
72
73
|
function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
|
|
73
|
-
|
|
74
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
75
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
74
76
|
if (shouldEvaluateBindings)
|
|
75
77
|
return evaluateBindings({
|
|
76
78
|
block: transformedBlock,
|
|
@@ -7,7 +7,7 @@ const createRegisterComponentMessage = (info) => ({
|
|
|
7
7
|
const serializeFn = (fnValue) => {
|
|
8
8
|
const fnStr = fnValue.toString().trim();
|
|
9
9
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
10
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
10
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
11
11
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
12
12
|
};
|
|
13
13
|
function serializeIncludingFunctions(info) {
|
|
@@ -5,7 +5,7 @@ const createRegisterComponentMessage = (info) => ({
|
|
|
5
5
|
const serializeFn = (fnValue) => {
|
|
6
6
|
const fnStr = fnValue.toString().trim();
|
|
7
7
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
8
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
8
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
9
9
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
10
10
|
};
|
|
11
11
|
function serializeIncludingFunctions(info) {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function traverse(obj, callback, parent = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
4
|
+
if (obj == null || typeof obj !== "object") {
|
|
5
|
+
callback(obj, (newValue) => {
|
|
6
|
+
if (parent !== null && key !== null)
|
|
7
|
+
parent[key] = newValue;
|
|
8
|
+
});
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (visited.has(obj))
|
|
12
|
+
return;
|
|
13
|
+
visited.add(obj);
|
|
14
|
+
if (Array.isArray(obj))
|
|
15
|
+
obj.forEach((item, index) => {
|
|
16
|
+
const update = (newValue) => {
|
|
17
|
+
obj[index] = newValue;
|
|
18
|
+
};
|
|
19
|
+
callback(item, update);
|
|
20
|
+
traverse(item, callback, obj, index, visited);
|
|
21
|
+
});
|
|
22
|
+
else
|
|
23
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
24
|
+
const update = (newValue) => {
|
|
25
|
+
obj[key2] = newValue;
|
|
26
|
+
};
|
|
27
|
+
callback(value, update);
|
|
28
|
+
traverse(value, callback, obj, key2, visited);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.traverse = traverse;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
function traverse(obj, callback, parent = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
2
|
+
if (obj == null || typeof obj !== "object") {
|
|
3
|
+
callback(obj, (newValue) => {
|
|
4
|
+
if (parent !== null && key !== null)
|
|
5
|
+
parent[key] = newValue;
|
|
6
|
+
});
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (visited.has(obj))
|
|
10
|
+
return;
|
|
11
|
+
visited.add(obj);
|
|
12
|
+
if (Array.isArray(obj))
|
|
13
|
+
obj.forEach((item, index) => {
|
|
14
|
+
const update = (newValue) => {
|
|
15
|
+
obj[index] = newValue;
|
|
16
|
+
};
|
|
17
|
+
callback(item, update);
|
|
18
|
+
traverse(item, callback, obj, index, visited);
|
|
19
|
+
});
|
|
20
|
+
else
|
|
21
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
22
|
+
const update = (newValue) => {
|
|
23
|
+
obj[key2] = newValue;
|
|
24
|
+
};
|
|
25
|
+
callback(value, update);
|
|
26
|
+
traverse(value, callback, obj, key2, visited);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
traverse
|
|
31
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
3
3
|
import type { RepeatData } from './types';
|
|
4
|
-
export declare const getComponent: ({ block, registeredComponents }: {
|
|
4
|
+
export declare const getComponent: ({ block, registeredComponents, model }: {
|
|
5
5
|
block: BuilderBlock;
|
|
6
6
|
registeredComponents: RegisteredComponents;
|
|
7
|
+
model: string;
|
|
7
8
|
}) => RegisteredComponent | null | undefined;
|
|
8
9
|
export declare const getRepeatItemData: ({ block, context }: {
|
|
9
10
|
block: BuilderBlock;
|
|
@@ -18,8 +19,10 @@ export declare const provideLinkComponent: (block: RegisteredComponent | null |
|
|
|
18
19
|
} | {
|
|
19
20
|
builderLinkComponent?: undefined;
|
|
20
21
|
};
|
|
21
|
-
export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents) => {
|
|
22
|
-
builderComponents:
|
|
22
|
+
export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents, model: string) => {
|
|
23
|
+
builderComponents: {
|
|
24
|
+
[k: string]: RegisteredComponent;
|
|
25
|
+
};
|
|
23
26
|
} | {
|
|
24
27
|
builderComponents?: undefined;
|
|
25
28
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Target } from '../../../types/targets';
|
|
2
|
+
/**
|
|
3
|
+
* SDKS that use the elementRef approach to enable visual editing.
|
|
4
|
+
* We don't need to render the div for other SDKs as they attach event listeners to the window.
|
|
5
|
+
*/
|
|
6
|
+
export declare const SDKS_USING_ELEMENT_REF_APPROACH: Target[];
|
|
7
|
+
/**
|
|
8
|
+
* We need to attach this div only when content exists or isPreviewing/isEditing even when content is null,
|
|
9
|
+
* as we need to set the elementRef and allow previewing and visual editing
|
|
10
|
+
*/
|
|
11
|
+
export declare const needsElementRefDivForEditing: () => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.17.1";
|
|
@@ -14,5 +14,5 @@ export declare const _processContentResult: (options: GetContentOptions, content
|
|
|
14
14
|
/**
|
|
15
15
|
* Returns a paginated array of entries that match the given options.
|
|
16
16
|
*/
|
|
17
|
-
export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]
|
|
17
|
+
export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]>;
|
|
18
18
|
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type TraverseCallback = (value: any, update: (newValue: any) => void) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Recursively traverses an object or array, invoking a callback on each value.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} obj - The object or array to traverse. Can also handle primitives, null, or undefined.
|
|
6
|
+
* @param {TraverseCallback} callback - The function to invoke on each value. Receives the current value
|
|
7
|
+
* and an `update` function to modify the value in its parent container.
|
|
8
|
+
* @param {any} [parent=null] - The parent object or array of the current value. Used internally.
|
|
9
|
+
* @param {any} [key=null] - The key or index of the current value in its parent. Used internally.
|
|
10
|
+
* @param {WeakSet} [visited=new WeakSet()] - Tracks visited objects to handle circular references. Used internally.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Example: Doubling all numbers in an object
|
|
14
|
+
* const obj = { a: 1, b: [2, 3, { c: 4 }] };
|
|
15
|
+
* traverse(obj, (value, update) => {
|
|
16
|
+
* if (typeof value === 'number') {
|
|
17
|
+
* update(value * 2);
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
* console.log(obj); // { a: 2, b: [4, 6, { c: 8 }] }
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Example: Handling circular references
|
|
24
|
+
* const obj = { a: 1 };
|
|
25
|
+
* obj.self = obj;
|
|
26
|
+
* traverse(obj, (value, update) => {
|
|
27
|
+
* if (typeof value === 'number') {
|
|
28
|
+
* update(value * 2);
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
* console.log(obj.a); // 2
|
|
32
|
+
*/
|
|
33
|
+
export declare function traverse(obj: any, callback: TraverseCallback, parent?: any, key?: any, visited?: WeakSet<object>): void;
|
|
34
|
+
export {};
|