1 | # xkcdjs [![npm version](https://img.shields.io/npm/v/@ffflorian/xkcdjs.svg)](https://www.npmjs.com/package/@ffflorian/xkcdjs)
|
2 |
|
3 | An [xkcd](https://xkcd.com) API client with a CLI.
|
4 |
|
5 | ## Usage
|
6 |
|
7 | A complete documentation is available at https://ffflorian.github.io/api-clients/packages/xkcdjs/.
|
8 |
|
9 | ### CLI
|
10 |
|
11 | To use `xkcdjs` globally, run `yarn global add @ffflorian/xkcdjs` or `npm i -g @ffflorian/xkcdjs`.
|
12 |
|
13 | ```
|
14 | Usage: xkcdjs [options] [command]
|
15 |
|
16 | An xkcd API client with a CLI.
|
17 |
|
18 | Options:
|
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 |
|
23 | Commands:
|
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 |
|
31 | Run `yarn add @ffflorian/xkcdjs` or `npm install @ffflorian/xkcdjs`.
|
32 |
|
33 | #### Example
|
34 |
|
35 | ```ts
|
36 | import {XKCD} from '@ffflorian/xkcdjs';
|
37 |
|
38 | const xkcd = new XKCD();
|
39 |
|
40 | xkcd.api.getLatest().then(result => {
|
41 | // XKCDResult { ... }
|
42 | });
|
43 |
|
44 | xkcd.api.getRandom().then(result => {
|
45 | // XKCDResult
|
46 | });
|
47 |
|
48 | xkcd.api.getById(2036).then(result => {
|
49 | // XKCDResult
|
50 | });
|
51 |
|
52 | xkcd.api.getLatest({withData: true}).then(result => {
|
53 | // XKCDResultWithData
|
54 | });
|
55 |
|
56 | xkcd.api.getRandom({withData: true}).then(result => {
|
57 | // XKCDResultWithData
|
58 | });
|
59 |
|
60 | xkcd.api.getById(2036, {withData: true}).then(result => {
|
61 | // XKCDResultWithData
|
62 | });
|
63 | ```
|
64 |
|
65 | ## Build and test
|
66 |
|
67 | ```
|
68 | yarn
|
69 | yarn test
|
70 | ```
|