2023-11-27 12:17:58 +00:00
|
|
|
import type { Node } from 'ultrahtml'
|
|
|
|
import { decode } from 'tiny-decode'
|
2024-09-30 09:11:56 +01:00
|
|
|
import { parse, TEXT_NODE } from 'ultrahtml'
|
2023-11-27 12:17:58 +00:00
|
|
|
|
2023-01-10 08:33:20 +00:00
|
|
|
export const maxAccountFieldCount = computed(() => isGlitchEdition.value ? 16 : 4)
|
2023-11-27 12:17:58 +00:00
|
|
|
|
|
|
|
export function convertMetadata(metadata: string) {
|
|
|
|
try {
|
|
|
|
const tree = parse(metadata)
|
|
|
|
return (tree.children as Node[]).map(n => convertToText(n)).join('').trim()
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function convertToText(input: Node): string {
|
|
|
|
let text = ''
|
|
|
|
|
|
|
|
if (input.type === TEXT_NODE)
|
|
|
|
return decode(input.value)
|
|
|
|
|
|
|
|
if ('children' in input)
|
|
|
|
text = (input.children as Node[]).map(n => convertToText(n)).join('')
|
|
|
|
|
|
|
|
return text
|
|
|
|
}
|