UNPKG

7.18 kBJavaScriptView Raw
1"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("dompurify"),r=(t=require("swr"))&&"object"==typeof t&&"default"in t?t.default:t,n=require("htmlparser2"),o=function(t,e){return function(t,e){return Array.from(t).find((function(t){return t.nodeName===e}))}(t.children,e)},i=function(t,e){return function(t,e){return Array.from(t).filter((function(t){return t.nodeName===e}))}(t.children,e)};function u(t){var e,r,n,u,l;return{id:null!=(e=a(o(t,"id")))?e:"",title:c(o(t,"title")),updated:new Date(null!=(r=null==(n=o(t,"updated"))?void 0:n.textContent)?r:0),author:i(t,"author").map((function(t){return y(t)})),content:s(o(t,"content")),link:i(t,"link").map((function(t){return d(t)})),summary:c(o(t,"summary")),category:i(t,"category").map((function(t){return p(t)})),contributor:i(t,"contributor").map((function(t){return y(t)})),published:o(t,"published")?new Date(null!=(u=null==(l=o(t,"published"))?void 0:l.textContent)?u:0):void 0,rights:c(o(t,"rights")),source:v(o(t,"source"))}}function l(t,r){if(void 0!==r){var n;if("xhtml"===t)return e.sanitize(r.innerHTML);if("html"===t)return e.sanitize(null!=(n=r.textContent)?n:"");if("text"===t)return e.sanitize(r.innerHTML)}return""}function a(t){var r;return void 0!==t?e.sanitize(null!=(r=null==t?void 0:t.textContent)?r:""):void 0}function f(t,r){return void 0!==t&&null!==t.getAttribute(r)?e.sanitize(t.getAttribute(r)):void 0}function s(t){var e,r=null!=(e=f(t,"type"))?e:void 0;return{type:r,src:f(t,"src"),value:l(r,t)}}function c(t){var e,r=null!=(e=f(t,"type"))?e:void 0;return{type:r,value:l(r,t)}}function y(t){var r,n;return{name:e.sanitize(null!=(r=null==(n=o(t,"name"))?void 0:n.textContent)?r:""),uri:a(o(t,"uri")),email:a(o(t,"email"))}}function d(t){var e;return{href:null!=(e=f(t,"href"))?e:"",rel:f(t,"ref"),type:f(t,"type"),hreflang:f(t,"hreflang"),title:f(t,"title"),length:f(t,"length")}}function p(t){var e,r,n;return{term:null!=(e=f(t,"term"))?e:"",scheme:null!=(r=f(t,"scheme"))?r:void 0,label:null!=(n=f(t,"label"))?n:void 0}}function v(t){var e,r,n,i;if(void 0!==t)return{id:null!=(e=a(o(t,"id")))?e:"",title:null!=(r=a(o(t,"title")))?r:"",updated:new Date(null!=(n=null==(i=o(t,"title"))?void 0:i.textContent)?n:0)}}var m={__proto__:null,parseAtomFeed:function(t){var e,r,n,l,s=(new DOMParser).parseFromString(t,"text/xml"),v=o(s,"feed");if(v)return{id:null!=(e=a(o(v,"id")))?e:"",title:c(o(v,"title")),updated:new Date(null!=(r=null==(n=o(v,"updated"))?void 0:n.textContent)?r:0),entries:i(v,"entry").map((function(t){return u(t)})),author:i(v,"author").map((function(t){return y(t)})),link:i(v,"link").map((function(t){return d(t)})),category:i(v,"category").map((function(t){return p(t)})),contributor:i(v,"contributor").map((function(t){return y(t)})),generator:{value:null!=(l=a(o(v,"generator")))?l:"",uri:f(o(v,"generator"),"uri"),version:f(o(v,"generator"),"version")},icon:a(o(v,"icon")),logo:a(o(v,"logo")),rights:c(o(v,"rights")),subtitle:a(o(v,"subtitle"))};throw Error("No <feed> tag found.")},parseAtomEntry:u,safelyDecodeAtomText:l,sanitizeTextContent:a,sanitizeTextAttribute:f,parseAtomContent:s,parseAtomText:c,parseAtomPerson:y,parseAtomLink:d,parseAtomCategory:p,parseAtomSource:v};function g(t,e){return!((null===t||"object"!=typeof t)&&"function"!=typeof t||"string"!=typeof t.value||void 0!==t.uri&&"string"!=typeof t.uri||void 0!==t.version&&"string"!=typeof t.version)}function h(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"string"==typeof t.id&&_(t.title)&&t.updated instanceof Date&&(void 0===t.author||Array.isArray(t.author)&&t.author.every((function(t){return j(t)})))&&(void 0===t.content||x(t.content))&&(void 0===t.link||Array.isArray(t.link)&&t.link.every((function(t){return k(t)})))&&(void 0===t.summary||z(t.summary))&&(void 0===t.category||Array.isArray(t.category)&&t.category.every((function(t){return b(t)})))&&(void 0===t.contributor||Array.isArray(t.contributor)&&t.contributor.every((function(t){return T(t)})))&&(void 0===t.published||t.published instanceof Date)&&(void 0===t.rights||w(t.rights))&&(void 0===t.source||A(t.source))}function A(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"string"==typeof t.id&&"string"==typeof t.title&&t.updated instanceof Date}function b(t,e){return!((null===t||"object"!=typeof t)&&"function"!=typeof t||"string"!=typeof t.term||void 0!==t.scheme&&"string"!=typeof t.scheme||void 0!==t.label&&"string"!=typeof t.label)}function x(t,e){return!((null===t||"object"!=typeof t)&&"function"!=typeof t||void 0!==t.type&&"text"!==t.type&&"html"!==t.type&&"xhtml"!==t.type||void 0!==t.src&&"string"!=typeof t.src||"string"!=typeof t.value)}function k(t,e){return!((null===t||"object"!=typeof t)&&"function"!=typeof t||"string"!=typeof t.href||void 0!==t.rel&&"alternate"!==t.rel&&"enclosure"!==t.rel&&"related"!==t.rel&&"self"!==t.rel&&"via"!==t.rel||void 0!==t.type&&"string"!=typeof t.type||void 0!==t.hreflang&&"string"!=typeof t.hreflang||void 0!==t.title&&"string"!=typeof t.title||void 0!==t.length&&"string"!=typeof t.length)}function C(t,e){return!((null===t||"object"!=typeof t)&&"function"!=typeof t||"string"!=typeof t.name||void 0!==t.uri&&"string"!=typeof t.uri||void 0!==t.email&&"string"!=typeof t.email)}function j(t,e){return C(t)}function T(t,e){return C(t)}function D(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&(void 0===t.type||"text"===t.type||"html"===t.type||"xhtml"===t.type)&&"string"==typeof t.value}function _(t,e){return D(t)}function z(t,e){return D(t)}function w(t,e){return D(t)}exports.Guards={__proto__:null,isAtomFeed:function(t,e){return(null!==t&&"object"==typeof t||"function"==typeof t)&&"string"==typeof t.id&&_(t.title)&&t.updated instanceof Date&&Array.isArray(t.entries)&&t.entries.every((function(t){return h(t)}))&&(void 0===t.author||Array.isArray(t.author)&&t.author.every((function(t){return j(t)})))&&(void 0===t.link||Array.isArray(t.link)&&t.link.every((function(t){return k(t)})))&&(void 0===t.category||Array.isArray(t.category)&&t.category.every((function(t){return b(t)})))&&(void 0===t.contributor||Array.isArray(t.contributor)&&t.contributor.every((function(t){return T(t)})))&&(void 0===t.generator||g(t.generator))&&(void 0===t.icon||"string"==typeof t.icon)&&(void 0===t.logo||"string"==typeof t.logo)&&(void 0===t.rights||w(t.rights))&&(void 0===t.subtitle||"string"==typeof t.subtitle)},isAtomGenerator:g,isAtomEntry:h,isAtomSource:A,isAtomCategory:b,isAtomContent:x,isAtomLink:k,isAtomPerson:C,isAtomLinkRelType:function(t,e){return"alternate"===t||"enclosure"===t||"related"===t||"self"===t||"via"===t},isAtomAuthor:j,isAtomContributor:T,isAtomText:D,isAtomTextType:function(t,e){return"text"===t||"html"===t||"xhtml"===t},isAtomTitle:_,isAtomSummary:z,isAtomRights:w},exports.Parser=m,exports.useAtomFeed=function(t,e){var o=r(t,(function(t){return fetch(t).then((function(t){return t.text()}))}),e),i=o.data,u=o.error,l=o.isValidating;if(!i)return{data:void 0,error:u,isValidating:l};try{return{data:n.parseFeed(i,{xmlMode:!0}),error:u,isValidating:l}}catch(t){return{data:void 0,error:t,isValidating:l}}};
2//# sourceMappingURL=use-atom-feed.cjs.production.min.js.map