For some reason, scrapper gathers a lot of stuff that is not JS.
If JSON.parse(sourceText) succeeds then we definitely don't care about it.
HTML is harder to pin down; it's wrong to search for tags, because many JS files contain globs of HTML, for use with .innerHTML.
One solid indicator of HTML is <!doctype or <html at the start of the file.
You can detect whether a string matches Script by doing new Function("", sourceText) and catching the SyntaxError. But it throws for modules.
For some reason, scrapper gathers a lot of stuff that is not JS.
If
JSON.parse(sourceText)succeeds then we definitely don't care about it.HTML is harder to pin down; it's wrong to search for tags, because many JS files contain globs of HTML, for use with
.innerHTML.One solid indicator of HTML is
<!doctypeor<htmlat the start of the file.You can detect whether a string matches Script by doing
new Function("", sourceText)and catching theSyntaxError. But it throws for modules.