UNPKG

dbl-utils

Version:

Utilities for dbl, adba and others projects

23 lines (22 loc) 791 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractNodeString = void 0; const react_1 = __importDefault(require("react")); const extractNodeString = (obj) => { if (typeof obj === 'string') return obj; else if (Array.isArray(obj)) { return obj.map(e => (0, exports.extractNodeString)(e)).filter(n => !!n).flat().join(' '); } else if (react_1.default.isValidElement(obj)) { obj = obj; return (0, exports.extractNodeString)(obj.props.children); } else if (!obj) return ''; return obj.toString(); }; exports.extractNodeString = extractNodeString;