Comparing version
15
index.js
@@ -47,2 +47,6 @@ /*! | ||
attribute: 'src' | ||
}, | ||
styles: { | ||
selector: 'style', | ||
method: 'text' | ||
} | ||
@@ -68,10 +72,17 @@ }; | ||
let value = ''; | ||
if (chosenType.method && $element[chosenType.method]) { | ||
value = $element[chosenType.method](); | ||
} else if (chosenType.attribute) { | ||
value = $element.attr(chosenType.attribute); | ||
} | ||
if (raw) { | ||
return { | ||
$el: $element, | ||
value: $element.attr(chosenType.attribute) | ||
value | ||
}; | ||
} | ||
return $element.attr(chosenType.attribute); | ||
return value; | ||
}); | ||
@@ -78,0 +89,0 @@ } |
{ | ||
"name": "oust", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"author": "Addy Osmani <addyosmani@gmail.com> (https://addyosmani.com/)", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -49,2 +49,8 @@ # oust [](https://github.com/addyosmani/oust/actions?workflow=Tests) [](https://david-dm.org/addyosmani/oust) [](https://david-dm.org/addyosmani/oust?type=dev) | ||
#### Extract style preload references `<link rel="preload" as="style">` | ||
```js | ||
const hrefs = oust(htmlString, 'preload'); | ||
``` | ||
#### Extract URL references `<a href>` | ||
@@ -62,2 +68,8 @@ | ||
#### Extract inline styles `<style>...</style>` | ||
```js | ||
const styles = oust(htmlString, 'styles'); | ||
``` | ||
#### Extract cheerio elements alongside the value | ||
@@ -86,3 +98,3 @@ | ||
`src` | not set | a valid HTML string to parse for references | ||
`type` | not set | one of `stylesheets`, `scripts`, `imports`, `links`, `images` | ||
`type` | not set | one of `stylesheets`, `scripts`, `imports`, `preload`, `styles`, `links`, `images` | ||
@@ -89,0 +101,0 @@ ## CLI |
18253
2.85%109
10.1%145
9.02%