Socket
Socket
Sign inDemoInstall

oust

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oust - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

40

index.js

@@ -23,17 +23,33 @@ /*!

module.exports = function ( options, cb ) {
if ( !options.src && !options.source ) {
module.exports = function ( src, type ) {
if ( !src ) {
throw new Error( 'A valid source must be specified' );
process.exit(1);
}
options = options || {};
options.selector = options.selector || 'link[rel="stylesheet"]';
options.attribute = options.attribute || 'href';
cb = cb || function () {};
var html = options.source || fs.readFileSync( path.join(process.cwd(), options.src ),'utf8' );
var $ = cheerio.load( html );
if ( !type ) {
throw new Error( 'A valid type must be specified' );
}
// Defaults
var attribute = 'href';
var selector = '';
if ( type == 'stylesheets' ){
selector = 'link[rel="stylesheet"]';
} else if ( type == 'scripts' ) {
selector = 'script';
attribute = 'src';
} else if ( type == 'imports' ) {
selector = 'link[rel="import"]';
} else if ( type == 'links' ) {
selector = 'a';
} else if ( type == 'images' ) {
selector = 'img';
attribute = 'src';
}
var $ = cheerio.load( src );
var linkList = [];
var files = $( options.selector ).map(function( i, elem ){
return $( elem ).attr( options.attribute );
var files = $( selector ).map(function( i, elem ){
return $( elem ).attr( attribute );
}).toArray().filter(function( item ){

@@ -44,3 +60,3 @@ linkList.push( item );

cb( linkList );
return linkList;
}
{
"name": "oust",
"version": "0.0.1",
"description": "Extract a list of stylesheets, scripts or HTML imports from HTML",
"version": "0.0.2",
"description": "Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML",
"main": "index.js",
"bin": {
"oust": "./bin/oust.js"
},
"files": [

@@ -13,3 +16,4 @@ "index.js"

"dependencies": {
"cheerio": "0.17.0"
"cheerio": "0.17.0",
"minimist": "0.1.0"
},

@@ -16,0 +20,0 @@ "devDependencies": {

oust [![Build Status](https://travis-ci.org/addyosmani/oust.svg?branch=master)](https://travis-ci.org/addyosmani/oust)
====
> Extract a list of stylesheets, scripts or HTML imports from HTML
> Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML

@@ -25,5 +25,3 @@ ### Install

```js
oust({ src: 'test/sample/index.html' } , function ( hrefs ){
console.log( hrefs );
});
var hrefs = oust(htmlString, 'stylesheets');
```

@@ -34,9 +32,3 @@

```js
oust({
src: 'test/sample/index.html',
selector: 'script',
attribute: 'src'
}, function ( srcs ){
console.log( srcs );
});
var srcs = oust(htmlString, 'scripts');
```

@@ -47,21 +39,17 @@

```js
oust({
src: 'test/imports.html',
selector: 'link[rel="import"]',
attribute: 'href'
}, function ( hrefs ){
console.log( hrefs );
});
var hrefs = oust(htmlString, 'imports');
```
#### Or from HTML string input:
#### Extract URL references `<a href>`
```js
oust({
source: '<html><link rel="stylesheet" href="styles/main.css"></html>'
}, function ( hrefs ){
console.log( hrefs );
});
var srcs = oust(htmlString, 'links');
```
#### Extract image source references `<img src>`
```js
var srcs = oust(htmlString, 'images');
```
### API

@@ -73,11 +61,50 @@

--- | --- | ---
`src` | `` | a valid path to the file you wish to parse
`source` | `` | a valid string to parse for references
`selector` | `link[rel="stylesheet"]` | a selector to query for
`attribute` | `href` | an attribute to read from the selector query
`src` | `` | a valid HTML string to parse for references
`type` | `` | one of `stylesheets`, `scripts`, `imports`, `links`, `images`
The second parameter to `oust()` is a callback function which will include the array of resources discovered.
### Oust CLI
```sh
npm install --global oust
```
```sh
Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML
Usage:
$ 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 an Apache 2 license. © Google 2014.
Released under an Apache 2 license. © Google 2014.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc