Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stefanpenner/find-scripts-srcs-in-document

simple library to extra script src's from a document
https://github.com/stefanpenner/find-scripts-srcs-in-document

Last synced: 17 days ago
JSON representation

simple library to extra script src's from a document

Awesome Lists containing this project

README

        

# find-script-srcs-in-document
[![Build Status](https://travis-ci.org/stefanpenner/find-script-srcs-in-document.svg?branch=master)](https://travis-ci.org/stefanpenner/find-script-srcs-in-document)

A quick and simple took to find all script src's in a given HTML document.
Under the hood we [simple-html-tokenizer](https://github.com/tildeio/simple-html-tokenizer) to parse the document.

## Usage

```sh
yarn add find-script-srcs-in-document
```

```javascript
const allScriptSources = require('find-script-srcs-in-document');

// basic
allScriptSources('') === ['foo'];

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

// advanced
allScriptSources('<html><script src="foo" data-ignore-me>', 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')
})) === [];
```