MCPcopy
hub / github.com/yjs/yjs / toString

Method toString

src/ytype.js:1316–1336  ·  view source on GitHub ↗

* @param {object} opts * @param {boolean} [opts.forceTag] enforce creating a surrouning tag, even if it is null.

({ forceTag = false } = {})

Source from the content-addressed store, hash-verified

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

Callers 15

compareFunction · 0.80
testAttributionSession1Function · 0.80
testMergePendingUpdatesFunction · 0.80
testBasicInsertAndDeleteFunction · 0.80
testBasicFormatFunction · 0.80
testSearchMarkerBug1Function · 0.80
y-text.tests.jsFile · 0.80
testUndoTextFunction · 0.80
testDoubleUndoFunction · 0.80

Calls 4

forEachAttrMethod · 0.95
toArrayMethod · 0.95
pushMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected