UNPKG

yaml-unist-parser

Version:

A YAML parser that produces output compatible with unist

21 lines (20 loc) 704 B
import { createSlicer } from "./create-slicer.js"; export function groupCstFlowCollectionItems(cstItems) { const groups = []; const sliceCstItems = createSlicer(cstItems, 1); // exclude `{` or `[` let hasItem = false; for (let i = 1; i < cstItems.length - 1; i++) { const cstItem = cstItems[i]; if ("char" in cstItem && cstItem.char === ",") { groups.push(sliceCstItems(i)); sliceCstItems(i + 1); // exclude `,` hasItem = false; continue; } hasItem = true; } if (hasItem) { groups.push(sliceCstItems(cstItems.length - 1)); // exclude `}` or `]` } return groups; }