Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.1.1 to 0.2.0

35

cli.js
#!/usr/bin/env node
var oust = require( './index' );
var pkg = require( './package.json' );
var fs = require( 'fs' );
'use strict';
var fs = require('fs');
var argv = require('minimist')(process.argv.slice(2));
var pkg = require('./package.json');
var oust = require('./');
var printHelp = function() {
function printHelp() {
console.log([
'oust',
pkg.description,
'',
'Usage:',
' $ oust <filename> <type>'
'Usage',
' $ oust <filename> <type>',
'',
'Example',
' $ oust index.html scripts'
].join('\n'));
};
}
if(argv.v || argv.version) {
if (argv.v || argv.version) {
console.log(pkg.version);

@@ -24,3 +25,3 @@ return;

if(argv.h || argv.help || argv._.length === 0) {
if (argv.h || argv.help || argv._.length === 0) {
printHelp();

@@ -33,11 +34,9 @@ return;

fs.readFile(file, function(err, data) {
if(err) {
fs.readFile(file, function (err, data) {
if (err) {
console.error('Error opening file:', err.message);
process.exit(1);
}
var res = oust(data, type);
console.log(res.join('\n'));
console.log(oust(data, type).join('\n'));
});

@@ -18,44 +18,39 @@ /*!

*/
'use strict';
var cheerio = require('cheerio');
var fs = require( 'fs' );
var path = require( 'path' );
var cheerio = require( 'cheerio' );
module.exports = function ( src, type ) {
if ( !src ) {
throw new Error( 'A valid source must be specified' );
var types = {
stylesheets: {
selector: 'link[rel="stylesheet"]',
attribute: 'href'
},
scripts: {
selector: 'script',
attribute: 'src'
},
imports: {
selector: 'link[rel="import"]',
attribute: 'href'
},
links: {
selector: 'a',
attribute: 'href'
},
images: {
selector: 'img',
attribute: 'src'
}
};
if ( !type ) {
throw new Error( 'A valid type must be specified' );
module.exports = function (src, type) {
if (!src || !type) {
throw new Error('`src` and `type` required');
}
// Defaults
var attribute = 'href';
var selector = '';
var chosenType = types[type];
var $ = cheerio.load(src);
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 = $( selector ).map(function( i, elem ){
return $( elem ).attr( attribute );
}).toArray().filter(function( item ){
linkList.push( item );
return ( item !== undefined && item.substring( 0 ,4 ) !== 'http' && item.substring( 0 , 2 ) !== '//' );
});
return linkList;
}
return $(chosenType.selector).map(function (i, el) {
return $(el).attr(chosenType.attribute);
}).toArray();
};
{
"name": "oust",
"version": "0.1.1",
"version": "0.2.0",
"description": "Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML",
"main": "index.js",
"bin": {

@@ -17,4 +16,4 @@ "oust": "cli.js"

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

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

@@ -1,14 +0,15 @@

oust [![Build Status](https://travis-ci.org/addyosmani/oust.svg?branch=master)](https://travis-ci.org/addyosmani/oust)
====
# oust [![Build Status](https://travis-ci.org/addyosmani/oust.svg?branch=master)](https://travis-ci.org/addyosmani/oust)
> Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML
### Install
## Install
```sh
npm install oust --save-dev
$ npm install --save-dev oust
```
### Usage
## Usage
First include:

@@ -52,3 +53,3 @@

### API
## API

@@ -60,8 +61,9 @@ #### Options

`src` | `` | a valid HTML string to parse for references
`type` | `` | one of `stylesheets`, `scripts`, `imports`, `links`, `images`
`type` | `` | one of `stylesheets`, `scripts`, `imports`, `links`, `images`
### Oust CLI
## CLI
```sh
sudo npm install --global oust
$ npm install --global oust
```

@@ -79,3 +81,3 @@

```sh
oust myFile.html stylesheets
$ oust myFile.html stylesheets
```

@@ -86,3 +88,3 @@

```sh
oust myFile.html scripts
$ oust myFile.html scripts
```

@@ -93,3 +95,3 @@

```sh
oust myFile.html imports
$ oust myFile.html imports
```

@@ -100,3 +102,3 @@

```sh
oust myFile.html links
$ oust myFile.html links
```

@@ -107,7 +109,8 @@

```sh
oust myFile.html images
$ oust myFile.html images
```
### License
## License
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