-
-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(settings): convert metadata to text (#2444)
- Loading branch information
Showing
2 changed files
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,28 @@ | ||
import type { Node } from 'ultrahtml' | ||
import { decode } from 'tiny-decode' | ||
import { TEXT_NODE, parse } from 'ultrahtml' | ||
|
||
export const maxAccountFieldCount = computed(() => isGlitchEdition.value ? 16 : 4) | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters