Comparing version 0.5.2 to 1.0.0
24
cli.js
@@ -7,3 +7,3 @@ #!/usr/bin/env node | ||
const minimist = require('minimist'); | ||
const pkg = require('./package.json'); | ||
const {description, version} = require('./package.json'); | ||
const oust = require('.'); | ||
@@ -14,15 +14,14 @@ | ||
function printHelp() { | ||
console.log([ | ||
pkg.description, | ||
'', | ||
'Usage', | ||
' $ oust <filename> <type>', | ||
'', | ||
'Example', | ||
' $ oust index.html scripts' | ||
].join('\n')); | ||
console.log(` | ||
${description} | ||
Usage: | ||
$ oust <filename> <type> | ||
Example: | ||
$ oust index.html scripts`); | ||
} | ||
if (argv.v || argv.version) { | ||
console.log(pkg.version); | ||
console.log(version); | ||
process.exit(0); | ||
@@ -36,4 +35,3 @@ } | ||
const file = argv._[0]; | ||
const type = argv._[1]; | ||
const [file, type] = argv._; | ||
@@ -40,0 +38,0 @@ fs.readFile(file, (err, data) => { |
35
index.js
@@ -50,3 +50,3 @@ /*! | ||
module.exports = (src, type) => { | ||
function oust(src, type, raw) { | ||
if (!src || !type) { | ||
@@ -56,13 +56,8 @@ throw new Error('`src` and `type` required'); | ||
const chosenType = types[type]; | ||
const $ = cheerio.load(src); | ||
const validTypes = Object.keys(types); | ||
return $(chosenType.selector).map((i, el) => { | ||
return $(el).attr(chosenType.attribute); | ||
}).toArray(); | ||
}; | ||
module.exports.raw = function (src, type) { | ||
if (!src || !type) { | ||
throw new Error('`src` and `type` required'); | ||
if (!validTypes.includes(type)) { | ||
throw new Error( | ||
`Invalid \`type\` value "${type}". Choose one of: ${validTypes.join(', ')}` | ||
); | ||
} | ||
@@ -76,7 +71,15 @@ | ||
return { | ||
$el, | ||
value: $el.attr(chosenType.attribute) | ||
}; | ||
if (raw) { | ||
return { | ||
$el, | ||
value: $el.attr(chosenType.attribute) | ||
}; | ||
} | ||
return $el.attr(chosenType.attribute); | ||
}); | ||
}; | ||
} | ||
module.exports = (src, type) => oust(src, type, false); | ||
module.exports.raw = (src, type) => oust(src, type, true); |
{ | ||
"name": "oust", | ||
"version": "0.5.2", | ||
"version": "1.0.0", | ||
"author": "Addy Osmani <addyosmani@gmail.com> (https://addyosmani.com/)", | ||
@@ -33,4 +33,4 @@ "license": "Apache-2.0", | ||
"devDependencies": { | ||
"mocha": "^6.1.3", | ||
"xo": "^0.24.0" | ||
"mocha": "^6.2.2", | ||
"xo": "^0.25.3" | ||
}, | ||
@@ -45,10 +45,7 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=8" | ||
}, | ||
"xo": { | ||
"space": 4, | ||
"rules": { | ||
"valid-jsdoc": "off" | ||
} | ||
"space": 4 | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# oust [![Build Status](https://img.shields.io/travis/addyosmani/oust/master.svg)](https://travis-ci.org/addyosmani/oust) [![dependencies Status](https://img.shields.io/david/addyosmani/oust.svg)](https://david-dm.org/addyosmani/oust) [![devDependencies Status](https://img.shields.io/david/dev/addyosmani/oust.svg)](https://david-dm.org/addyosmani/oust?type=dev) | ||
# oust [![Build Status](https://github.com/addyosmani/oust/workflows/Tests/badge.svg)](https://github.com/addyosmani/oust/actions?workflow=Tests) [![dependencies Status](https://img.shields.io/david/addyosmani/oust.svg)](https://david-dm.org/addyosmani/oust) [![devDependencies Status](https://img.shields.io/david/dev/addyosmani/oust.svg)](https://david-dm.org/addyosmani/oust?type=dev) | ||
@@ -9,3 +9,3 @@ > Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML | ||
```sh | ||
$ npm install --save-dev oust | ||
npm install --save-dev oust | ||
``` | ||
@@ -19,3 +19,3 @@ | ||
```js | ||
var oust = require('oust'); | ||
const oust = require('oust'); | ||
``` | ||
@@ -28,3 +28,3 @@ | ||
```js | ||
var hrefs = oust(htmlString, 'stylesheets'); | ||
const hrefs = oust(htmlString, 'stylesheets'); | ||
``` | ||
@@ -35,3 +35,3 @@ | ||
```js | ||
var hrefs = oust(htmlString, 'stylesheets', function(i, $el) { | ||
const hrefs = oust(htmlString, 'stylesheets', (i, $el) => { | ||
return $el.attr('media') === 'print'; | ||
@@ -44,3 +44,3 @@ }); | ||
```js | ||
var srcs = oust(htmlString, 'scripts'); | ||
const srcs = oust(htmlString, 'scripts'); | ||
``` | ||
@@ -51,3 +51,3 @@ | ||
```js | ||
var hrefs = oust(htmlString, 'imports'); | ||
const hrefs = oust(htmlString, 'imports'); | ||
``` | ||
@@ -58,3 +58,3 @@ | ||
```js | ||
var srcs = oust(htmlString, 'links'); | ||
const srcs = oust(htmlString, 'links'); | ||
``` | ||
@@ -65,3 +65,3 @@ | ||
```js | ||
var srcs = oust(htmlString, 'images'); | ||
const srcs = oust(htmlString, 'images'); | ||
``` | ||
@@ -75,3 +75,3 @@ | ||
```js | ||
var srcs = oust.raw(htmlString, '...'); | ||
const srcs = oust.raw(htmlString, '...'); | ||
@@ -92,4 +92,4 @@ -> [ | ||
--- | --- | --- | ||
`src` | `` | a valid HTML string to parse for references | ||
`type` | `` | one of `stylesheets`, `scripts`, `imports`, `links`, `images` | ||
`src` | not set | a valid HTML string to parse for references | ||
`type` | not set | one of `stylesheets`, `scripts`, `imports`, `links`, `images` | ||
@@ -99,3 +99,3 @@ ## CLI | ||
```sh | ||
$ npm install --global oust | ||
npm install --global oust | ||
``` | ||
@@ -113,3 +113,3 @@ | ||
```sh | ||
$ oust myFile.html stylesheets | ||
oust myFile.html stylesheets | ||
``` | ||
@@ -120,3 +120,3 @@ | ||
```sh | ||
$ oust myFile.html scripts | ||
oust myFile.html scripts | ||
``` | ||
@@ -127,3 +127,3 @@ | ||
```sh | ||
$ oust myFile.html imports | ||
oust myFile.html imports | ||
``` | ||
@@ -134,3 +134,3 @@ | ||
```sh | ||
$ oust myFile.html links | ||
oust myFile.html links | ||
``` | ||
@@ -141,3 +141,3 @@ | ||
```sh | ||
$ oust myFile.html images | ||
oust myFile.html images | ||
``` | ||
@@ -148,2 +148,2 @@ | ||
Released under an Apache 2 license. © Google 2014. | ||
Released under the [Apache 2 license. © Google 2014](LICENSE). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
0
17708
101