MCPcopy Create free account
hub / github.com/triggerdotdev/jsonhero-web / addEllipsisToSlices

Function addEllipsisToSlices

app/utilities/search.ts:222–371  ·  view source on GitHub ↗
(
    slices: PathSlice[],
    mostImportantComponentIndex: number
  )

Source from the content-addressed store, hash-verified

220 };
221
222 const addEllipsisToSlices = (
223 slices: PathSlice[],
224 mostImportantComponentIndex: number
225 ): PathSlice[] => {
226 // This should take an array of slices like this:
227 // [
228 // { type: "component", slice: { isMatch: true, slice: "re" } },
229 // { type: "component", slice: { isMatch: false, slice: "cords" } },
230 // { type: "join" },
231 // { type: "ellipsis" },
232 // { type: "join" },
233 // { type: "ellipsis" },
234 // { type: "ellipsis" },
235 // { type: "join" },
236 // { type: "component", slice: { isMatch: true, slice: "street" } },
237 // { type: "component", slice: { isMatch: false, slice: "_address" } },
238 // ]
239 //
240 //
241 // And should return this:
242 // [
243 // { type: "component", slice: { isMatch: true, slice: "re" } },
244 // { type: "component", slice: { isMatch: false, slice: "cords" } },
245 // { type: "join" },
246 // { type: "ellipsis" },
247 // { type: "join" },
248 // { type: "component", slice: { isMatch: true, slice: "street" } },
249 // { type: "component", slice: { isMatch: false, slice: "_address" } },
250 // ]
251 const combineAdjacentEllipsis = (toCombine: PathSlice[]): PathSlice[] => {
252 const combined: PathSlice[] = [];
253 let inEllipsis = false;
254
255 for (let i = 0; i < toCombine.length; i++) {
256 const slice = toCombine[i];
257
258 if (slice.type === "ellipsis") {
259 if (!inEllipsis) {
260 inEllipsis = true;
261 combined.push(slice);
262 }
263 }
264
265 if (slice.type === "join") {
266 if (!inEllipsis) {
267 combined.push(slice);
268 }
269 }
270
271 if (slice.type === "component") {
272 if (inEllipsis) {
273 combined.push({ type: "join" });
274 inEllipsis = false;
275 }
276 combined.push(slice);
277 }
278 }
279

Callers 1

getComponentSlicesFunction · 0.85

Calls 1

Tested by

no test coverage detected