Comparing version 2.0.2 to 2.1.0
@@ -14,3 +14,3 @@ ## Documentation | ||
#### Return | ||
- **Tinyreq** The request object. | ||
- **Promise** A promise object. | ||
@@ -26,3 +26,2 @@ ### `scrapeIt.scrapeCheerio($, opts)` | ||
- `listItem` (String): The list item selector. | ||
- `name` (String): The list name (e.g. `articles`). | ||
- `data` (Object): The fields to include in the list objects: | ||
@@ -29,0 +28,0 @@ - `<fieldName>` (Object|String): The selector or an object containing: |
@@ -5,3 +5,16 @@ "use strict"; | ||
// Promise interface | ||
scrapeIt("http://ionicabizau.net", { | ||
title: ".header h1" | ||
, desc: ".header h2" | ||
, avatar: { | ||
selector: ".header img" | ||
, attr: "src" | ||
} | ||
}).then(page => { | ||
console.log(page); | ||
}); | ||
// Callback interface | ||
scrapeIt("http://ionicabizau.net", { | ||
// Fetch the articles | ||
@@ -8,0 +21,0 @@ articles: { |
@@ -9,2 +9,3 @@ "use strict"; | ||
, emptyObj = require("is-empty-obj") | ||
, assured = require("assured") | ||
; | ||
@@ -21,5 +22,6 @@ | ||
* @param {Function} cb The callback function. | ||
* @return {Tinyreq} The request object. | ||
* @return {Promise} A promise object. | ||
*/ | ||
function scrapeIt (url, opts, cb) { | ||
cb = assured(cb); | ||
req(url, (err, $, res, body) => { | ||
@@ -29,2 +31,3 @@ if (err) { return cb(err); } | ||
}); | ||
return cb._; | ||
} | ||
@@ -44,3 +47,2 @@ | ||
* - `listItem` (String): The list item selector. | ||
* - `name` (String): The list name (e.g. `articles`). | ||
* - `data` (Object): The fields to include in the list objects: | ||
@@ -47,0 +49,0 @@ * - `<fieldName>` (Object|String): The selector or an object containing: |
@@ -14,3 +14,3 @@ { | ||
"license": "MIT", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"main": "lib/index.js", | ||
@@ -33,2 +33,3 @@ "scripts": { | ||
"dependencies": { | ||
"assured": "^1.0.0", | ||
"cheerio-req": "^1.0.0", | ||
@@ -35,0 +36,0 @@ "err": "^2.1.1", |
@@ -24,3 +24,16 @@ | ||
// Promise interface | ||
scrapeIt("http://ionicabizau.net", { | ||
title: ".header h1" | ||
, desc: ".header h2" | ||
, avatar: { | ||
selector: ".header img" | ||
, attr: "src" | ||
} | ||
}).then(page => { | ||
console.log(page); | ||
}); | ||
// Callback interface | ||
scrapeIt("http://ionicabizau.net", { | ||
// Fetch the articles | ||
@@ -112,3 +125,3 @@ articles: { | ||
#### Return | ||
- **Tinyreq** The request object. | ||
- **Promise** A promise object. | ||
@@ -124,3 +137,2 @@ ### `scrapeIt.scrapeCheerio($, opts)` | ||
- `listItem` (String): The list item selector. | ||
- `name` (String): The list name (e.g. `articles`). | ||
- `data` (Object): The fields to include in the list objects: | ||
@@ -127,0 +139,0 @@ - `<fieldName>` (Object|String): The selector or an object containing: |
@@ -56,2 +56,21 @@ const tester = require("tester") | ||
}); | ||
t.it("promise version", cb => { | ||
scrapeIt(URL, { | ||
features: { | ||
listItem: ".features > li" | ||
} | ||
}).then(page => { | ||
t.expect(page).toEqual({ | ||
features: [ | ||
"1" | ||
, "2" | ||
, "3" | ||
, "4" | ||
, "5" | ||
, "6" | ||
] | ||
}); | ||
cb(); | ||
}); | ||
}); | ||
@@ -58,0 +77,0 @@ t.it("end", () => { |
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
22805
305
207
7
+ Addedassured@^1.0.0