UNPKG

1.47 kBMarkdownView Raw
1# xkcdjs [![npm version](https://img.shields.io/npm/v/@ffflorian/xkcdjs.svg)](https://www.npmjs.com/package/@ffflorian/xkcdjs)
2
3An [xkcd](https://xkcd.com) API client with a CLI.
4
5## Usage
6
7A complete documentation is available at https://ffflorian.github.io/api-clients/packages/xkcdjs/.
8
9### CLI
10
11To use `xkcdjs` globally, run `yarn global add @ffflorian/xkcdjs` or `npm i -g @ffflorian/xkcdjs`.
12
13```
14Usage: xkcdjs [options] [command]
15
16An xkcd API client with a CLI.
17
18Options:
19 -v, --version output the version number
20 -o, --output <dir> Specify the output directory (default: current directory)
21 -h, --help output usage information
22
23Commands:
24 latest Save the latest comic
25 random Save a random comic
26 number <index> Save comic by index number
27```
28
29#### Installation
30
31Run `yarn add @ffflorian/xkcdjs` or `npm install @ffflorian/xkcdjs`.
32
33#### Example
34
35```ts
36import {XKCD} from '@ffflorian/xkcdjs';
37
38const xkcd = new XKCD();
39
40xkcd.api.getLatest().then(result => {
41 // XKCDResult { ... }
42});
43
44xkcd.api.getRandom().then(result => {
45 // XKCDResult
46});
47
48xkcd.api.getById(2036).then(result => {
49 // XKCDResult
50});
51
52xkcd.api.getLatest({withData: true}).then(result => {
53 // XKCDResultWithData
54});
55
56xkcd.api.getRandom({withData: true}).then(result => {
57 // XKCDResultWithData
58});
59
60xkcd.api.getById(2036, {withData: true}).then(result => {
61 // XKCDResultWithData
62});
63```
64
65## Build and test
66
67```
68yarn
69yarn test
70```