|
3 | 3 | [](https://badge.fury.io/js/%40xivapi%2Fjs) |
4 | 4 | [](LICENSE) |
5 | 5 |
|
6 | | -This is a pure JS wrapper for interacting with [XIVAPI](https://xivapi.com/) and handling all requests in a simple, promise-driven manner. |
| 6 | +A JavaScript library for working with [XIVAPI v2](https://v2.xivapi.com/), providing a source of Final Fantasy XIV game data. It lets you fetch, search, and use FFXIV data easily in a promise-based manner. |
| 7 | + |
| 8 | +> [!WARNING] |
| 9 | +> `@xivapi/js@0.4.5` (using XIVAPI v1) is now deprecated. Please use it at your own risk. We strongly recommend you update to the latest version. Migration guide and details: https://v2.xivapi.com/docs/migrate/. |
| 10 | +
|
| 11 | +If you need help or run into any issues, please [open an issue](https://github.com/xivapi/xivapi-js/issues) on GitHub or join the [XIVAPI Discord server](https://discord.gg/MFFVHWC) for support. |
7 | 12 |
|
8 | 13 | ## Installation |
9 | 14 |
|
10 | | -Simply add the module to your node project with `npm`: |
11 | | -``` |
12 | | -npm i @xivapi/js |
| 15 | +```bash |
| 16 | +npm install @xivapi/js@latest # or use yarn, pnpm, or bun |
13 | 17 | ``` |
14 | 18 |
|
15 | | -## Usage |
| 19 | +## Usage Examples |
| 20 | + |
| 21 | +#### 1. Importing and Initialization |
16 | 22 |
|
17 | | -Require and initialize the module in your code: |
18 | 23 | ```js |
19 | | -const XIVAPI = require('@xivapi/js') |
20 | | -const xiv = new XIVAPI() |
21 | | -``` |
| 24 | +import xivapi from '@xivapi/js'; |
22 | 25 |
|
23 | | -...and then check out the [wiki](https://github.com/xivapi/xivapi-js/wiki) for usage help! |
| 26 | +// Basic instance |
| 27 | +const xiv = new xivapi(); |
24 | 28 |
|
25 | | -If you get really stuck and need some help, or run into any problems/concerns, either open up an issue on github or join the [XIVAPI discord server](https://discord.gg/MFFVHWC) and ping/DM @kaimoe. |
| 29 | +// With options |
| 30 | +const xivCustom = new xivapi({ |
| 31 | + version: "7.0", // specify game version |
| 32 | + language: "jp", // specify language (jp, en, de, fr) |
| 33 | + verbose: true // output more logging |
| 34 | +}); |
| 35 | +``` |
26 | 36 |
|
27 | | -### Examples: |
| 37 | +#### 2. Get an Item |
28 | 38 |
|
29 | | -Find an item's ID: |
30 | 39 | ```js |
31 | | -const getID = async () => { |
32 | | - //find item |
33 | | - let res = await xiv.search('Stuffed Khloe') |
| 40 | +// Fetch the Gil item (item ID 1) |
| 41 | +const item = await xiv.items.get(1); |
34 | 42 |
|
35 | | - //return item ID |
36 | | - return res.Results[0].ID |
37 | | -} |
| 43 | +console.log(item.Name); // "Gil" (or equivalent in your language) |
38 | 44 | ``` |
39 | 45 |
|
40 | | -Search for an FC and get an list of members: |
41 | | -```javascript |
42 | | -const getMembers = async () => { |
43 | | - //find the FC with its name and server |
44 | | - let res = await xiv.freecompany.search('My Fun FC', {server: 'Excalibur'}) |
| 46 | +#### 3. Search Example |
45 | 47 |
|
46 | | - //get the FC ID |
47 | | - let id = res.Results[0].ID |
48 | | - |
49 | | - //get and return fc members |
50 | | - let fc = await xiv.freecompany.get('9231253336202687179', {data: FCM}) |
51 | | - return fc.FreeCompanyMembers |
| 48 | +```js |
| 49 | +// Find all items named "gil" |
| 50 | +const params = { |
| 51 | + query: 'Name~"gil"', |
| 52 | + sheets: "Item" |
| 53 | +}; |
| 54 | + |
| 55 | +const { results } = await xiv.search(params); |
| 56 | +console.log(results[0]); |
| 57 | + |
| 58 | +/* |
| 59 | +Output example: |
| 60 | +{ |
| 61 | + "score": 1, |
| 62 | + "sheet": "Item", |
| 63 | + "row_id": 1, |
| 64 | + "fields": { |
| 65 | + "Icon": { |
| 66 | + "id": 65002, |
| 67 | + "path": "ui/icon/065000/065002.tex", |
| 68 | + "path_hr1": "ui/icon/065000/065002_hr1.tex" |
| 69 | + }, |
| 70 | + "Name": "Gil", |
| 71 | + "Singular": "gil" |
| 72 | + } |
52 | 73 | } |
| 74 | +*/ |
53 | 75 | ``` |
54 | 76 |
|
55 | | -Check for character ownership using a token we generated and provided to the user: |
| 77 | +#### 4. Using Raw XIVAPI v2 Endpoints |
| 78 | + |
56 | 79 | ```js |
57 | | -const verifyCharacter = async () => { |
58 | | - //find the character with their name and server |
59 | | - let res = await xiv.character.search('Kai Megumi', {server: 'excalibur'}) //case insensitive server names, btw ;) |
| 80 | +// Fetch a raw asset file (e.g. icon image) |
| 81 | +const asset = await xiv.data.assets.get({ |
| 82 | + path: "ui/icon/051000/051474_hr1.tex", |
| 83 | + format: "png" // jpg or webp also supported |
| 84 | +}); |
| 85 | + |
| 86 | +// List all quests |
| 87 | +const quests = await xiv.data.sheets.list("Quest"); |
| 88 | +console.log(quests); |
| 89 | + |
| 90 | +// List available game versions |
| 91 | +const versions = await xiv.data.versions(); |
| 92 | +console.log(versions[0]); // e.g. "7.0" |
| 93 | +``` |
60 | 94 |
|
61 | | - //get the character |
62 | | - let char = res.Results[0] |
| 95 | +## Contributing |
63 | 96 |
|
64 | | - //return whether or not the character's lodestone bio matches our token |
65 | | - return char.Bio === 'example_token' |
66 | | -} |
67 | | -``` |
| 97 | +We welcome all contributions! Whether you'd like to report a bug, suggest a feature, improve the documentation, or submit a pull request, your help is appreciated. |
68 | 98 |
|
69 | | -## Contribute |
| 99 | +To get started, clone the repository with: `git clone https://github.com/xivapi/xivapi-js.git` |
70 | 100 |
|
71 | | -Feel free to open up issues/PRs or anything else. |
| 101 | +Before opening a pull request, please: |
| 102 | +- Make sure your code passes linting and all current tests (`npm run lint && npm test`). |
| 103 | +- Clearly explain your changes and reference any relevant issues in your PR description. |
72 | 104 |
|
73 | | -Just `git clone https://github.com/xivapi/xivapi-js.git`, run `npm i`, and go to town! |
| 105 | +If you have questions, suggestions, or want to discuss changes before contributing, feel free to open an issue! |
74 | 106 |
|
75 | 107 | ## License |
76 | 108 |
|
77 | | -This project is open source, under the terms described in the [MIT License](LICENSE). |
| 109 | +MIT License - see [LICENSE](LICENSE) file for details. |
0 commit comments