masticate 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/attributes.js +13 -38
- package/lib/canonical_url_parser.js +7 -17
- package/lib/data_vocabulary_recipe_parser.js +14 -35
- package/lib/hrecipe_parser.js +14 -47
- package/lib/hrecipe_parser.spec.js +52 -67
- package/lib/html_recipe_parser.js +13 -34
- package/lib/index.js +39 -95
- package/lib/non_standard/all_recipes_parser.js +17 -35
- package/lib/non_standard/all_recipes_parser.spec.js +53 -66
- package/lib/non_standard/chowhound_parser.js +14 -36
- package/lib/non_standard/chowhound_parser.spec.js +53 -64
- package/lib/non_standard/epicurious_parser.js +18 -38
- package/lib/non_standard/epicurious_parser.spec.js +42 -55
- package/lib/recipe.js +7 -15
- package/lib/recipe_parser.js +9 -27
- package/lib/schema_org_json_recipe_parser.js +18 -53
- package/lib/schema_org_json_recipe_parser.spec.js +162 -206
- package/lib/schema_org_recipe_parser.js +14 -47
- package/lib/schema_org_recipe_parser.spec.js +53 -68
- package/package.json +6 -6
@@ -1,55 +1,34 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
function _typeof(
|
4
|
-
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.HtmlRecipeParser = void 0;
|
9
|
-
|
10
8
|
var _cheerio = _interopRequireDefault(require("cheerio"));
|
11
|
-
|
12
9
|
var _recipe_parser = require("./recipe_parser");
|
13
|
-
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
15
|
-
|
16
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
17
|
-
|
11
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
18
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
19
|
-
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
20
15
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
21
|
-
|
22
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
23
|
-
|
24
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
25
|
-
|
26
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
27
|
-
|
16
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
28
17
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
29
|
-
|
30
18
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
31
|
-
|
32
|
-
function
|
33
|
-
|
34
|
-
function
|
35
|
-
|
36
|
-
var HtmlRecipeParser = /*#__PURE__*/function (_RecipeParser) {
|
37
|
-
_inherits(HtmlRecipeParser, _RecipeParser);
|
38
|
-
|
39
|
-
var _super = _createSuper(HtmlRecipeParser);
|
40
|
-
|
19
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
20
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
21
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
22
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
23
|
+
var HtmlRecipeParser = exports.HtmlRecipeParser = /*#__PURE__*/function (_RecipeParser) {
|
41
24
|
function HtmlRecipeParser(doc) {
|
42
25
|
var _this;
|
43
|
-
|
44
26
|
_classCallCheck(this, HtmlRecipeParser);
|
45
|
-
|
46
|
-
_this = _super.call(this, doc);
|
27
|
+
_this = _callSuper(this, HtmlRecipeParser, [doc]);
|
47
28
|
_this.recipe_node = _this.doc(_this.constructor.root_selector).first();
|
48
29
|
_this.nutrition_node = _this.doc(_this.constructor.nutrition_selector).first();
|
49
30
|
return _this;
|
50
31
|
}
|
51
|
-
|
32
|
+
_inherits(HtmlRecipeParser, _RecipeParser);
|
52
33
|
return _createClass(HtmlRecipeParser);
|
53
|
-
}(_recipe_parser.RecipeParser);
|
54
|
-
|
55
|
-
exports.HtmlRecipeParser = HtmlRecipeParser;
|
34
|
+
}(_recipe_parser.RecipeParser);
|
package/lib/index.js
CHANGED
@@ -4,129 +4,73 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.Masticate = void 0;
|
7
|
-
|
8
7
|
require("core-js/stable");
|
9
|
-
|
10
8
|
require("regenerator-runtime/runtime");
|
11
|
-
|
12
9
|
var _all_recipes_parser = require("./non_standard/all_recipes_parser");
|
13
|
-
|
14
10
|
var _chowhound_parser = require("./non_standard/chowhound_parser");
|
15
|
-
|
16
11
|
var _epicurious_parser = require("./non_standard/epicurious_parser");
|
17
|
-
|
18
12
|
var _schema_org_json_recipe_parser = require("./schema_org_json_recipe_parser");
|
19
|
-
|
20
13
|
var _schema_org_recipe_parser = require("./schema_org_recipe_parser");
|
21
|
-
|
22
14
|
var _hrecipe_parser = require("./hrecipe_parser");
|
23
|
-
|
24
15
|
var _attributes = require("./attributes");
|
25
|
-
|
26
16
|
var _cheerio = _interopRequireDefault(require("cheerio"));
|
27
|
-
|
28
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
29
|
-
|
30
|
-
function
|
31
|
-
|
32
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
33
|
-
|
34
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
35
|
-
|
18
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
19
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
36
20
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
37
|
-
|
38
21
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
39
|
-
|
40
22
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
41
|
-
|
42
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
43
|
-
|
23
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
44
24
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
45
|
-
|
25
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
26
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
46
27
|
var parsers = [_all_recipes_parser.AllRecipesParser, _chowhound_parser.ChowhoundParser, _epicurious_parser.EpicuriousParser, _schema_org_json_recipe_parser.SchemaOrgJsonRecipeParser, _schema_org_recipe_parser.SchemaOrgRecipeParser, _hrecipe_parser.HRecipeParser];
|
47
|
-
|
48
|
-
var Masticate = /*#__PURE__*/function () {
|
28
|
+
var Masticate = exports.Masticate = /*#__PURE__*/function () {
|
49
29
|
function Masticate() {
|
50
30
|
_classCallCheck(this, Masticate);
|
51
31
|
}
|
52
|
-
|
53
|
-
_createClass(Masticate, null, [{
|
32
|
+
return _createClass(Masticate, null, [{
|
54
33
|
key: "parse",
|
55
34
|
value: function () {
|
56
|
-
var _parse = _asyncToGenerator( /*#__PURE__*/
|
57
|
-
var doc,
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
_context.
|
66
|
-
|
67
|
-
_iterator.s();
|
68
|
-
|
69
|
-
case 4:
|
70
|
-
if ((_step = _iterator.n()).done) {
|
71
|
-
_context.next = 16;
|
72
|
-
break;
|
73
|
-
}
|
74
|
-
|
75
|
-
parser = _step.value;
|
76
|
-
|
77
|
-
if (!parser.can_parse(doc)) {
|
78
|
-
_context.next = 14;
|
79
|
-
break;
|
80
|
-
}
|
81
|
-
|
82
|
-
p = new parser(doc);
|
83
|
-
_context.next = 10;
|
84
|
-
return p.parse();
|
85
|
-
|
86
|
-
case 10:
|
87
|
-
recipe = _context.sent;
|
88
|
-
cleaner = new _attributes.AttributeCleaner(recipe);
|
89
|
-
recipe = cleaner.clean();
|
90
|
-
return _context.abrupt("return", recipe);
|
91
|
-
|
92
|
-
case 14:
|
93
|
-
_context.next = 4;
|
35
|
+
var _parse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(html) {
|
36
|
+
var doc, _i, _parsers, parser, p, recipe, cleaner;
|
37
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
38
|
+
while (1) switch (_context.prev = _context.next) {
|
39
|
+
case 0:
|
40
|
+
doc = _cheerio["default"].load(html);
|
41
|
+
_i = 0, _parsers = parsers;
|
42
|
+
case 2:
|
43
|
+
if (!(_i < _parsers.length)) {
|
44
|
+
_context.next = 15;
|
94
45
|
break;
|
95
|
-
|
96
|
-
|
97
|
-
|
46
|
+
}
|
47
|
+
parser = _parsers[_i];
|
48
|
+
if (!parser.can_parse(doc)) {
|
49
|
+
_context.next = 12;
|
98
50
|
break;
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
return _context.stop();
|
116
|
-
}
|
51
|
+
}
|
52
|
+
p = new parser(doc);
|
53
|
+
_context.next = 8;
|
54
|
+
return p.parse();
|
55
|
+
case 8:
|
56
|
+
recipe = _context.sent;
|
57
|
+
cleaner = new _attributes.AttributeCleaner(recipe);
|
58
|
+
recipe = cleaner.clean();
|
59
|
+
return _context.abrupt("return", recipe);
|
60
|
+
case 12:
|
61
|
+
_i++;
|
62
|
+
_context.next = 2;
|
63
|
+
break;
|
64
|
+
case 15:
|
65
|
+
case "end":
|
66
|
+
return _context.stop();
|
117
67
|
}
|
118
|
-
}, _callee
|
68
|
+
}, _callee);
|
119
69
|
}));
|
120
|
-
|
121
70
|
function parse(_x) {
|
122
71
|
return _parse.apply(this, arguments);
|
123
72
|
}
|
124
|
-
|
125
73
|
return parse;
|
126
74
|
}()
|
127
75
|
}]);
|
128
|
-
|
129
|
-
return Masticate;
|
130
|
-
}();
|
131
|
-
|
132
|
-
exports.Masticate = Masticate;
|
76
|
+
}();
|
@@ -1,51 +1,37 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
function _typeof(
|
4
|
-
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.AllRecipesParser = void 0;
|
9
|
-
|
10
8
|
var _schema_org_recipe_parser = require("../schema_org_recipe_parser");
|
11
|
-
|
12
9
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
13
|
-
|
14
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
15
|
-
|
10
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
16
11
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
17
|
-
|
18
|
-
function
|
19
|
-
|
20
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
21
|
-
|
22
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
23
|
-
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
13
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
14
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
24
15
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
25
|
-
|
26
16
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
27
|
-
|
28
|
-
function
|
29
|
-
|
30
|
-
function
|
31
|
-
|
32
|
-
var AllRecipesParser = /*#__PURE__*/function (_SchemaOrgRecipeParse) {
|
33
|
-
_inherits(AllRecipesParser, _SchemaOrgRecipeParse);
|
34
|
-
|
35
|
-
var _super = _createSuper(AllRecipesParser);
|
36
|
-
|
17
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
18
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
19
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
20
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
21
|
+
var AllRecipesParser = exports.AllRecipesParser = /*#__PURE__*/function (_SchemaOrgRecipeParse) {
|
37
22
|
function AllRecipesParser() {
|
38
23
|
_classCallCheck(this, AllRecipesParser);
|
39
|
-
|
40
|
-
return _super.apply(this, arguments);
|
24
|
+
return _callSuper(this, AllRecipesParser, arguments);
|
41
25
|
}
|
42
|
-
|
43
|
-
_createClass(AllRecipesParser, [{
|
26
|
+
_inherits(AllRecipesParser, _SchemaOrgRecipeParse);
|
27
|
+
return _createClass(AllRecipesParser, [{
|
44
28
|
key: "parse_name",
|
45
|
-
value:
|
29
|
+
value:
|
30
|
+
// parse_instructions() {
|
46
31
|
// var node = this.recipe_node.find('.directions ol').first();
|
47
32
|
// return node.text();
|
48
33
|
// }
|
34
|
+
|
49
35
|
function parse_name() {
|
50
36
|
var node = this.recipe_node.find(".recipe-summary [itemprop = \"name\"]").first();
|
51
37
|
return node ? node.text() : null;
|
@@ -56,8 +42,4 @@ var AllRecipesParser = /*#__PURE__*/function (_SchemaOrgRecipeParse) {
|
|
56
42
|
return this.matches_domain(html, 'allrecipes.com');
|
57
43
|
}
|
58
44
|
}]);
|
59
|
-
|
60
|
-
return AllRecipesParser;
|
61
|
-
}(_schema_org_recipe_parser.SchemaOrgRecipeParser);
|
62
|
-
|
63
|
-
exports.AllRecipesParser = AllRecipesParser;
|
45
|
+
}(_schema_org_recipe_parser.SchemaOrgRecipeParser);
|
@@ -1,78 +1,65 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
3
4
|
var _index = require("../index");
|
4
|
-
|
5
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
5
6
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
6
|
-
|
7
7
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
8
|
-
|
9
8
|
var fs = require("fs");
|
10
|
-
|
11
9
|
var expect = require("chai").expect;
|
12
|
-
|
13
10
|
describe("AllRecipeParser", function () {
|
14
|
-
it("sets all values", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/
|
15
|
-
return
|
16
|
-
while (1) {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
var
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
expected = ["1/2 cup Parmesan cheese", "3/4 teaspoon ground black pepper", "1/2 teaspoon garlic powder", "1 (17.5 ounce) package frozen puff pastry, thawed", "1 egg white"];
|
38
|
-
|
39
|
-
for (i = 0; i > rec.ingredients.length; i++) {
|
40
|
-
expect(rec.ingredients[i]).to.equal([expected[i]]);
|
41
|
-
}
|
42
|
-
|
43
|
-
expect(rec.instructions).to.equal("Combine parmesan cheese, pepper and garlic powder. Unfold pastry sheets onto cutting board. Brush lightly with egg white; sprinkle each sheet with 1/4 of the cheese mixture. Lightly press into pastry, turn over; repeat. Cut each sheet into 12 (1-inch) strips; twist.\nPlace on ungreased cookie sheet and bake in 350 degrees F (175 degrees C) oven for 15 minutes or until golden brown.");
|
44
|
-
expect(rec.prep_time).to.equal(null);
|
45
|
-
expect(rec.published_date).to.equal(null);
|
46
|
-
expect(rec["yield"]).to.equal('24');
|
47
|
-
expect(rec.nutrition.calories).to.equal('121 kcal');
|
48
|
-
expect(rec.nutrition.cholesterol).to.equal('1 mg');
|
49
|
-
expect(rec.nutrition.fiber).to.equal(null);
|
50
|
-
expect(rec.nutrition.protein).to.equal('2.3 g');
|
51
|
-
expect(rec.nutrition.saturated_fat).to.equal(null);
|
52
|
-
expect(rec.nutrition.sodium).to.equal('79 mg');
|
53
|
-
expect(rec.nutrition.sugar).to.equal(null);
|
54
|
-
expect(rec.nutrition.total_carbohydrates).to.equal('9.4g');
|
55
|
-
expect(rec.nutrition.total_fat).to.equal('8.3 g');
|
56
|
-
expect(rec.nutrition.trans_fat).to.equal(null);
|
57
|
-
expect(rec.nutrition.unsaturated_fat).to.equal(null);
|
58
|
-
|
59
|
-
case 26:
|
60
|
-
case "end":
|
61
|
-
return _context.stop();
|
11
|
+
it("sets all values", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
12
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
13
|
+
while (1) switch (_context2.prev = _context2.next) {
|
14
|
+
case 0:
|
15
|
+
fs.readFile("test/fixtures/all_recipes.html", /*#__PURE__*/function () {
|
16
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err, html) {
|
17
|
+
var rec, expected, i;
|
18
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
19
|
+
while (1) switch (_context.prev = _context.next) {
|
20
|
+
case 0:
|
21
|
+
_context.next = 2;
|
22
|
+
return _index.Masticate.parse(html);
|
23
|
+
case 2:
|
24
|
+
rec = _context.sent;
|
25
|
+
expect(rec.name).to.equal("Crispy Cheese Twists");
|
26
|
+
expect(rec.author).to.equal("Stephanie");
|
27
|
+
expect(rec.cook_time).to.equal(null);
|
28
|
+
expect(rec.description).to.equal("\"These are great as an appetizer or served alongside a meal!\"");
|
29
|
+
expect(rec.image_url).to.equal("http://images.media-allrecipes.com/userphotos/250x250/69987.jpg");
|
30
|
+
expect(rec.ingredients.length).to.equal(5);
|
31
|
+
expected = ["1/2 cup Parmesan cheese", "3/4 teaspoon ground black pepper", "1/2 teaspoon garlic powder", "1 (17.5 ounce) package frozen puff pastry, thawed", "1 egg white"];
|
32
|
+
for (i = 0; i > rec.ingredients.length; i++) {
|
33
|
+
expect(rec.ingredients[i]).to.equal([expected[i]]);
|
62
34
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
35
|
+
expect(rec.instructions).to.equal("Combine parmesan cheese, pepper and garlic powder. Unfold pastry sheets onto cutting board. Brush lightly with egg white; sprinkle each sheet with 1/4 of the cheese mixture. Lightly press into pastry, turn over; repeat. Cut each sheet into 12 (1-inch) strips; twist.\nPlace on ungreased cookie sheet and bake in 350 degrees F (175 degrees C) oven for 15 minutes or until golden brown.");
|
36
|
+
expect(rec.prep_time).to.equal(null);
|
37
|
+
expect(rec.published_date).to.equal(null);
|
38
|
+
expect(rec["yield"]).to.equal('24');
|
39
|
+
expect(rec.nutrition.calories).to.equal('121 kcal');
|
40
|
+
expect(rec.nutrition.cholesterol).to.equal('1 mg');
|
41
|
+
expect(rec.nutrition.fiber).to.equal(null);
|
42
|
+
expect(rec.nutrition.protein).to.equal('2.3 g');
|
43
|
+
expect(rec.nutrition.saturated_fat).to.equal(null);
|
44
|
+
expect(rec.nutrition.sodium).to.equal('79 mg');
|
45
|
+
expect(rec.nutrition.sugar).to.equal(null);
|
46
|
+
expect(rec.nutrition.total_carbohydrates).to.equal('9.4g');
|
47
|
+
expect(rec.nutrition.total_fat).to.equal('8.3 g');
|
48
|
+
expect(rec.nutrition.trans_fat).to.equal(null);
|
49
|
+
expect(rec.nutrition.unsaturated_fat).to.equal(null);
|
50
|
+
case 26:
|
51
|
+
case "end":
|
52
|
+
return _context.stop();
|
53
|
+
}
|
54
|
+
}, _callee);
|
55
|
+
}));
|
56
|
+
return function (_x, _x2) {
|
57
|
+
return _ref2.apply(this, arguments);
|
58
|
+
};
|
59
|
+
}());
|
60
|
+
case 1:
|
61
|
+
case "end":
|
62
|
+
return _context2.stop();
|
76
63
|
}
|
77
64
|
}, _callee2);
|
78
65
|
})));
|
@@ -1,50 +1,32 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
function _typeof(
|
4
|
-
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
6
5
|
value: true
|
7
6
|
});
|
8
7
|
exports.ChowhoundParser = void 0;
|
9
|
-
|
10
8
|
var _schema_org_recipe_parser = require("../schema_org_recipe_parser");
|
11
|
-
|
12
9
|
var _cheerio = _interopRequireDefault(require("cheerio"));
|
13
|
-
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
15
|
-
|
16
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
17
|
-
|
18
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
19
|
-
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
20
13
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
21
|
-
|
22
|
-
function
|
23
|
-
|
24
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
25
|
-
|
26
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
27
|
-
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
16
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
28
17
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
29
|
-
|
30
18
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
31
|
-
|
32
|
-
function
|
33
|
-
|
34
|
-
function
|
35
|
-
|
36
|
-
var ChowhoundParser = /*#__PURE__*/function (_SchemaOrgRecipeParse) {
|
37
|
-
_inherits(ChowhoundParser, _SchemaOrgRecipeParse);
|
38
|
-
|
39
|
-
var _super = _createSuper(ChowhoundParser);
|
40
|
-
|
19
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
20
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
21
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
22
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
23
|
+
var ChowhoundParser = exports.ChowhoundParser = /*#__PURE__*/function (_SchemaOrgRecipeParse) {
|
41
24
|
function ChowhoundParser() {
|
42
25
|
_classCallCheck(this, ChowhoundParser);
|
43
|
-
|
44
|
-
return _super.apply(this, arguments);
|
26
|
+
return _callSuper(this, ChowhoundParser, arguments);
|
45
27
|
}
|
46
|
-
|
47
|
-
_createClass(ChowhoundParser, [{
|
28
|
+
_inherits(ChowhoundParser, _SchemaOrgRecipeParse);
|
29
|
+
return _createClass(ChowhoundParser, [{
|
48
30
|
key: "parse_name",
|
49
31
|
value: function parse_name() {
|
50
32
|
var node = this.recipe_node.find(".frajax_recipe_head [itemprop = \"name\"]").first();
|
@@ -57,8 +39,4 @@ var ChowhoundParser = /*#__PURE__*/function (_SchemaOrgRecipeParse) {
|
|
57
39
|
return this.matches_domain(html, 'chowhound.com');
|
58
40
|
}
|
59
41
|
}]);
|
60
|
-
|
61
|
-
return ChowhoundParser;
|
62
|
-
}(_schema_org_recipe_parser.SchemaOrgRecipeParser);
|
63
|
-
|
64
|
-
exports.ChowhoundParser = ChowhoundParser;
|
42
|
+
}(_schema_org_recipe_parser.SchemaOrgRecipeParser);
|