(prefix)
| 358 | * }} |
| 359 | */ |
| 360 | export function createParseAttrsWithPrefix(prefix) { |
| 361 | /** |
| 362 | * @param {string} name |
| 363 | * @return {boolean} |
| 364 | */ |
| 365 | const attrMatches = (name) => name?.startsWith(prefix) && name !== prefix; |
| 366 | |
| 367 | /** |
| 368 | * @param {Element} element |
| 369 | * @return {JsonObject|undefined} |
| 370 | */ |
| 371 | const parseAttrs = (element) => { |
| 372 | /** @type {JsonObject|undefined} */ |
| 373 | let currObj = undefined; |
| 374 | const attrs = element.attributes; |
| 375 | for (let i = 0; i < attrs.length; i++) { |
| 376 | const attrib = attrs[i]; |
| 377 | if (attrMatches(attrib.name)) { |
| 378 | if (!currObj) { |
| 379 | currObj = {}; |
| 380 | } |
| 381 | currObj[dashToCamelCase(attrib.name.slice(prefix.length))] = |
| 382 | attrib.value; |
| 383 | } |
| 384 | } |
| 385 | return currObj; |
| 386 | }; |
| 387 | |
| 388 | return { |
| 389 | 'attrMatches': attrMatches, |
| 390 | 'parseAttrs': parseAttrs, |
| 391 | }; |
| 392 | } |
no outgoing calls
no test coverage detected