UNPKG

webextension-store-meta

Version:

Get browser extension(webextension) item meta from Chrome Web Store and Firefox add-ons.

73 lines 2.84 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SourceReduxStoreState = void 0; const pretty_bytes_1 = __importDefault(require("pretty-bytes")); const dom_1 = require("../utils/dom"); const parse_1 = require("../utils/parse"); const utils_1 = require("./utils"); class SourceReduxStoreState { dom; /** @internal */ addonInfo; /** @internal */ versionInfo; constructor( /** @internal */ dom) { this.dom = dom; const elm = (0, dom_1.findOne)((el) => el.name === "script" && el.attribs.id === "redux-store-state", this.dom); if (elm) { const state = (0, parse_1.tryJSONParseObject)(elm.children[0]?.data); const ids = (0, parse_1.toPlainObject)((0, parse_1.toPlainObject)(state?.addons)?.byID); if (ids) { this.addonInfo = (0, parse_1.toPlainObject)(Object.values(ids)[0]); } const versionId = this.addonInfo?.currentVersionId; if (typeof versionId === "number" || typeof versionId === "string") { this.versionInfo = (0, parse_1.toPlainObject)((0, parse_1.toPlainObject)((0, parse_1.toPlainObject)(state?.versions)?.byId)?.[versionId]); } } } name() { return (0, parse_1.toStr)(this.addonInfo?.name); } description() { return (0, parse_1.toStr)(this.addonInfo?.description); } ratingValue() { return (0, utils_1.parseRattingValue)((0, parse_1.toPlainObject)(this.addonInfo?.ratings)?.average); } ratingCount() { return (0, parse_1.parseNum)((0, parse_1.toPlainObject)(this.addonInfo?.ratings)?.count); } users() { return (0, parse_1.parseNum)(this.addonInfo?.average_daily_users); } version() { return (0, parse_1.parseVersion)(this.versionInfo?.version); } url() { return (0, parse_1.toStr)(this.addonInfo?.url); } image() { return (0, parse_1.toStr)((0, parse_1.toPlainObject)((0, parse_1.toArray)(this.addonInfo?.previews)?.[0])?.src); } size() { const versionId = this.addonInfo?.currentVersionId; if (typeof versionId === "number" || typeof versionId === "string") { const size = (0, parse_1.parseNum)((0, parse_1.toPlainObject)(this.versionInfo?.file)?.size); if (size) { return (0, pretty_bytes_1.default)(size); } } return null; } lastUpdated() { return (0, parse_1.toStr)((0, parse_1.toPlainObject)(this.versionInfo?.file)?.created); } } exports.SourceReduxStoreState = SourceReduxStoreState; //# sourceMappingURL=SourceReduxStoreState.js.map