MCPcopy
hub / github.com/nuxt/nuxt / parseData

Function parseData

test/utils.ts:95–115  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

93 return parse(payload || '', revivers)
94}
95export function parseData (html: string) {
96 if (!isRenderingJson) {
97 const { script = '' } = html.match(/<script>(?<script>window.__NUXT__.*?)<\/script>/)?.groups || {}
98 const _script = new Script(script)
99 return {
100 script: _script.runInContext(createContext({ window: {} })),
101 attrs: {},
102 }
103 }
104
105 const regexp = /<script type="application\/json" data-nuxt-data="[^"]+"(?<attrs>[^>]+)>(?<script>.*?)<\/script>/
106 const { script, attrs = '' } = html.match(regexp)?.groups || {}
107 const _attrs: Record<string, string> = {}
108 for (const attr of attrs.matchAll(/( |^)(?<key>[\w-]+)="(?<value>[^"]+)"/g)) {
109 _attrs[attr!.groups!.key!] = attr!.groups!.value!
110 }
111 return {
112 script: parsePayload(script || ''),
113 attrs: _attrs,
114 }
115}

Callers 1

basic.test.tsFile · 0.90

Calls 1

parsePayloadFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…