@ginlink/chrome-webstore-meta
Version:
Get chrome extension item meta from Web Store.
3 lines (2 loc) • 9.55 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r=require("htmlparser2"),e=(t=require("axios"))&&"object"==typeof t&&"default"in t?t.default:t;function n(){n=function(){return r};var t,r={},e=Object.prototype,o=e.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function l(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{l({},"")}catch(t){l=function(t,r,e){return t[r]=e}}function h(t,r,e,n){var o=Object.create((r&&r.prototype instanceof g?r:g).prototype),a=new S(n||[]);return i(o,"_invoke",{value:j(t,e,a)}),o}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var p="suspendedStart",v="executing",d="completed",y={};function g(){}function m(){}function w(){}var b={};l(b,u,(function(){return this}));var x=Object.getPrototypeOf,L=x&&x(x(U([])));L&&L!==e&&o.call(L,u)&&(b=L);var E=w.prototype=g.prototype=Object.create(b);function O(t){["next","throw","return"].forEach((function(r){l(t,r,(function(t){return this._invoke(r,t)}))}))}function _(t,r){function e(n,i,a,u){var c=f(t[n],t,i);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&o.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function j(r,e,n){var o=p;return function(i,a){if(o===v)throw Error("Generator is already running");if(o===d){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=k(u,n);if(c){if(c===y)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=f(r,e,n);if("normal"===s.type){if(o=n.done?d:"suspendedYield",s.arg===y)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=d,n.method="throw",n.arg=s.arg)}}}function k(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,k(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var i=f(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,y;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,y):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function P(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function q(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function U(r){if(r||""===r){var e=r[u];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return m.prototype=w,i(E,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:m,configurable:!0}),m.displayName=l(w,s,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===m||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,l(t,s,"GeneratorFunction")),t.prototype=Object.create(E),t},r.awrap=function(t){return{__await:t}},O(_.prototype),l(_.prototype,c,(function(){return this})),r.AsyncIterator=_,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new _(h(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},O(E),l(E,s,"Generator"),l(E,u,(function(){return this})),l(E,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=U,S.prototype={constructor:S,reset:function(r){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(q),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return u.type="throw",u.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=o.call(a,"catchLoc"),s=o.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,r){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&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),q(e),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;q(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:U(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),y}},r}function o(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function i(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var a=t.apply(r,e);function u(t){o(a,n,i,u,c,"next",t)}function c(t){o(a,n,i,u,c,"throw",t)}u(void 0)}))}}var a=function(){function t(t){this.requester=t}return t.prototype.run=function(){var t=i(n().mark((function t(){var e,o,i,a,u,c;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.requester.get();case 2:if(e=t.sent,o={},i=new r.DomHandler(null),new r.Parser(i).end(e),r.DomUtils.getElementsByTagName("meta",i.dom,!0).forEach((function(t){var e=r.DomUtils.getAttributeValue(t,"property"),n=r.DomUtils.getAttributeValue(t,"content");if(e&&0===e.indexOf("og:")){var i=e.replace("og:","");return i=i.replace("title","name"),void(o[i.toLowerCase()]=n)}})),a=e.match(/<div[^>]*>([\d.]+)<\/div>/),u=null,a&&a.length>1&&(u=a[1]),o.version=u,0!==Object.keys(o).length){t.next=14;break}throw new Error("meta property not found");case 14:if(Object.prototype.hasOwnProperty.call(o,"url")&&o.url){t.next=16;break}throw new Error("url in response is required");case 16:return c=o.url.split("/"),o.id=c[c.length-1],t.abrupt("return",o);case 19:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),t}(),u={headers:{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"},qs:{hl:"en",gl:"US"}},c=function(){function t(t,r,e){if(!t)throw new Error("urlOrID is required");this.id=this.transformID(t),this.config={headers:(null==e?void 0:e.headers)||r.headers,qs:(null==e?void 0:e.qs)||r.qs}}var r=t.prototype;return r.transformID=function(t){var r=t=decodeURIComponent(t);if(/^(http|https)/.test(t)){var e=t.indexOf("detail/");r=t.substring(-1!==e?e+"detail/".length:0,t.length)}(r=r.replace(/^\/|\/$/g,"")).split("?").length>0&&(r=r.split("?")[0]);var n=r.split("/");return n.length>1&&(r=encodeURIComponent(n[0])+"/"+n.slice(1).join("/")),r},r.getConfig=function(){return this.config},r.getUrl=function(){var t=new URLSearchParams(this.config.qs).toString();return"https://chromewebstore.google.com/detail/"+this.id+"?"+t},t}(),s=function(){function t(t){this.prepare=t}return t.prototype.get=function(){return e.get(this.prepare.getUrl(),{headers:this.prepare.getConfig().headers}).then((function(t){return t.data}))},t}();function l(t,r){return h.apply(this,arguments)}function h(){return(h=i(n().mark((function t(r,e){var o,i,l;return n().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=new c(r,u,e),i=new s(o),l=new a(i),t.abrupt("return",l.run());case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}exports.default=l,exports.parse=l;
//# sourceMappingURL=chrome-webstore-meta.cjs.production.min.js.map