find-scripts-srcs-in-document

1.0.0 • Public • Published

find-script-srcs-in-document

Build Status

A quick and simple took to find all script src's in a given HTML document. Under the hood we simple-html-tokenizer to parse the document.

Usage

yarn add find-script-srcs-in-document
const allScriptSources = require('find-script-srcs-in-document');

// basic
allScriptSources('<html><script src="foo"></scripts>') === ['foo'];

// with the ability to ignore on a specific attribute
allScriptSources('<html><script src="foo" data-ignore-me></scripts>', allScriptSources.ignoreWithAttribute('data-ignore-me')) === [];

// advanced
allScriptSources('<html><script src="foo" data-ignore-me></scripts>', scriptToken => {
  const {
    type,       // string type (StartTag)
    tagName,    // string tagName (script)
    attributes, // array of attributes
    selfClosing // boolean
  } = scriptToken;

  return attributes.find(attribute => attribute[0] === 'data-ignore-me')
})) === [];

Readme

Keywords

none

Package Sidebar

Install

npm i find-scripts-srcs-in-document

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

2.2 kB

Total Files

3

Last publish

Collaborators

  • stefanpenner