Comparing version
22
cli.js
#!/usr/bin/env node | ||
'use strict'; | ||
var fs = require('fs'); | ||
var argv = require('minimist')(process.argv.slice(2)); | ||
var pkg = require('./package.json'); | ||
var oust = require('./'); | ||
const fs = require('fs'); | ||
const minimist = require('minimist'); | ||
const pkg = require('./package.json'); | ||
const oust = require('.'); | ||
const argv = minimist(process.argv.slice(2)); | ||
function printHelp() { | ||
@@ -22,3 +26,3 @@ console.log([ | ||
console.log(pkg.version); | ||
return; | ||
process.exit(0); | ||
} | ||
@@ -28,9 +32,9 @@ | ||
printHelp(); | ||
return; | ||
process.exit(0); | ||
} | ||
var file = argv._[0]; | ||
var type = argv._[1]; | ||
const file = argv._[0]; | ||
const type = argv._[1]; | ||
fs.readFile(file, function (err, data) { | ||
fs.readFile(file, (err, data) => { | ||
if (err) { | ||
@@ -37,0 +41,0 @@ console.error('Error opening file:', err.message); |
31
index.js
@@ -18,6 +18,8 @@ /*! | ||
*/ | ||
'use strict'; | ||
var cheerio = require('cheerio'); | ||
var types = { | ||
const cheerio = require('cheerio'); | ||
const types = { | ||
stylesheets: { | ||
@@ -36,4 +38,4 @@ selector: 'link[rel="stylesheet"]', | ||
preload: { | ||
selector: 'link[rel="preload"][as="style"]', | ||
attribute: 'href' | ||
selector: 'link[rel="preload"][as="style"]', | ||
attribute: 'href' | ||
}, | ||
@@ -50,3 +52,3 @@ links: { | ||
module.exports = function (src, type) { | ||
module.exports = (src, type) => { | ||
if (!src || !type) { | ||
@@ -56,6 +58,6 @@ throw new Error('`src` and `type` required'); | ||
var chosenType = types[type]; | ||
var $ = cheerio.load(src); | ||
const chosenType = types[type]; | ||
const $ = cheerio.load(src); | ||
return $(chosenType.selector).map(function (i, el) { | ||
return $(chosenType.selector).map((i, el) => { | ||
return $(el).attr(chosenType.attribute); | ||
@@ -70,12 +72,13 @@ }).toArray(); | ||
var chosenType = types[type]; | ||
var $ = cheerio.load(src); | ||
const chosenType = types[type]; | ||
const $ = cheerio.load(src); | ||
return Array.prototype.map.call($(chosenType.selector), function(el) { | ||
var $el = $(el); | ||
return Array.prototype.map.call($(chosenType.selector), el => { | ||
const $el = $(el); | ||
return { | ||
$el: $el, | ||
$el, | ||
value: $el.attr(chosenType.attribute) | ||
} | ||
}; | ||
}); | ||
}; |
{ | ||
"name": "oust", | ||
"version": "0.4.0", | ||
"author": "Addy Osmani <addyosmani@gmail.com> (http://addyosmani.com)", | ||
"version": "0.5.1", | ||
"author": "Addy Osmani <addyosmani@gmail.com> (https://addyosmani.com/)", | ||
"license": "Apache-2.0", | ||
@@ -9,3 +9,3 @@ "description": "Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML", | ||
"type": "git", | ||
"url": "https://github.com/addyosmani/oust.git" | ||
"url": "git+https://github.com/addyosmani/oust.git" | ||
}, | ||
@@ -25,10 +25,13 @@ "bugs": { | ||
"scripts": { | ||
"test": "mocha" | ||
"mocha": "mocha", | ||
"test": "npm run xo && npm run mocha", | ||
"xo": "xo" | ||
}, | ||
"dependencies": { | ||
"cheerio": "^0.19.0", | ||
"minimist": "^1.1.0" | ||
"cheerio": "^0.22.0", | ||
"minimist": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"mocha": "^5.2.0", | ||
"xo": "^0.23.0" | ||
}, | ||
@@ -43,4 +46,10 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=6" | ||
}, | ||
"xo": { | ||
"space": 4, | ||
"rules": { | ||
"valid-jsdoc": "off" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# oust [](https://travis-ci.org/addyosmani/oust) | ||
# oust [](https://travis-ci.org/addyosmani/oust) [](https://david-dm.org/addyosmani/oust) [](https://david-dm.org/addyosmani/oust?type=dev) | ||
@@ -62,3 +62,4 @@ > Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML | ||
#### Extract cheerio elements alongside the value | ||
Usefull for post processing/filtering as you get an array of matched elements | ||
Usefull for post processing/filtering as you get an array of matched elements | ||
with cheerio convenience syntax (e.g. `$el.attr()`) | ||
@@ -65,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
18226
5.6%104
0.97%133
0.76%2
100%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated