Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/stefanpenner/find-scripts-srcs-in-document
- Owner: stefanpenner
- Created: 2019-09-12T02:55:33.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-11T01:00:55.000Z (over 2 years ago)
- Last Synced: 2024-10-17T18:09:53.529Z (19 days ago)
- Language: JavaScript
- Size: 787 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
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')
})) === [];
```