Open History to see the last commit
1import * as cheerio from 'cheerio'
2β
3export function extractHtmlScripts(
4 html: string,
5): Array<{ content?: string; src?: string }> {
6 const $ = cheerio.load(html)
7 const scripts: Array<{ content?: string; src?: string }> = []
8β
9 $('script').each((_, element) => {
10 const src = $(element).attr('src')
11 const content = $(element).html() ?? undefined
12 scripts.push({
13 src,
14 content,
15 })
16 })
17β
18 return scripts
19}