hn-ts
Version:
TypeScript client for the Hacker News API
3 lines (2 loc) • 2.44 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var t=require("isomorphic-unfetch"),e=require("html-to-text");function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var s=n(t);const o="https://hacker-news.firebaseio.com/v0";async function a({id:t}){const e=`${o}/item/${t}.json`,n=await s.default(e),a=await n.json();return null!=a?a:void 0}function r({time:t}){return new Date(1e3*t).toISOString()}async function i({id:t}){const e=`${o}/user/${t}.json`,n=await s.default(e),a=await n.json();return null!=a?a:void 0}exports.getAskStoriesIds=async function(){const t=`${o}/askstories.json`,e=await s.default(t);return await e.json()},exports.getBestStoriesIds=async function(){const t=`${o}/beststories.json`,e=await s.default(t);return await e.json()},exports.getItemById=async function({id:t}){const n=await a({id:t});if(n)return function({rawItem:t}){var n,s,o;const a=null!=(n=t.type)?n:"unknown",i=t.time?r({time:t.time}):void 0,d=null!=(s=t.deleted)&&s,u=null!=(o=t.dead)&&o,c=t.title?e.htmlToText(t.title,{wordwrap:!1}):void 0,l=t.text?e.htmlToText(t.text,{wordwrap:!1}):void 0;return{id:t.id,type:a,author:t.by,title:c,url:t.url,text:l,timestamp:i,score:t.score,numChildren:t.descendants,deleted:d,dead:u,parentId:t.parent,childrenIds:t.kids,pollId:t.poll,pollOptionsIds:t.parts}}({rawItem:n})},exports.getJobStoriesIds=async function(){const t=`${o}/jobstories.json`,e=await s.default(t);return await e.json()},exports.getLatestItemAndUserUpdates=async function(){const t=`${o}/updates.json`,e=await s.default(t);return await e.json()},exports.getMaxItemId=async function(){const t=`${o}/maxitem.json`,e=await s.default(t);return await e.json()},exports.getNewStoriesIds=async function(){const t=`${o}/newstories.json`,e=await s.default(t);return await e.json()},exports.getRawItemById=a,exports.getRawUserById=i,exports.getShowStoriesIds=async function(){const t=`${o}/showstories.json`,e=await s.default(t);return await e.json()},exports.getTopStoriesIds=async function(){const t=`${o}/topstories.json`,e=await s.default(t);return await e.json()},exports.getUserById=async function({id:t}){const n=await i({id:t});if(n)return function({rawUser:t}){const n=r({time:t.created}),s=t.about?e.htmlToText(t.about,{wordwrap:!1}):void 0;return{id:t.id,createdAt:n,karma:t.karma,about:s,submittedIds:t.submitted}}({rawUser:n})},exports.hnApiBaseUrl=o;
//# sourceMappingURL=hn-ts.cjs.production.min.js.map
;