UNPKG

2.12 kBMarkdownView Raw
1# hn-ts
2
3[![Build status](https://img.shields.io/github/workflow/status/velut/hn-ts/CI)](https://github.com/velut/hn-ts/actions?query=workflow%3ACI)
4[![Coverage](https://img.shields.io/codecov/c/gh/velut/hn-ts)](https://codecov.io/gh/velut/hn-ts)
5[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/hn-ts)
6![Language](https://img.shields.io/github/languages/top/velut/hn-ts)
7[![npm bundle size](https://img.shields.io/bundlephobia/min/hn-ts)](https://bundlephobia.com/result?p=hn-ts)
8[![npm](https://img.shields.io/npm/v/hn-ts)](https://www.npmjs.com/package/hn-ts)
9[![License](https://img.shields.io/github/license/velut/hn-ts)](https://github.com/velut/hn-ts/blob/main/LICENSE)
10
11A TypeScript client for the [Hacker News API](https://github.com/HackerNews/API).
12
13## Features
14
15- Fully typed API and response data
16- Well documented and tested
17
18## API & Package Info
19
20- [Explore the package API on **jsDocs.io**](https://www.jsdocs.io/package/hn-ts)
21- [View package contents on **unpkg**](https://unpkg.com/hn-ts/)
22- [View repository on **GitHub**](https://github.com/velut/hn-ts)
23
24## Install
25
26Using `npm`:
27
28```
29npm i hn-ts
30```
31
32Using `yarn`:
33
34```
35yarn add hn-ts
36```
37
38## Usage Examples
39
40Get the ID of the latest item created on HN:
41
42```typescript
43import { getMaxItemId } from 'hn-ts';
44
45(async () => {
46 const id = await getMaxItemId();
47
48 // Output: a number like `27107832`
49 console.log(id);
50})();
51```
52
53Get the item (story, comment, job, poll or poll option) with the given ID:
54
55```typescript
56import { getItemById } from 'hn-ts';
57
58(async () => {
59 const item = await getItemById({
60 id: 27107832,
61 });
62
63 // Output: `27107832`
64 console.log(item.id);
65
66 // Output: `story`
67 console.log(item.type);
68
69 // Output: `velut`
70 console.log(item.author);
71})();
72```
73
74Get the user with the given name:
75
76```typescript
77import { getUserById } from 'hn-ts';
78
79(async () => {
80 const user = await getUserById({
81 id: "velut",
82 });
83
84 // Output: `velut`
85 console.log(user.id);
86})();
87```
88
89## License
90
91MIT License
92
93Copyright (c) 2021 Edoardo Scibona
94
95See LICENSE file.