Skip to content

stefanpenner/find-scripts-srcs-in-document

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

simple library to extra script src's from a document

Resources

Stars

Watchers

Forks

Packages

No packages published