Skip to content

Commit

Permalink
consistancy & guide
Browse files Browse the repository at this point in the history
  • Loading branch information
0t4u committed Apr 15, 2022
1 parent 41f9ee0 commit 9fa586e
Show file tree
Hide file tree
Showing 38 changed files with 289 additions and 258 deletions.
83 changes: 83 additions & 0 deletions Guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Guide

Please read guide at [docs](https://azurapi.github.io/v2/).

This document is provided for convenience only, and may not be up to date.

> Latest: 1.1.0
> Guide: 0.1.0
## General

### Create a new AzurAPI class
```js
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 } */);
```

### Update the data
```js
<AzurAPI>.updater.update();
```

## Data accessor classes
```js
<AzurAPI>.ships
<AzurAPI>.equipments
<AzurAPI>.chapters
<AzurAPI>.voicelines
<AzurAPI>.barrages
```

> Note: All functions in accessor classes return arrays.
## Base API

### Search fuse
```js
<AzurAPI>.<accessor>.fuze(/* name: string */);
```

### Get by id
```js
<AzurAPI>.<accessor>.id(/* id: string */);
```

### Get by search query
```js
<AzurAPI>.<accessor>.get(/* query: string */);
```

### Perform a filter operation
```js
<AzurAPI>.<accessor>.filter(/* predicate: function */);
```

### Perform a map operation
```js
<AzurAPI>.<accessor>.map(/* callbackfn: function */);
```

### Perform a forEach operation
```js
<AzurAPI>.<accessor>.forEach(/* callbackfn: function */);
```

### Perform an every operation
```js
<AzurAPI>.<accessor>.every(/* predicate: function */);
```

### Perform a some operation
```js
<AzurAPI>.<accessor>.some(/* predicate: function */);
```

## Extentions - Ships

### Get ship by name/language
<AzurApi>.ships.name(/* name: string, language: 'en' | 'cn' | 'jp' | 'kr' */);

<AzurApi>.ships.hull(/* name: string */);
```
> TODO: Rattley will write the rest later
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ To use the Library, Please refer to the [Docs](https://azurapi.github.io/v2/).

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

## Support Server
## Breaking Changes

### 1.1.0
- All functions from accessors after verion 1.1.0 return arrays.
- Bundles are now built with typescript version 4.5.5

## Discord Support Server

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

Expand Down
97 changes: 27 additions & 70 deletions bundles/azurapi.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions bundles/azurapi.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions bundles/azurapi.umd.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion docs/CNAME

This file was deleted.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/classes/core_CacheUpdater.default.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/classes/core_Client.AzurAPI.html

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions docs/classes/core_api_api.default.html

Large diffs are not rendered by default.

31 changes: 16 additions & 15 deletions docs/classes/core_api_api_barrage.Barrages.html

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions docs/classes/core_api_api_chapter.Chapters.html

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions docs/classes/core_api_api_equipment.Equipments.html

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions docs/classes/core_api_api_ship.Ships.html

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions docs/classes/core_api_api_voiceline.Voicelines.html

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
</p>
<p>
<a href="https://github.com/AzurAPI/azurapi-js/actions">
<img src="https://github.com/AzurAPI/azurapi-js/workflows/Github%20Actions/badge.svg?branch=v2-array-cache" alt="Github Actions" />
<img src="https://github.com/AzurAPI/azurapi-js/workflows/Github%20Actions/badge.svg?branch=master" alt="Github Actions" />
</a>
<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>
</p>
<p><a href="https://npmjs.com/package/@azurapi/azurapi"><img src="https://nodeico.herokuapp.com/@azurapi/azurapi.svg"></a>
<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>
</p>
</div>

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

<a href="#support-server" id="support-server" style="color: inherit; text-decoration: none;">
<h2>Support Server</h2>
<a href="#breaking-changes" id="breaking-changes" style="color: inherit; text-decoration: none;">
<h2>Breaking Changes</h2>
</a>

<a href="#110" id="110" style="color: inherit; text-decoration: none;">
<h3>1.1.0</h3>
</a>
<ul>
<li>All functions from accessors after verion 1.1.0 return arrays.</li>
</ul>

<a href="#discord-support-server" id="discord-support-server" style="color: inherit; text-decoration: none;">
<h2>Discord Support Server</h2>
</a>
<p><a href="https://discord.gg/aAEdys8"><img src="https://discordapp.com/api/guilds/648206344729526272/widget.png?style=banner2" alt=""></a></p>
<p>Discord Link: <a href="https://discord.gg/aAEdys8">https://discord.gg/aAEdys8</a></p>
Expand Down
2 changes: 1 addition & 1 deletion docs/interfaces/core_Client.CacheOptions.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/core_api_api.advancedOptions.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_barrage.Barrage.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_barrage.Rounds.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_chapter.Chapter.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_chapter.SubChapter.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_equipment.Equipment.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_identifiable.Identifiable.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_ship.Ship.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_ship.shipAdvancedOptions.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/interfaces/types_voiceline.Voiceline.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/modules/core_Client.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/modules/core_Data.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/modules/core_UpdateChecker.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/modules/core_api_api.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/modules/types_barrage.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azurapi/azurapi",
"version": "1.0.6",
"version": "1.1.0",
"description": "Open Source Azur Lane Local Database",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
5 changes: 3 additions & 2 deletions src/core/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ export default class API<T extends Identifiable> {
/**
* Get by any
* @param query Any
* @returns Array
*/
get(query: string): T | undefined {
return this.id(query) || this.fuze(query)?.map(s => s.item)[0];
get(query: string): T | T[] {
return this.id(query) || this.fuze(query)?.map(s => s.item);
}

/**
Expand Down
11 changes: 5 additions & 6 deletions src/core/api/api_barrage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,31 @@ export class Barrages extends API<Barrage> {
* Get barrage by name
* @param name Barrage name
*/
name(name: string): Barrage | undefined {
for (let barrage of this.raw) if (normalize(barrage.name.toUpperCase()) === normalize(name.toUpperCase())) return barrage;
return undefined;
name(name: string): Barrage[] | [] {
return this.raw.filter(barrage => normalize(barrage.name.toUpperCase()) === normalize(name.toUpperCase()));
}

/**
* Get barrage by type
* @param type Barrage type
*/
type(type: 'ship' | 'class' | 'skill'): Barrage[] | void[] {
type(type: 'ship' | 'class' | 'skill'): Barrage[] | [] {
return this.raw.filter(barrage => normalize(barrage.type.toUpperCase()) === normalize(type.toUpperCase()));
}

/**
* Get barrage by hull type
* @param hull Hull type
*/
hull(hull: Hull): Barrage[] | void[] {
hull(hull: Hull): Barrage[] | [] {
return this.raw.filter(barrage => normalize(barrage.hull.toUpperCase()) === normalize(hull.toUpperCase()));
}

/**
* Sort barrages by compatable ship
* @param ship A ship name
*/
ships(ship: Ships): Barrage[] | void[] {
ships(ship: Ships): Barrage[] | [] {
return this.raw.filter(barrage => barrage.ships.map(ship => normalize(ship.toUpperCase())).includes(normalize(ship.toUpperCase())));
}
}
17 changes: 11 additions & 6 deletions src/core/api/api_chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ export class Chapters extends API<Chapter> {
* @param name Chapter name
* @param languages Language to search
*/
name(name: string, languages: Language[] = ['en', 'cn', 'jp']): Chapter | SubChapter | undefined {
for (let chapter of this.raw) if (languages.some(lang => chapter.names[lang] && normalize(chapter.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) return chapter;
/*for (let chapter of this.raw) {
for (let sub of chapter) if (languages.some(lang => sub.names[lang] && normalize(sub.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) return sub;
}*/
return undefined;
name(name: string, languages: Language[] = ['en', 'cn', 'jp']): (Chapter | SubChapter)[] | [] {
let result: (Chapter | SubChapter)[] = [];
for (let chapter of this.raw) {
if (languages.some(lang => chapter.names[lang] && normalize(chapter.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) result.push(chapter);
for (let sub of Object.values(chapter)) {
if (sub.names !== undefined) {
if (languages.some(lang => sub.names[lang] && normalize(sub.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) result.push(sub);
}
}
}
return result;
}
}
41 changes: 11 additions & 30 deletions src/core/api/api_equipment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,44 @@ export class Equipments extends API<Equipment> {
* @param name Equipment name
* @param languages Language to search
*/
name(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Equipment | undefined {
for (let equipment of this.raw) if (languages.some(lang => equipment.names[lang] && normalize(equipment.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) return equipment;
return undefined;
name(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Equipment[] | [] {
return this.raw.filter(equipment => languages.some(lang => equipment.names[lang] && normalize(equipment.names[lang].toUpperCase()) === normalize(name.toUpperCase())));
}

/**
* Lists the equipments by category
* @param category name of the category you want to search for
*/
category(category: string): Equipment[] {
let results: Equipment[] = [];
for (let equipment of this.raw) if (normalize(equipment.category.toUpperCase() === normalize(category.toUpperCase()))) results.push(equipment);
return results;
category(category: string): Equipment[] | [] {
return this.raw.filter(equipment => normalize(equipment.category.toUpperCase() === normalize(category.toUpperCase())));
}

/**
* Lists the equipments by nationality
* @param nationality naitionality name of the equipments you want to search for
*/
nationality(nationality: string): Equipment[] {
let results: Equipment[] = [];
nationality(nationality: string): Equipment[] | [] {
nationality = Object.keys(NATIONS).find(key => NATIONS[key].includes(nationality.toLowerCase())) || nationality;
for (let equipment of this.raw) if (normalize(equipment.nationality.toUpperCase()) === normalize(nationality.toUpperCase())) results.push(equipment);
return results;
}

private _nameAll(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Equipment[] {
return this.raw.filter(equipment => languages.some(lang => equipment.names[lang] && normalize(equipment.names[lang].toUpperCase()) === normalize(name.toUpperCase())));
return this.raw.filter(equipment => normalize(equipment.nationality.toUpperCase()) === normalize(nationality.toUpperCase()));
}

/**
* Get equipment using name in any language or id
* @param query Equipment name in any language or equipment id
*/
get(query: string, adv?: advancedOptions): Equipment | undefined {
if (adv) {
if (adv.idOnly) {
return this.id(query);
} else if (adv.nameOnly || adv.nameOnly && !adv.language) {
return this.name(query);
} else if (adv.nameOnly && adv.language) {
return this.name(query, [adv.language]);
}
} else {
let fuzeResult = this.fuze(query).sort((a, b) => (b.score || 0) - (a.score || 0))[0];
return this.id(query) || this.name(query) || (fuzeResult ? fuzeResult.item : undefined);
}
get(query: string): Equipment | Equipment[] {
let fuzeResult = this.fuze(query).sort((a, b) => (b.score || 0) - (a.score || 0))[0];
return this.id(query) || this.name(query) || (fuzeResult ? fuzeResult.item : undefined);
}

/**
* Get equipment using everything
* @param query basically anyting i guess
*/
all(query: string): Equipment[] {
all(query: string): Equipment[] | [] {
let results: (Equipment | undefined)[] = [];
results.push(this.id(query));
results.push(...this._nameAll(query).filter(i => i));
results.push(...this.name(query).filter(i => i));
results.push(...this.fuze(query).map(i => i.item));
return results
.filter((value: Equipment | undefined): value is Equipment => value !== null && value !== undefined)
Expand Down
35 changes: 10 additions & 25 deletions src/core/api/api_ship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,64 +24,49 @@ export class Ships extends API<Ship> {
* @param name Ship name
* @param languages Language to search
*/
name(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Ship | undefined {
for (let ship of this.raw) if (languages.some(lang => ship.names[lang] && normalize(ship.names[lang].toUpperCase()) === normalize(name.toUpperCase()))) return ship;
return undefined;
name(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Ship[] | [] {
return this.raw.filter(ship => languages.some(lang => ship.names[lang] && normalize(ship.names[lang].toUpperCase()) === normalize(name.toUpperCase())));
}

/**
* Get ship by hull
* @param hull Hull name
*/
hull(hull: string): Ship[] {
hull(hull: string): Ship[] | [] {
return this.raw.filter(ship =>
(ship.hullType && normalize(ship.hullType.toUpperCase()) === normalize(hull.toUpperCase())) ||
(ship.retrofitHullType && normalize(ship.retrofitHullType.toUpperCase()) === normalize(hull.toUpperCase()))
(ship.retrofitHullType && normalize(ship.retrofitHullType.toUpperCase()) === normalize(hull.toUpperCase()))
);
}

/**
* Get ship by nationality
* @param nationality Nationality name
*/
nationality(nationality: string): Ship[] {
nationality(nationality: string): Ship[] | [] {
let results: Ship[] = [];
nationality = Object.keys(NATIONS).find(key => NATIONS[key].includes(nationality.toLowerCase())) || nationality;
for (let ship of this.raw) if (normalize(ship.nationality.toUpperCase()) === normalize(nationality.toUpperCase())) results.push(ship);
return results;
}

private _nameAll(name: string, languages: Language[] = ['en', 'cn', 'jp', 'kr']): Ship[] {
return this.raw.filter(ship => languages.some(lang => ship.names[lang] && normalize(ship.names[lang].toUpperCase()) === normalize(name.toUpperCase())));
}

/**
* Get ship using name in any language or id
* @param query Ship name in any language or ship id
*/
get(query: string, adv?: advancedOptions): Ship | undefined {
if (adv) {
if (adv.idOnly) {
return this.id(query);
} else if (adv.nameOnly || adv.nameOnly && !adv.language) {
return this.name(query);
} else if (adv.nameOnly && adv.language) {
return this.name(query, [adv.language]);
}
} else {
let fuzeResult = this.fuze(query).sort((a, b) => (b.score || 0) - (a.score || 0))[0];
return this.id(query) || this.name(query) || (fuzeResult ? fuzeResult.item : undefined);
}
get(query: string): Ship | Ship[] {
let fuzeResult = this.fuze(query).sort((a, b) => (b.score || 0) - (a.score || 0))[0];
return this.id(query) || this.name(query)[0] || (fuzeResult ? fuzeResult.item : undefined);
}

/**
* Get ship using everything
* @param query basically anyting i guess
*/
all(query: string): Ship[] {
all(query: string): Ship[] | [] {
let results: (Ship | undefined)[] = [];
results.push(this.id(query));
results.push(...this._nameAll(query).filter(i => i));
results.push(...this.name(query).filter(i => i));
results.push(...this.fuze(query).map(i => i.item));
return results
.filter((value: Ship | undefined): value is Ship => value !== null && value !== undefined)
Expand Down

0 comments on commit 9fa586e

Please sign in to comment.