* @param {object} opts * @param {boolean} [opts.forceTag] enforce creating a surrouning tag, even if it is null.
({ forceTag = false } = {})
| 1314 | * @param {boolean} [opts.forceTag] enforce creating a surrouning <name /> tag, even if it is null. |
| 1315 | */ |
| 1316 | toString ({ forceTag = false } = {}) { |
| 1317 | /** |
| 1318 | * @type {Array<[string|number,string]>} |
| 1319 | */ |
| 1320 | const attrs = [] |
| 1321 | this.forEachAttr((attr, key) => { |
| 1322 | attrs.push([(key), /** @type {any} */ (attr) instanceof YType ? attr.toString({ forceTag: true }) : JSON.stringify(attr)]) |
| 1323 | }) |
| 1324 | const attrsString = (attrs.length > 0 ? ' ' : '') + attrs.sort((a, b) => a[0].toString() < b[0].toString() ? -1 : 1).map(attr => attr[0] + '=' + attr[1]).join(' ') |
| 1325 | /** |
| 1326 | * @type {string} |
| 1327 | */ |
| 1328 | const children = this.toArray().map(c => s.$string.check(c) ? c : (c instanceof YType ? c.toString({ forceTag: true }) : JSON.stringify(c))).join('') |
| 1329 | if (this.name == null && !forceTag && attrs.length === 0) { |
| 1330 | return children |
| 1331 | } |
| 1332 | if (this.length === 0) { |
| 1333 | return `<${this.name ?? ''}${attrsString} />` |
| 1334 | } |
| 1335 | return `<${this.name ?? ''}${attrsString}>${children}</${this.name ?? ''}>` |
| 1336 | } |
| 1337 | |
| 1338 | /** |
| 1339 | * Returns an Array with the result of calling a provided function on every |
no test coverage detected