Skip to content

Commit

Permalink
fix 'names' not being a valid query
Browse files Browse the repository at this point in the history
fyi putting 'names' as query will return a list of all results
  • Loading branch information
theBowja committed Mar 22, 2021
1 parent 501e479 commit 39db693
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 40 deletions.
2 changes: 1 addition & 1 deletion examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let header = `# Examples\n\nFirst start off with:\n${codeStart()}const ${libname
let folders = [
{
function: 'characters',
params: ['jean','amber, { resultlanguage: \'JP\' }', 'carmen', 'december', 'pyro', 'geo dmg', 'liyue', 'sword', 'ballad']
params: ['names','amber, { resultlanguage: \'JP\' }', 'carmen', 'december', 'pyro', 'geo dmg', 'liyue', 'sword', 'ballad']
},
{
function: 'talents',
Expand Down
49 changes: 14 additions & 35 deletions examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,22 @@ const genshindb = require('genshin-db');
## genshindb.characters(query[, opts])]

<details>
<summary>genshindb.characters('<b>jean'</b>)</summary>
<summary>genshindb.characters('<b>name'</b>)</summary>

```js
{
name: 'Jean',
title: 'Dandelion Knight',
description: "The righteous and rigorous Dandelion Knight, and Acting Grand Master of Mondstadt's Knights of Favonius.",
rarity: '5',
element: 'Anemo',
weapontype: 'Sword',
substat: 'Healing Bonus',
gender: 'Female',
body: 'LADY',
association: 'MONDSTADT',
region: 'Mondstadt',
affiliation: 'Knights of Favonius',
birthdaymmdd: '3/14',
birthday: 'March 14',
constellation: 'Leo Minor',
cv: {
english: 'Stephanie Southerland',
chinese: '林簌',
japanese: '斎藤千和',
korean: '안영미'
},
talentmaterialtype: 'Resistance',
url: 'https://genshin-impact.fandom.com/wiki/Jean',
images: {
image: 'https://static.wikia.nocookie.net/gensin-impact/images/8/89/Character_Jean_Thumb.png',
card: 'https://static.wikia.nocookie.net/gensin-impact/images/0/0e/Character_Jean_Card.jpg',
portrait: 'https://static.wikia.nocookie.net/gensin-impact/images/0/02/Character_Jean_Portrait.png',
icon: 'https://upload-os-bbs.mihoyo.com/game_record/genshin/character_icon/UI_AvatarIcon_Qin.png',
sideicon: 'https://upload-os-bbs.mihoyo.com/game_record/genshin/character_side_icon/UI_AvatarIcon_Side_Qin.png',
cover1: 'https://uploadstatic-sea.mihoyo.com/contentweb/20200616/2020061611214389168.png',
cover2: 'https://uploadstatic-sea.mihoyo.com/contentweb/20200616/2020061611215344626.png'
}
}
[
'Aether', 'Albedo', 'Amber',
'Barbara', 'Beidou', 'Bennett',
'Chongyun', 'Diluc', 'Diona',
'Fischl', 'Ganyu', 'Hu Tao',
'Jean', 'Kaeya', 'Keqing',
'Klee', 'Lisa', 'Lumine',
'Mona', 'Ningguang', 'Noelle',
'Qiqi', 'Razor', 'Rosaria',
'Sucrose', 'Tartaglia', 'Venti',
'Xiangling', 'Xiao', 'Xingqiu',
'Xinyan', 'Zhongli'
]
```

</details>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genshin-db",
"version": "2.4.0",
"version": "2.4.1",
"description": "Genshin Impact v1.4 JSON database. Search and get results in all in-game languages! Sources from the fandom wiki and GenshinData repo.",
"main": "./src/main.js",
"scripts": {
Expand Down
8 changes: 5 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ function searchFolder(query, folder, opts) {
if(langindex.aliases[query] !== undefined)
return getData(opts.resultlanguage, folder, langindex.aliases[query]);

// check if query is in .categories
if(langindex.categories[query] !== undefined) {
// check if query is in .categories or is 'names'
if(langindex.categories[query] !== undefined || query === 'names') {
let reslangindex = getIndex(opts.resultlanguage, folder);
if(reslangindex === undefined) return undefined;

let tmparr = (query === 'names') ? Object.values(reslangindex.names) : langindex.categories[query];
// change the array of filenames into an array of data objects or data names. ignores undefined results if any
return langindex.categories[query].reduce((accum, filename) => {
return tmparr.reduce((accum, filename) => {
let res = opts.verbose ? getData(opts.resultlanguage, folder, filename) : reslangindex.namemap[filename];
if(res !== undefined) accum.push(res);
return accum;
Expand Down

0 comments on commit 39db693

Please sign in to comment.