MCPcopy Create free account
hub / github.com/decaporg/decap-cms / expandPath

Function expandPath

packages/decap-cms-lib-widgets/src/stringTemplate.ts:110–143  ·  view source on GitHub ↗
({
  data,
  path,
  paths = [],
}: {
  data: Record<string, unknown>;
  path: string;
  paths?: string[];
})

Source from the content-addressed store, hash-verified

108}
109
110export function expandPath({
111 data,
112 path,
113 paths = [],
114}: {
115 data: Record<string, unknown>;
116 path: string;
117 paths?: string[];
118}) {
119 if (path.endsWith('.*')) {
120 path = path + '.';
121 }
122
123 const sep = '.*.';
124 const parts = path.split(sep);
125 if (parts.length === 1) {
126 paths.push(path);
127 } else {
128 const partialPath = parts[0];
129 const value = get(data, partialPath);
130
131 if (Array.isArray(value)) {
132 value.forEach((_, index) => {
133 expandPath({
134 data,
135 path: trimEnd(`${partialPath}.${index}.${parts.slice(1).join(sep)}`, '.'),
136 paths,
137 });
138 });
139 }
140 }
141
142 return paths;
143}
144
145// Allow `fields.` prefix in placeholder to override built in replacements
146// like "slug" and "year" with values from fields of the same name.

Callers 2

expandSearchEntriesFunction · 0.85

Calls 1

getFunction · 0.50

Tested by

no test coverage detected