([tag, attrs, content]: HeadConfig)
| 7 | * Resolve identifier of a tag, to avoid duplicated tags in `<head>` |
| 8 | */ |
| 9 | export const resolveHeadIdentifier = ([tag, attrs, content]: HeadConfig): |
| 10 | | string |
| 11 | | null => { |
| 12 | // avoid duplicated unique tags |
| 13 | if (TAGS_UNIQUE.includes(tag)) { |
| 14 | return tag |
| 15 | } |
| 16 | |
| 17 | // avoid disallowed tags |
| 18 | if (!TAGS_ALLOWED.includes(tag)) { |
| 19 | return null |
| 20 | } |
| 21 | |
| 22 | // avoid duplicated `<meta>` with same `name` |
| 23 | if (tag === 'meta' && attrs.name) { |
| 24 | return `${tag}.${attrs.name}` |
| 25 | } |
| 26 | |
| 27 | // avoid duplicated `<template>` with same `id` |
| 28 | if (tag === 'template' && attrs.id) { |
| 29 | return `${tag}.${attrs.id}` |
| 30 | } |
| 31 | |
| 32 | return JSON.stringify([ |
| 33 | tag, |
| 34 | Object.entries(attrs) |
| 35 | .map(([key, value]) => { |
| 36 | // normalize boolean attributes |
| 37 | if (typeof value === 'boolean') { |
| 38 | return value ? [key, ''] : null |
| 39 | } |
| 40 | return [key, value] |
| 41 | }) |
| 42 | .filter((item): item is [string, string] => item != null) |
| 43 | .sort(([keyA], [keyB]) => keyA.localeCompare(keyB)), |
| 44 | content, |
| 45 | ]) |
| 46 | } |
no outgoing calls
no test coverage detected