Comparing version 0.3.0 to 0.4.0
17
index.js
@@ -60,1 +60,18 @@ /*! | ||
}; | ||
module.exports.raw = function (src, type) { | ||
if (!src || !type) { | ||
throw new Error('`src` and `type` required'); | ||
} | ||
var chosenType = types[type]; | ||
var $ = cheerio.load(src); | ||
return Array.prototype.map.call($(chosenType.selector), function(el) { | ||
var $el = $(el); | ||
return { | ||
$el: $el, | ||
value: $el.attr(chosenType.attribute) | ||
} | ||
}); | ||
}; |
{ | ||
"name": "oust", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"author": "Addy Osmani <addyosmani@gmail.com> (http://addyosmani.com)", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -29,2 +29,10 @@ # oust [![Build Status](https://travis-ci.org/addyosmani/oust.svg?branch=master)](https://travis-ci.org/addyosmani/oust) | ||
#### Extract stylesheets references with media print `<link rel="stylesheet" media="print">` | ||
```js | ||
var hrefs = oust(htmlString, 'stylesheets', function(i, $el) { | ||
return $el.attr('media') === 'print'; | ||
}); | ||
``` | ||
#### Extract script references `<script src>` | ||
@@ -54,2 +62,17 @@ | ||
#### Extract cheerio elements alongside the value | ||
Usefull for post processing/filtering as you get an array of matched elements | ||
with cheerio convenience syntax (e.g. `$el.attr()`) | ||
```js | ||
var srcs = oust.raw(htmlString, '...'); | ||
-> [ | ||
{value: '...', $el: '...'}, | ||
{value: '...', $el: '...'}, | ||
... | ||
] | ||
``` | ||
## API | ||
@@ -64,3 +87,2 @@ | ||
## CLI | ||
@@ -67,0 +89,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
17259
103
132