(html: string)
| 93 | return parse(payload || '', revivers) |
| 94 | } |
| 95 | export 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 | } |
no test coverage detected
searching dependent graphs…