UNPKG

nice-ui

Version:

React design system, components, and utilities

23 lines (22 loc) 664 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const getText = (ast, idx = 0, stopAtLength = Infinity) => { let str = ''; const iterate = (currentIdx) => { const node = ast.nodes[currentIdx]; if (typeof node.value === 'string') { str += node.value.replace(/\s+/g, ' '); return; } if (node.children instanceof Array) { for (const child of node.children) { iterate(child); if (str.length >= stopAtLength) return; } } }; iterate(idx); return str; }; exports.default = getText;