1.0.0 • Published 5 years ago

find-scripts-srcs-in-document v1.0.0

Weekly downloads
51
License
MIT
Repository
-
Last release
5 years ago

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')
})) === [];