UNPKG

parjs

Version:

Library for building parsers using combinators.

28 lines 721 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.flatten = void 0; const map_1 = require("./map"); function flattenNestedArrays(arr) { if (!Array.isArray(arr)) { return [arr]; } const items = []; for (const item of arr) { if (Array.isArray(item)) { items.push(...flattenNestedArrays(item)); } else { items.push(item); } } return items; } /** * Applies the source parser and projects its result into a flat array - an array with non-array * elements. */ function flatten() { return (0, map_1.map)(x => flattenNestedArrays(x)); } exports.flatten = flatten; //# sourceMappingURL=flatten.js.map