Comparing version 1.1.0 to 1.2.0
15
index.js
@@ -60,13 +60,19 @@ /*! | ||
const validTypes = Object.keys(types); | ||
const typeArray = Array.isArray(type) ? type : [type]; | ||
if (!validTypes.includes(type)) { | ||
throw new Error(`Invalid \`type\` value "${type}". Choose one of: ${validTypes.join(', ')}`); | ||
for (const type of typeArray) { | ||
if (!validTypes.includes(type)) { | ||
throw new Error(`Invalid \`type\` value "${type}". Choose one of: ${validTypes.join(', ')}`); | ||
} | ||
} | ||
const chosenType = types[type]; | ||
const chosenTypes = typeArray.map(type => ({...types[type], type})); | ||
const selector = chosenTypes.map(type => type.selector).join(', '); | ||
const $ = cheerio.load(src); | ||
return Array.prototype.map.call($(chosenType.selector), element => { | ||
return Array.prototype.map.call($(selector), element => { | ||
const $element = $(element); | ||
const chosenType = chosenTypes.find(type => $element.is(type.selector)); | ||
let value = ''; | ||
@@ -82,2 +88,3 @@ if (chosenType.method && $element[chosenType.method]) { | ||
$el: $element, | ||
type: chosenType.type, | ||
value | ||
@@ -84,0 +91,0 @@ }; |
{ | ||
"name": "oust", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"author": "Addy Osmani <addyosmani@gmail.com> (https://addyosmani.com/)", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -73,2 +73,8 @@ # 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) | ||
#### Extract preload and stylesheet references combined | ||
```js | ||
const hrefs = oust(htmlString, ['preload', 'stylesheets']); | ||
``` | ||
#### Extract cheerio elements alongside the value | ||
@@ -75,0 +81,0 @@ |
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
18713
115
151