-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
57 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function absoluteTimestamp(time?: number) { | ||
if (time === undefined) return; | ||
|
||
return new Intl.DateTimeFormat('en-GB', { | ||
year: 'numeric', | ||
month: 'long', | ||
day: 'numeric', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
}).format(time * 1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { HackerNewsCategory } from '@/types'; | ||
|
||
const apiBaseUrl = 'https://hacker-news.firebaseio.com/v0/'; | ||
|
||
export function apiCategoryUrl(category: HackerNewsCategory) { | ||
return apiBaseUrl + category + 'stories.json'; | ||
} | ||
|
||
export function apiItemUrl(id: number) { | ||
return apiBaseUrl + 'item/' + id + '.json'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function formatNumber(number?: number) { | ||
if (number === undefined) return; | ||
return new Intl.NumberFormat('gb-GB').format(number); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export function parseUrl(url: string) { | ||
const parsedUrl = new URL(url); | ||
|
||
const customUrl = { | ||
hostname: parsedUrl.hostname, | ||
pathname: parsedUrl.pathname, | ||
href: parsedUrl.href, | ||
search: parsedUrl.search, | ||
}; | ||
|
||
customUrl.hostname = customUrl.hostname.replace(/^www\./g, ''); | ||
|
||
if (customUrl.hostname === 'github.com') { | ||
customUrl.hostname = customUrl.hostname + '/' + customUrl.pathname.split('/')[1]; | ||
customUrl.pathname = '/' + customUrl.pathname.split('/').slice(2).join('/'); | ||
} | ||
|
||
if (customUrl.pathname.endsWith('/')) { | ||
customUrl.pathname = customUrl.pathname.substring(0, customUrl.pathname.length - 1); | ||
} | ||
|
||
return customUrl; | ||
} |