cloudflare/vinext

Public

mirrored from https://github.com/cloudflare/vinextAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.0.9

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/hackernews/lib/get-item.js

29lines · modecode

1import fetchData from './fetch-data'
2
3export default async function getItem(id) {
4 const val = await fetchData(`item/${id}`)
5 if (val) {
6 return transform(val)
7 } else {
8 return null
9 }
10}
11
12export function transform(val) {
13 if (val) {
14 return {
15 id: val.id,
16 url: val.url || '',
17 user: val.by,
18 // time is seconds since epoch, not ms
19 date: new Date(val.time * 1000).getTime() || 0,
20 // sometimes `kids` is `undefined`
21 comments: val.kids || [],
22 commentsCount: val.descendants || 0,
23 score: val.score,
24 title: val.title
25 }
26 } else {
27 return null
28 }
29}
30