Skip to content

Commit 9fa586e

Browse files
committed
consistancy & guide
1 parent 41f9ee0 commit 9fa586e

38 files changed

+289
-258
lines changed

Guide.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Guide
2+
3+
Please read guide at [docs](https://azurapi.github.io/v2/).
4+
5+
This document is provided for convenience only, and may not be up to date.
6+
7+
> Latest: 1.1.0
8+
> Guide: 0.1.0
9+
10+
## General
11+
12+
### Create a new AzurAPI class
13+
```js
14+
const client = new AzurAPI(/* options [optional]: { source (data source) [default = "local"]: "uncached" | "local", autoupdate (fetch new data or not) [default = true]: boolean, rate (rate of fetching new data) [default = 3600000]: number } */);
15+
```
16+
17+
### Update the data
18+
```js
19+
<AzurAPI>.updater.update();
20+
```
21+
22+
## Data accessor classes
23+
```js
24+
<AzurAPI>.ships
25+
<AzurAPI>.equipments
26+
<AzurAPI>.chapters
27+
<AzurAPI>.voicelines
28+
<AzurAPI>.barrages
29+
```
30+
31+
> Note: All functions in accessor classes return arrays.
32+
33+
## Base API
34+
35+
### Search fuse
36+
```js
37+
<AzurAPI>.<accessor>.fuze(/* name: string */);
38+
```
39+
40+
### Get by id
41+
```js
42+
<AzurAPI>.<accessor>.id(/* id: string */);
43+
```
44+
45+
### Get by search query
46+
```js
47+
<AzurAPI>.<accessor>.get(/* query: string */);
48+
```
49+
50+
### Perform a filter operation
51+
```js
52+
<AzurAPI>.<accessor>.filter(/* predicate: function */);
53+
```
54+
55+
### Perform a map operation
56+
```js
57+
<AzurAPI>.<accessor>.map(/* callbackfn: function */);
58+
```
59+
60+
### Perform a forEach operation
61+
```js
62+
<AzurAPI>.<accessor>.forEach(/* callbackfn: function */);
63+
```
64+
65+
### Perform an every operation
66+
```js
67+
<AzurAPI>.<accessor>.every(/* predicate: function */);
68+
```
69+
70+
### Perform a some operation
71+
```js
72+
<AzurAPI>.<accessor>.some(/* predicate: function */);
73+
```
74+
75+
## Extentions - Ships
76+
77+
### Get ship by name/language
78+
<AzurApi>.ships.name(/* name: string, language: 'en' | 'cn' | 'jp' | 'kr' */);
79+
80+
<AzurApi>.ships.hull(/* name: string */);
81+
```
82+
83+
> TODO: Rattley will write the rest later

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ To use the Library, Please refer to the [Docs](https://azurapi.github.io/v2/).
4848

4949
For advanced users or package developers, please refer to [TSDoc](https://azurapi.github.io/azurapi-js/).
5050

51-
## Support Server
51+
## Breaking Changes
52+
53+
### 1.1.0
54+
- All functions from accessors after verion 1.1.0 return arrays.
55+
- Bundles are now built with typescript version 4.5.5
56+
57+
## Discord Support Server
5258

5359
[![](https://discordapp.com/api/guilds/648206344729526272/widget.png?style=banner2)](https://discord.gg/aAEdys8)
5460

bundles/azurapi.js

Lines changed: 27 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundles/azurapi.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundles/azurapi.umd.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/CNAME

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/assets/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/classes/core_CacheUpdater.default.html

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

docs/classes/core_Client.AzurAPI.html

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/classes/core_api_api.default.html

Lines changed: 11 additions & 10 deletions
Large diffs are not rendered by default.

docs/classes/core_api_api_barrage.Barrages.html

Lines changed: 16 additions & 15 deletions
Large diffs are not rendered by default.

docs/classes/core_api_api_chapter.Chapters.html

Lines changed: 12 additions & 11 deletions
Large diffs are not rendered by default.

docs/classes/core_api_api_equipment.Equipments.html

Lines changed: 15 additions & 15 deletions
Large diffs are not rendered by default.

docs/classes/core_api_api_ship.Ships.html

Lines changed: 15 additions & 15 deletions
Large diffs are not rendered by default.

docs/classes/core_api_api_voiceline.Voicelines.html

Lines changed: 11 additions & 10 deletions
Large diffs are not rendered by default.

docs/index.html

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
</p>
1717
<p>
1818
<a href="https://github.com/AzurAPI/azurapi-js/actions">
19-
<img src="https://github.com/AzurAPI/azurapi-js/workflows/Github%20Actions/badge.svg?branch=v2-array-cache" alt="Github Actions" />
19+
<img src="https://github.com/AzurAPI/azurapi-js/workflows/Github%20Actions/badge.svg?branch=master" alt="Github Actions" />
2020
</a>
2121
<a href="https://ci.nekos.cloud/buildConfiguration/AzurapiJs_Build?guest=1"><img src="https://ci.nekos.cloud/app/rest/builds/buildType:id:AzurapiJs_Build/statusIcon.svg"></a>
2222
</p>
23-
<p><a href="https://npmjs.com/package/@azurapi/azurapi"><img src="https://nodeico.herokuapp.com/@azurapi/azurapi.svg"></a>
23+
<p><a href="https://npmjs.com/package/@azurapi/azurapi"><img src="https://nodei.co/npm/@azurapi/azurapi.png?downloads=true&downloadRank=true&stars=true"></a>
2424
</p>
2525
</div>
2626

@@ -58,8 +58,19 @@ <h2>Usage / Documentation</h2>
5858
<p>To use the Library, Please refer to the <a href="https://azurapi.github.io/v2/">Docs</a>.</p>
5959
<p>For advanced users or package developers, please refer to <a href="https://azurapi.github.io/azurapi-js/">TSDoc</a>.</p>
6060

61-
<a href="#support-server" id="support-server" style="color: inherit; text-decoration: none;">
62-
<h2>Support Server</h2>
61+
<a href="#breaking-changes" id="breaking-changes" style="color: inherit; text-decoration: none;">
62+
<h2>Breaking Changes</h2>
63+
</a>
64+
65+
<a href="#110" id="110" style="color: inherit; text-decoration: none;">
66+
<h3>1.1.0</h3>
67+
</a>
68+
<ul>
69+
<li>All functions from accessors after verion 1.1.0 return arrays.</li>
70+
</ul>
71+
72+
<a href="#discord-support-server" id="discord-support-server" style="color: inherit; text-decoration: none;">
73+
<h2>Discord Support Server</h2>
6374
</a>
6475
<p><a href="https://discord.gg/aAEdys8"><img src="https://discordapp.com/api/guilds/648206344729526272/widget.png?style=banner2" alt=""></a></p>
6576
<p>Discord Link: <a href="https://discord.gg/aAEdys8">https://discord.gg/aAEdys8</a></p>

docs/interfaces/core_Client.CacheOptions.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/core_api_api.advancedOptions.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_barrage.Barrage.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_barrage.Rounds.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_chapter.Chapter.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_chapter.SubChapter.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_equipment.Equipment.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_identifiable.Identifiable.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_ship.Ship.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_ship.shipAdvancedOptions.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/interfaces/types_voiceline.Voiceline.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/modules/core_Client.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/modules/core_Data.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/modules/core_UpdateChecker.html

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

docs/modules/core_api_api.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

docs/modules/types_barrage.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azurapi/azurapi",
3-
"version": "1.0.6",
3+
"version": "1.1.0",
44
"description": "Open Source Azur Lane Local Database",
55
"main": "./build/index.js",
66
"types": "./build/index.d.ts",

src/core/api/api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ export default class API<T extends Identifiable> {
8787
/**
8888
* Get by any
8989
* @param query Any
90+
* @returns Array
9091
*/
91-
get(query: string): T | undefined {
92-
return this.id(query) || this.fuze(query)?.map(s => s.item)[0];
92+
get(query: string): T | T[] {
93+
return this.id(query) || this.fuze(query)?.map(s => s.item);
9394
}
9495

9596
/**

src/core/api/api_barrage.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,31 @@ export class Barrages extends API<Barrage> {
2222
* Get barrage by name
2323
* @param name Barrage name
2424
*/
25-
name(name: string): Barrage | undefined {
26-
for (let barrage of this.raw) if (normalize(barrage.name.toUpperCase()) === normalize(name.toUpperCase())) return barrage;
27-
return undefined;
25+
name(name: string): Barrage[] | [] {
26+
return this.raw.filter(barrage => normalize(barrage.name.toUpperCase()) === normalize(name.toUpperCase()));
2827
}
2928

3029
/**
3130
* Get barrage by type
3231
* @param type Barrage type
3332
*/
34-
type(type: 'ship' | 'class' | 'skill'): Barrage[] | void[] {
33+
type(type: 'ship' | 'class' | 'skill'): Barrage[] | [] {
3534
return this.raw.filter(barrage => normalize(barrage.type.toUpperCase()) === normalize(type.toUpperCase()));
3635
}
3736

3837
/**
3938
* Get barrage by hull type
4039
* @param hull Hull type
4140
*/
42-
hull(hull: Hull): Barrage[] | void[] {
41+
hull(hull: Hull): Barrage[] | [] {
4342
return this.raw.filter(barrage => normalize(barrage.hull.toUpperCase()) === normalize(hull.toUpperCase()));
4443
}
4544

4645
/**
4746
* Sort barrages by compatable ship
4847
* @param ship A ship name
4948
*/
50-
ships(ship: Ships): Barrage[] | void[] {
49+
ships(ship: Ships): Barrage[] | [] {
5150
return this.raw.filter(barrage => barrage.ships.map(ship => normalize(ship.toUpperCase())).includes(normalize(ship.toUpperCase())));
5251
}
5352
}

src/core/api/api_chapter.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ export class Chapters extends API<Chapter> {
2424
* @param name Chapter name
2525
* @param languages Language to search
2626
*/
27-
name(name: string, languages: Language[] = ['en', 'cn', 'jp']): Chapter | SubChapter | undefined {
28-
for (let chapter of this.raw) if (languages.some(lang => chapter.names[lang] && normalize(chapter.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) return chapter;
29-
/*for (let chapter of this.raw) {
30-
for (let sub of chapter) if (languages.some(lang => sub.names[lang] && normalize(sub.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) return sub;
31-
}*/
32-
return undefined;
27+
name(name: string, languages: Language[] = ['en', 'cn', 'jp']): (Chapter | SubChapter)[] | [] {
28+
let result: (Chapter | SubChapter)[] = [];
29+
for (let chapter of this.raw) {
30+
if (languages.some(lang => chapter.names[lang] && normalize(chapter.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) result.push(chapter);
31+
for (let sub of Object.values(chapter)) {
32+
if (sub.names !== undefined) {
33+
if (languages.some(lang => sub.names[lang] && normalize(sub.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) result.push(sub);
34+
}
35+
}
36+
}
37+
return result;
3338
}
3439
}

src/core/api/api_equipment.ts

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,63 +24,44 @@ export class Equipments extends API<Equipment> {
2424
* @param name Equipment name
2525
* @param languages Language to search
2626
*/
27-
name(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Equipment | undefined {
28-
for (let equipment of this.raw) if (languages.some(lang => equipment.names[lang] && normalize(equipment.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) return equipment;
29-
return undefined;
27+
name(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Equipment[] | [] {
28+
return this.raw.filter(equipment => languages.some(lang => equipment.names[lang] && normalize(equipment.names[lang].toUpperCase()) === normalize(name.toUpperCase())));
3029
}
3130

3231
/**
3332
* Lists the equipments by category
3433
* @param category name of the category you want to search for
3534
*/
36-
category(category: string): Equipment[] {
37-
let results: Equipment[] = [];
38-
for (let equipment of this.raw) if (normalize(equipment.category.toUpperCase() === normalize(category.toUpperCase()))) results.push(equipment);
39-
return results;
35+
category(category: string): Equipment[] | [] {
36+
return this.raw.filter(equipment => normalize(equipment.category.toUpperCase() === normalize(category.toUpperCase())));
4037
}
4138

4239
/**
4340
* Lists the equipments by nationality
4441
* @param nationality naitionality name of the equipments you want to search for
4542
*/
46-
nationality(nationality: string): Equipment[] {
47-
let results: Equipment[] = [];
43+
nationality(nationality: string): Equipment[] | [] {
4844
nationality = Object.keys(NATIONS).find(key => NATIONS[key].includes(nationality.toLowerCase())) || nationality;
49-
for (let equipment of this.raw) if (normalize(equipment.nationality.toUpperCase()) === normalize(nationality.toUpperCase())) results.push(equipment);
50-
return results;
51-
}
52-
53-
private _nameAll(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Equipment[] {
54-
return this.raw.filter(equipment => languages.some(lang => equipment.names[lang] && normalize(equipment.names[lang].toUpperCase()) === normalize(name.toUpperCase())));
45+
return this.raw.filter(equipment => normalize(equipment.nationality.toUpperCase()) === normalize(nationality.toUpperCase()));
5546
}
5647

5748
/**
5849
* Get equipment using name in any language or id
5950
* @param query Equipment name in any language or equipment id
6051
*/
61-
get(query: string, adv?: advancedOptions): Equipment | undefined {
62-
if (adv) {
63-
if (adv.idOnly) {
64-
return this.id(query);
65-
} else if (adv.nameOnly || adv.nameOnly && !adv.language) {
66-
return this.name(query);
67-
} else if (adv.nameOnly && adv.language) {
68-
return this.name(query, [adv.language]);
69-
}
70-
} else {
71-
let fuzeResult = this.fuze(query).sort((a, b) => (b.score || 0) - (a.score || 0))[0];
72-
return this.id(query) || this.name(query) || (fuzeResult ? fuzeResult.item : undefined);
73-
}
52+
get(query: string): Equipment | Equipment[] {
53+
let fuzeResult = this.fuze(query).sort((a, b) => (b.score || 0) - (a.score || 0))[0];
54+
return this.id(query) || this.name(query) || (fuzeResult ? fuzeResult.item : undefined);
7455
}
7556

7657
/**
7758
* Get equipment using everything
7859
* @param query basically anyting i guess
7960
*/
80-
all(query: string): Equipment[] {
61+
all(query: string): Equipment[] | [] {
8162
let results: (Equipment | undefined)[] = [];
8263
results.push(this.id(query));
83-
results.push(...this._nameAll(query).filter(i => i));
64+
results.push(...this.name(query).filter(i => i));
8465
results.push(...this.fuze(query).map(i => i.item));
8566
return results
8667
.filter((value: Equipment | undefined): value is Equipment => value !== null && value !== undefined)

src/core/api/api_ship.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,64 +24,49 @@ export class Ships extends API<Ship> {
2424
* @param name Ship name
2525
* @param languages Language to search
2626
*/
27-
name(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Ship | undefined {
28-
for (let ship of this.raw) if (languages.some(lang => ship.names[lang] && normalize(ship.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) return ship;
29-
return undefined;
27+
name(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Ship[] | [] {
28+
return this.raw.filter(ship => languages.some(lang => ship.names[lang] && normalize(ship.names[lang].toUpperCase()) === normalize(name.toUpperCase())));
3029
}
3130

3231
/**
3332
* Get ship by hull
3433
* @param hull Hull name
3534
*/
36-
hull(hull: string): Ship[] {
35+
hull(hull: string): Ship[] | [] {
3736
return this.raw.filter(ship =>
3837
(ship.hullType && normalize(ship.hullType.toUpperCase()) === normalize(hull.toUpperCase())) ||
39-
(ship.retrofitHullType && normalize(ship.retrofitHullType.toUpperCase()) === normalize(hull.toUpperCase()))
38+
(ship.retrofitHullType && normalize(ship.retrofitHullType.toUpperCase()) === normalize(hull.toUpperCase()))
4039
);
4140
}
4241

4342
/**
4443
* Get ship by nationality
4544
* @param nationality Nationality name
4645
*/
47-
nationality(nationality: string): Ship[] {
46+
nationality(nationality: string): Ship[] | [] {
4847
let results: Ship[] = [];
4948
nationality = Object.keys(NATIONS).find(key => NATIONS[key].includes(nationality.toLowerCase())) || nationality;
5049
for (let ship of this.raw) if (normalize(ship.nationality.toUpperCase()) === normalize(nationality.toUpperCase())) results.push(ship);
5150
return results;
5251
}
5352

54-
private _nameAll(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Ship[] {
55-
return this.raw.filter(ship => languages.some(lang => ship.names[lang] && normalize(ship.names[lang].toUpperCase()) === normalize(name.toUpperCase())));
56-
}
57-
5853
/**
5954
* Get ship using name in any language or id
6055
* @param query Ship name in any language or ship id
6156
*/
62-
get(query: string, adv?: advancedOptions): Ship | undefined {
63-
if (adv) {
64-
if (adv.idOnly) {
65-
return this.id(query);
66-
} else if (adv.nameOnly || adv.nameOnly && !adv.language) {
67-
return this.name(query);
68-
} else if (adv.nameOnly && adv.language) {
69-
return this.name(query, [adv.language]);
70-
}
71-
} else {
72-
let fuzeResult = this.fuze(query).sort((a, b) => (b.score || 0) - (a.score || 0))[0];
73-
return this.id(query) || this.name(query) || (fuzeResult ? fuzeResult.item : undefined);
74-
}
57+
get(query: string): Ship | Ship[] {
58+
let fuzeResult = this.fuze(query).sort((a, b) => (b.score || 0) - (a.score || 0))[0];
59+
return this.id(query) || this.name(query)[0] || (fuzeResult ? fuzeResult.item : undefined);
7560
}
7661

7762
/**
7863
* Get ship using everything
7964
* @param query basically anyting i guess
8065
*/
81-
all(query: string): Ship[] {
66+
all(query: string): Ship[] | [] {
8267
let results: (Ship | undefined)[] = [];
8368
results.push(this.id(query));
84-
results.push(...this._nameAll(query).filter(i => i));
69+
results.push(...this.name(query).filter(i => i));
8570
results.push(...this.fuze(query).map(i => i.item));
8671
return results
8772
.filter((value: Ship | undefined): value is Ship => value !== null && value !== undefined)

0 commit comments

Comments
 (0)