Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/addyosmani/oust
Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML
https://github.com/addyosmani/oust
Last synced: 23 days ago
JSON representation
Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML
- Host: GitHub
- URL: https://github.com/addyosmani/oust
- Owner: addyosmani
- License: apache-2.0
- Created: 2014-06-13T18:13:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-09-16T22:26:29.000Z (about 2 months ago)
- Last Synced: 2024-10-17T16:54:07.868Z (23 days ago)
- Language: JavaScript
- Homepage:
- Size: 1.05 MB
- Stars: 178
- Watchers: 10
- Forks: 21
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# oust
[![CI](https://img.shields.io/github/actions/workflow/status/addyosmani/oust/test.yml?branch=master&label=CI&logo=github)](https://github.com/addyosmani/oust/actions/workflows/test.yml?query=branch%3Amaster)
[![npm version](https://img.shields.io/npm/v/oust?logo=npm&logoColor=fff)](https://www.npmjs.com/package/oust)> Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML
## Install
```sh
npm install oust -D
```## Usage
First include:
```js
const oust = require('oust');
```Resource links can then be extracted from either files:
### Extract stylesheets references ``
```js
const hrefs = oust(htmlString, 'stylesheets');
```### Extract stylesheets references with media print ``
```js
const hrefs = oust(htmlString, 'stylesheets', (i, $el) => {
return $el.attr('media') === 'print';
});
```### Extract script references ``
```js
const srcs = oust(htmlString, 'scripts');
```### Extract HTML imports `<link rel="import">`
```js
const hrefs = oust(htmlString, 'imports');
```### Extract style preload references `<link rel="preload" as="style">`
```js
const hrefs = oust(htmlString, 'preload');
```### Extract URL references `<a href>`
```js
const srcs = oust(htmlString, 'links');
```### Extract image source references `<img src>`
```js
const srcs = oust(htmlString, 'images');
```### Extract inline styles `<style>...</style>`
```js
const styles = oust(htmlString, 'styles');
```### Extract preload and stylesheet references combined
```js
const hrefs = oust(htmlString, ['preload', 'stylesheets']);
```### Extract cheerio elements alongside the value
Useful for post processing/filtering as you get an array of matched elements
with cheerio convenience syntax (e.g. `$el.attr()`)```js
const srcs = oust.raw(htmlString, '...');/*
-> [
{$el: '...', type: '...', value: '...'},
{$el: '...', type: '...', value: '...'},
...
]
*/
```## API
### Options
Attribute | Default | Description
--- | --- | ---
`src` | not set | a valid HTML string to parse for references
`type` | not set | one of `stylesheets`, `scripts`, `imports`, `preload`, `styles`, `links`, `images`## CLI
```sh
npm install --global oust
``````sh
Extract URLs to stylesheets, scripts, links, images or HTML imports from HTMLUsage:
$ oust <filename> <type>
```### Extract stylesheets references `<link rel="stylesheet">`
```sh
oust myFile.html stylesheets
```### Extract script references `<script src>`
```sh
oust myFile.html scripts
```### Extract HTML imports `<link rel="import">`
```sh
oust myFile.html imports
```### Extract URL references `<a href>`
```sh
oust myFile.html links
```### Extract image source references `<img src>`
```sh
oust myFile.html images
```## License
Released under the [Apache 2 license](LICENSE). © Google 2014.