UNPKG

anime-info

Version:

Plugin intended to collect informing of anime characters through the fandow wiki

258 lines (257 loc) 14.4 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); var models_1 = require("../shared/models"); var models_2 = require("./models"); var elements_dom_1 = require("../shared/utils/elements.dom"); var utils_1 = require("./utils"); var OnePunchMan = /** @class */ (function (_super) { __extends(OnePunchMan, _super); function OnePunchMan(config) { if (config === void 0) { config = { lang: 'en' }; } return _super.call(this, config.lang, utils_1.getTagByLang(config.lang), "https://onepunchman.fandom.com/" + config.lang + "/wiki/", models_2.defaultOptionFieldsOnePunchMan, models_2.charactersOnePunchMan) || this; } OnePunchMan.prototype._toJson = function (keys) { if (keys === void 0) { keys = []; } return __awaiter(this, void 0, void 0, function () { var one_punch_man, promises; var _this = this; return __generator(this, function (_a) { switch (_a.label) { case 0: one_punch_man = {}; return [4 /*yield*/, keys.map(function (value) { return __awaiter(_this, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: _a = value; switch (_a) { case 'abilities': return [3 /*break*/, 1]; case 'affiliation': return [3 /*break*/, 2]; case 'age': return [3 /*break*/, 3]; case 'alias': return [3 /*break*/, 4]; case 'class': return [3 /*break*/, 5]; case 'description': return [3 /*break*/, 6]; case 'gallery': return [3 /*break*/, 7]; case 'height': return [3 /*break*/, 9]; case 'location': return [3 /*break*/, 10]; case 'name': return [3 /*break*/, 11]; case 'occupation': return [3 /*break*/, 12]; case 'partner': return [3 /*break*/, 13]; case 'photo': return [3 /*break*/, 14]; case 'race': return [3 /*break*/, 15]; case 'rank': return [3 /*break*/, 16]; case 'sex': return [3 /*break*/, 17]; case 'status': return [3 /*break*/, 18]; case 'weight': return [3 /*break*/, 19]; } return [3 /*break*/, 20]; case 1: one_punch_man.abilities = this._abilities(); return [3 /*break*/, 21]; case 2: one_punch_man.affiliation = this._affiliation(); return [3 /*break*/, 21]; case 3: one_punch_man.age = this._age(); return [3 /*break*/, 21]; case 4: one_punch_man.alias = this._alias(); return [3 /*break*/, 21]; case 5: one_punch_man.class = this._class(); return [3 /*break*/, 21]; case 6: one_punch_man.description = this._description(); return [3 /*break*/, 21]; case 7: _b = one_punch_man; return [4 /*yield*/, this._gallery()]; case 8: _b.gallery = _c.sent(); return [3 /*break*/, 21]; case 9: one_punch_man.height = this._height(); return [3 /*break*/, 21]; case 10: one_punch_man.location = this._location(); return [3 /*break*/, 21]; case 11: one_punch_man.name = this._name(); return [3 /*break*/, 21]; case 12: one_punch_man.occupation = this._occupation(); return [3 /*break*/, 21]; case 13: one_punch_man.partner = this._partner(); return [3 /*break*/, 21]; case 14: one_punch_man.photo = this._photo(); return [3 /*break*/, 21]; case 15: one_punch_man.race = this._race(); return [3 /*break*/, 21]; case 16: one_punch_man.rank = this._rank(); return [3 /*break*/, 21]; case 17: one_punch_man.sex = this._sex(); return [3 /*break*/, 21]; case 18: one_punch_man.status = this._status(); return [3 /*break*/, 21]; case 19: one_punch_man.weight = this._weight(); return [3 /*break*/, 21]; case 20: return [3 /*break*/, 21]; case 21: return [2 /*return*/]; } }); }); })]; case 1: promises = _a.sent(); return [4 /*yield*/, Promise.all(promises)]; case 2: _a.sent(); return [2 /*return*/, one_punch_man]; } }); }); }; OnePunchMan.prototype._abilities = function () { return elements_dom_1.getAndRemoveTagBr(this._document, this._tags.abilities); }; OnePunchMan.prototype._partner = function () { return elements_dom_1.getAndRemoveTagBr(this._document, this._tags.partner); }; OnePunchMan.prototype._age = function () { return elements_dom_1.$Query(this._document, this._tags.age); }; OnePunchMan.prototype._alias = function () { return elements_dom_1.getAndRemoveTagBr(this._document, this._tags.alias); }; OnePunchMan.prototype._class = function () { if (this._lang === 'es') { return elements_dom_1.$Query(this._document, this._tags.class); } var rank = this._rank(); var classes = rank .filter(function (value) { return /-Class/g.test(value); }) .map(function (value) { return value.trim().slice(0, 1); }) .sort(function (a, b) { if (a > b || b === 'S') return -1; if (a < b || a === 'S') return 1; return 0; }); return classes[classes.length - 1]; }; OnePunchMan.prototype._description = function () { return elements_dom_1.$Query(this._document, this._tags.description); }; OnePunchMan.prototype._gallery = function () { return __awaiter(this, void 0, void 0, function () { var gallery; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, utils_1.getGallery(this._baseUrl + this._character, this._tags.gallery, this._lang)]; case 1: gallery = _a.sent(); return [2 /*return*/, gallery]; } }); }); }; OnePunchMan.prototype._height = function () { return elements_dom_1.$Query(this._document, this._tags.height); }; OnePunchMan.prototype._location = function () { return elements_dom_1.getListElement(this._document, this._tags.location); }; OnePunchMan.prototype._name = function () { return elements_dom_1.$Query(this._document, this._tags.name); }; OnePunchMan.prototype._occupation = function () { return elements_dom_1.getAndRemoveTagBr(this._document, this._tags.occupation); }; OnePunchMan.prototype._affiliation = function () { return elements_dom_1.getAndRemoveTagBr(this._document, this._tags.affiliation); }; OnePunchMan.prototype._photo = function () { return elements_dom_1.getNameAndAllImageCharacter(this._document, this._tags.photo); }; OnePunchMan.prototype._race = function () { var race = []; if (this._lang === 'es') { race.push.apply(race, elements_dom_1.getAndRemoveTagBr(this._document, this._tags.race)); } else { race.push.apply(race, elements_dom_1.getListElement(this._document, this._tags.race)); } return race; }; OnePunchMan.prototype._rank = function () { return elements_dom_1.getAndRemoveTagBr(this._document, this._tags.rank); }; OnePunchMan.prototype._sex = function () { return elements_dom_1.$Query(this._document, this._tags.sex); }; OnePunchMan.prototype._status = function () { return elements_dom_1.$Query(this._document, this._tags.status); }; OnePunchMan.prototype._weight = function () { return elements_dom_1.$Query(this._document, this._tags.weight); }; return OnePunchMan; }(models_1.AnimesGeneric)); exports.OnePunchMan = OnePunchMan;