glancify
Version:
Get title, description and image from a URL for link preview purposes
3 lines (2 loc) • 3.34 kB
JavaScript
;function t(t,n,e,r,o,i,c){try{var u=t[i](c),a=u.value}catch(t){return void e(t)}u.done?n(a):Promise.resolve(a).then(r,o)}function n(n){return function(){var e=this,r=arguments;return new Promise((function(o,i){var c=n.apply(e,r);function u(n){t(c,o,i,u,a,"next",n)}function a(n){t(c,o,i,u,a,"throw",n)}u(void 0)}))}}function e(){var t,n,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",c=o.toStringTag||"@@toStringTag";function u(e,o,i,c){var u=Object.create((o&&o.prototype instanceof f?o:f).prototype);return r(u,"_invoke",function(e,r,o){var i,c,u,f=0,l=o||[],p=!1,s={p:0,n:0,v:t,a:v,f:v.bind(t,4),d:function(n,e){return i=n,c=0,u=t,s.n=e,a}};function v(e,r){for(c=e,u=r,n=0;!p&&f&&!o&&n<l.length;n++){var o,i=l[n],v=s.p,y=i[2];e>3?(o=y===r)&&(u=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=v&&((o=e<2&&v<i[1])?(c=0,s.v=r,s.n=i[1]):v<y&&(o=e<3||i[0]>r||r>y)&&(i[4]=e,i[5]=r,s.n=y,c=0))}if(o||e>1)return a;throw p=!0,r}return function(o,l,y){if(f>1)throw TypeError("Generator is already running");for(p&&1===l&&v(l,y),c=l,u=y;(n=c<2?t:u)||!p;){i||(c?c<3?(c>1&&(s.n=-1),v(c,u)):s.n=u:s.v=u);try{if(f=2,i){if(c||(o="next"),n=i[o]){if(!(n=n.call(i,u)))throw TypeError("iterator result is not an object");if(!n.done)return n;u=n.value,c<2&&(c=0)}else 1===c&&(n=i.return)&&n.call(i),c<2&&(u=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((n=(p=s.n<0)?u:e.call(r,s))!==a)break}catch(n){i=t,c=1,u=n}finally{f=1}}return{value:n,done:p}}}(e,i,c),!0),u}var a={};function f(){}function l(){}function p(){}n=Object.getPrototypeOf;var s=[][i]?n(n([][i]())):(r(n={},i,(function(){return this})),n),v=p.prototype=f.prototype=Object.create(s);function y(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,r(t,c,"GeneratorFunction")),t.prototype=Object.create(v),t}return l.prototype=p,r(v,"constructor",p),r(p,"constructor",l),l.displayName="GeneratorFunction",r(p,c,"GeneratorFunction"),r(v),r(v,c,"Generator"),r(v,i,(function(){return this})),r(v,"toString",(function(){return"[object Generator]"})),(e=function(){return{w:u,m:y}})()}function r(t,n,e,o){var i=Object.defineProperty;try{i({},"",{})}catch(t){i=0}(r=function(t,n,e,o){if(n)i?i(t,n,{value:e,enumerable:!o,configurable:!o,writable:!o}):t[n]=e;else{function c(n,e){r(t,n,(function(t){return this._invoke(n,e,t)}))}c("next",0),c("throw",1),c("return",2)}})(t,n,e,o)}Object.defineProperty(exports,"__esModule",{value:!0});var o=/<title[^>]*>([^<]+)<\/title>/,i=/<meta[^>]*property="og:title"[^>]*content="([^"]+)"/,c=/<meta[^>]*name="description"[^>]*content="([^"]+)"/,u=/<meta[^>]*property="og:description"[^>]*content="([^"]+)"/,a=/<meta[^>]*property="og:image"[^>]*content="([^"]+)"/;exports.glancify=function(){var t=n(e().m((function t(n){var r,f,l,p,s,v,y,h;return e().w((function(t){for(;;)switch(t.n){case 0:return t.n=1,fetch(n);case 1:if((p=t.v).ok){t.n=2;break}throw new Error("Failed to fetch URL: "+p.status+" "+p.statusText);case 2:return t.n=3,p.text();case 3:return v=(s=t.v).match(i)||s.match(o),y=s.match(u)||s.match(c),h=s.match(a),t.a(2,{title:null!=(r=null==v?void 0:v[1])?r:null,description:null!=(f=null==y?void 0:y[1])?f:null,image:null!=(l=null==h?void 0:h[1])?l:null})}}),t)})));return function(n){return t.apply(this,arguments)}}();
//# sourceMappingURL=glancify.cjs.production.min.js.map