Skip to content

Commit 2ad79da

Browse files
committed
refactor: add cjs support & fix docs
1 parent 8f05fd9 commit 2ad79da

File tree

5 files changed

+58
-63
lines changed

5 files changed

+58
-63
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const xiv = new xivapi();
2929
// With options
3030
const xivCustom = new xivapi({
3131
version: "7.0", // specify game version
32-
language: "jp", // specify language (jp, en, de, fr)
32+
language: "ja", // specify language (ja, en, de, fr)
3333
verbose: true // output more logging
3434
});
3535
```
@@ -40,7 +40,7 @@ const xivCustom = new xivapi({
4040
// Fetch the Gil item (item ID 1)
4141
const item = await xiv.items.get(1);
4242

43-
console.log(item.Name); // "Gil" (or equivalent in your language)
43+
console.log(item.fields.Name); // "Gil" (or equivalent in your language)
4444
```
4545

4646
#### 3. Search Example
@@ -78,13 +78,15 @@ Output example:
7878

7979
```js
8080
// Fetch a raw asset file (e.g. icon image)
81-
const asset = await xiv.data.assets.get({
81+
const assets = await xiv.data.assets();
82+
const asset = await assets.get({
8283
path: "ui/icon/051000/051474_hr1.tex",
8384
format: "png" // jpg or webp also supported
8485
});
8586

8687
// List all quests
87-
const quests = await xiv.data.sheets.list("Quest");
88+
const sheets = await xiv.data.sheets();
89+
const quests = await sheets.list("Quest");
8890
console.log(quests);
8991

9092
// List available game versions

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineConfig([
1111
languageOptions: { globals: globals.node },
1212
},
1313
{ files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
14-
globalIgnores(["tests/**/*.test.ts", "dist/**/*.js"]),
14+
globalIgnores(["tests/**/*.test.ts", "dist/**/*.{js,cjs,mjs}"]),
1515
tseslint.configs.recommended,
1616
{
1717
rules: {

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
"name": "@xivapi/js",
44
"version": "1.0.1",
55
"description": "A Node.JS wrapper for xivapi.com",
6-
"main": "dist/index.js",
6+
"main": "dist/index.cjs",
7+
"module": "dist/index.js",
8+
"types": "dist/index.d.ts",
79
"devDependencies": {
810
"@eslint/js": "^9.38.0",
911
"@types/node": "^24.7.2",
1012
"eslint": "^9.37.0",
1113
"globals": "^16.4.0",
1214
"ts-node": "^10.9.2",
15+
"tsup": "^8.5.0",
1316
"typescript": "^5.9.3",
1417
"typescript-eslint": "^8.46.1",
1518
"vitest": "^3.2.4"
1619
},
1720
"scripts": {
18-
"build": "tsc",
21+
"build": "tsup",
1922
"test": "vitest",
2023
"lint": "eslint --fix"
2124
},
@@ -33,7 +36,6 @@
3336
"url": "https://github.com/xivapi/xivapi-js/issues"
3437
},
3538
"homepage": "https://github.com/xivapi/xivapi-js#readme",
36-
"types": "dist/index.d.ts",
3739
"files": [
3840
"dist"
3941
]

src/index.ts

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,35 @@ import { Assets, Sheet, Sheets, Versions } from "./lib"
22
import { CustomError, request } from "./utils"
33

44
export default class XIVAPI {
5-
private readonly options: XIVAPI.Options
5+
public readonly options: XIVAPI.Options
6+
7+
public readonly achievements: Sheet<"Achievement">
8+
public readonly minions: Sheet<"Companion">
9+
public readonly mounts: Sheet<"Mount">
10+
public readonly items: Sheet<"Item">
11+
12+
/**
13+
* Raw endpoints for the API. Please consider using the typed endpoints instead.
14+
* @see https://v2.xivapi.com/api/docs
15+
* @since 0.5.0
16+
*/
17+
public readonly data = {
18+
/**
19+
* @see https://v2.xivapi.com/api/docs#tag/sheets
20+
* @since 0.5.0
21+
*/
22+
sheets: () => new Sheets(this.options),
23+
/**
24+
* @see https://v2.xivapi.com/api/docs#tag/versions
25+
* @since 0.5.0
26+
*/
27+
versions: () => new Versions().all().then((versions) => versions.versions.map((version) => version.names[0])),
28+
/**
29+
* @see https://v2.xivapi.com/api/docs#tag/assets
30+
* @since 0.5.0
31+
*/
32+
assets: () => new Assets(),
33+
}
634

735
/**
836
* A wrapper for the XIVAPI v2 API.
@@ -17,35 +45,12 @@ export default class XIVAPI {
1745
verbose: false,
1846
}
1947
) {
20-
this.options = options
21-
}
22-
23-
/**
24-
* @since 0.5.0
25-
*/
26-
public get achievements() {
27-
return new Sheet("Achievement")
28-
}
29-
30-
/**
31-
* @since 0.5.0
32-
*/
33-
public get minions() {
34-
return new Sheet("Companion")
35-
}
48+
this.achievements = new Sheet("Achievement")
49+
this.minions = new Sheet("Companion")
50+
this.mounts = new Sheet("Mount")
51+
this.items = new Sheet("Item")
3652

37-
/**
38-
* @since 0.5.0
39-
*/
40-
public get mounts() {
41-
return new Sheet("Mount")
42-
}
43-
44-
/**
45-
* @since 0.5.0
46-
*/
47-
public get items() {
48-
return new Sheet("Item")
53+
this.options = options
4954
}
5055

5156
/**
@@ -63,32 +68,6 @@ export default class XIVAPI {
6368
if (errors) throw new CustomError(errors[0].message)
6469
return data as Models.SearchResponse
6570
}
66-
67-
/**
68-
* Raw endpoints for the API. Please consider using the typed endpoints instead.
69-
* @see https://v2.xivapi.com/api/docs
70-
* @since 0.5.0
71-
*/
72-
public data = {
73-
/**
74-
* @see https://v2.xivapi.com/api/docs#tag/assets
75-
* @since 0.5.0
76-
*/
77-
assets: () => new Assets(),
78-
79-
/**
80-
* @see https://v2.xivapi.com/api/docs#tag/sheets
81-
* @since 0.5.0
82-
*/
83-
sheets: () => new Sheets(this.options),
84-
85-
/**
86-
* @see https://v2.xivapi.com/api/docs#tag/versions
87-
* @since 0.5.0
88-
*/
89-
versions: () =>
90-
new Versions().all().then((versions) => versions.versions.map((version) => version.names[0])),
91-
}
9271
}
9372

9473
export namespace XIVAPI {

tsup.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from "tsup"
2+
3+
export default defineConfig({
4+
entry: ["src/index.ts"],
5+
format: ["cjs", "esm"],
6+
dts: true,
7+
outDir: "dist",
8+
splitting: true,
9+
sourcemap: true,
10+
minify: false,
11+
clean: true
12+
})

0 commit comments

Comments
 (0)