Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move constants out to separate file, add some types #175

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"README.md",
"types/*",
"src/altnames.js",
"src/constants.js",
"src/language.js",
"src/folder.js",
"src/helper.js",
Expand Down
22 changes: 11 additions & 11 deletions src/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ class Options {
/**
*
*
* @param {boolean} dumpResult - If true, returns additional data such as the query, folder, what matched, the options, and the filename. The results of the search is found in the 'result' property.
* @param {boolean} matchNames - Allows autocomplete matching of data names.
* @param {boolean} matchAltNames - Allows autocomplete matching of alternate or custom names.
* @param {boolean} matchAliases - Allows autocomplete matching of data-defined aliases.
* @param {boolean} matchCategories - Allows autocomplete matching of categories. If true, returns an array of the categories that matched.
* @param {boolean} verboseCategories - Used if a category is matched. If true, then replaces each string name in the array with the data object instead
* @param {Array<String>} queryLanguages - The languages you wish your query will be searched in. See [Supported Languages](https://github.com/theBowja/genshin-db/blob/main/readme.md#genshindbsetoptionsopts)
* @param {String} resultLanguage - Output language that your results will be in.
* @param {boolean} v4Props - Adds genshin-db v4 data properties to the return result of the API.
* @param {boolean} v4PropsOnly - Same as v4Props but removes v5 data properties.
* @param {boolean} matchExactOnly -
* @param {boolean=} dumpResult - If true, returns additional data such as the query, folder, what matched, the options, and the filename. The results of the search is found in the 'result' property.
* @param {boolean=} matchNames - Allows autocomplete matching of data names.
* @param {boolean=} matchAltNames - Allows autocomplete matching of alternate or custom names.
* @param {boolean=} matchAliases - Allows autocomplete matching of data-defined aliases.
* @param {boolean=} matchCategories - Allows autocomplete matching of categories. If true, returns an array of the categories that matched.
* @param {boolean=} verboseCategories - Used if a category is matched. If true, then replaces each string name in the array with the data object instead
* @param {Array<string>=} queryLanguages - The languages you wish your query will be searched in. See [Supported Languages](https://github.com/theBowja/genshin-db/blob/main/readme.md#genshindbsetoptionsopts)
* @param {string=} resultLanguage - Output language that your results will be in.
* @param {boolean=} v4Props - Adds genshin-db v4 data properties to the return result of the API.
* @param {boolean=} v4PropsOnly - Same as v4Props but removes v5 data properties.
* @param {boolean=} matchExactOnly -
*/
constructor(dumpResult=undefined,
matchNames=undefined,
Expand Down
7 changes: 7 additions & 0 deletions src/altnames.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,16 @@ altnames.addAltName('English', 'constellations', 'Baal', 'raidenshogun');
altnames.addAltName('English', 'talents', 'Anemo Traveler', 'traveleranemo');
altnames.addAltName('English', 'talents', 'Electro Traveler', 'travelerelectro');
altnames.addAltName('English', 'talents', 'Geo Traveler', 'travelergeo');
altnames.addAltName('English', 'talents', 'Hydro Traveler', 'travelerhydro');
// TODO: when pyro traveler is added
// altnames.addAltName('English', 'talents', 'Pyro Traveler', 'travelerpyro');

altnames.addAltName('English', 'constellations', 'Anemo Traveler', 'traveleranemo');
altnames.addAltName('English', 'constellations', 'Electro Traveler', 'travelerelectro');
altnames.addAltName('English', 'constellations', 'Geo Traveler', 'travelergeo');
altnames.addAltName('English', 'constellations', 'Hydro Traveler', 'travelerhydro');
// TODO: when pyro traveler is added
// altnames.addAltName('English', 'constellations', 'Pyro Traveler', 'travelerpyro');

altnames.addAltName('English', 'enemies', 'Dvalin', 'stormterror');

Expand Down
119 changes: 119 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// enum for folders. // make sure update index.d.ts too
// not really used internally. mainly for altnames api
const FoldersEnum = {
characters : 'characters',
talents : 'talents',
constellations : 'constellations',

weapons : 'weapons',

foods : 'foods',
materials : 'materials',
crafts : 'crafts',

artifacts : 'artifacts',
domains : 'domains',
enemies : 'enemies',

rarity : 'rarity',
elements : 'elements',

achievements : 'achievements',
achievementgroups: 'achievementgroups',

windgliders : 'windgliders',
outfits : 'outfits',
animals : 'animals',
namecards : 'namecards',
geographies : 'geographies',
adventureranks : 'adventureranks',

emojis : 'emojis',
voiceovers : 'voiceovers',

tcgactioncards: 'tcgactioncards',
tcgcardbacks: 'tcgcardbacks',
tcgcardboxes: 'tcgcardboxes',
tcgcharactercards: 'tcgcharactercards',
tcgdetailedrules: 'tcgdetailedrules',
tcgenemycards: 'tcgenemycards',
tcgkeywords: 'tcgkeywords',
tcglevelrewards: 'tcglevelrewards',
tcgstatuseffects: 'tcgstatuseffects',
tcgsummons: 'tcgsummons'
};

const folders = Object.values(FoldersEnum);

const LanguagesEnum = {
'ChineseSimplified' : 'ChineseSimplified',
'ChineseTraditional' : 'ChineseTraditional',
'English' : 'English',
'French' : 'French',
'German' : 'German',
'Indonesian' : 'Indonesian',
'Italian' : 'Italian',
'Japanese' : 'Japanese',
'Korean' : 'Korean',
'Portuguese' : 'Portuguese',
'Russian' : 'Russian',
'Spanish' : 'Spanish',
'Thai' : 'Thai',
'Turkish' : 'Turkish',
'Vietnamese' : 'Vietnamese'
};

// converts Genshin's language codes into expanded strings
const languageMap = {
'CHS': 'ChineseSimplified',
'CHT': 'ChineseTraditional',
'DE': 'German',
'EN': 'English',
'ES': 'Spanish',
'FR': 'French',
'ID': 'Indonesian',
'IT': 'Italian',
'JP': 'Japanese',
'KR': 'Korean',
'PT': 'Portuguese',
'RU': 'Russian',
'TH': 'Thai',
'TR': 'Turkish',
'VI': 'Vietnamese'
};
// array of language strings
const languages = Object.values(languageMap);
// array of language codes
const languageCodes = Object.keys(languageMap);

// // converts expanded strings into javascript locale codes
const localeMap = {
'ChineseSimplified': 'zh-cn',
'ChineseTraditional': 'zh-tw',
'German': 'de',
'English': 'en',
'Spanish': 'es',
'French': 'fr',
'Indonesian': 'id',
'Italian': 'it',
'Japanese': 'ja',
'Korean': 'ko',
'Portuguese': 'pt',
'Russian': 'ru',
'Thai': 'th',
'Turkish': 'tr',
'Vietnamese': 'vi'
};

const languageDict = Object.keys(languageMap).concat(Object.values(languageMap));

module.exports = {
FoldersEnum,
folders, // Object.values(FoldersEnum)
languageMap,
languageCodes,
LanguagesEnum,
languages,
localeMap,
languageDict
}
56 changes: 5 additions & 51 deletions src/folder.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,5 @@
const fuzzysort = require('fuzzysort');

// enum for folders. // make sure update index.d.ts too
// not really used internally. mainly for altnames api
const FoldersEnum = {
characters : 'characters',
talents : 'talents',
constellations : 'constellations',

weapons : 'weapons',

foods : 'foods',
materials : 'materials',
crafts : 'crafts',

artifacts : 'artifacts',
domains : 'domains',
enemies : 'enemies',

rarity : 'rarity',
elements : 'elements',

achievements : 'achievements',
achievementgroups: 'achievementgroups',

windgliders : 'windgliders',
outfits : 'outfits',
animals : 'animals',
namecards : 'namecards',
geographies : 'geographies',
adventureranks : 'adventureranks',

emojis : 'emojis',
voiceovers : 'voiceovers',

tcgactioncards: 'tcgactioncards',
tcgcardbacks: 'tcgcardbacks',
tcgcardboxes: 'tcgcardboxes',
tcgcharactercards: 'tcgcharactercards',
tcgdetailedrules: 'tcgdetailedrules',
tcgenemycards: 'tcgenemycards',
tcgkeywords: 'tcgkeywords',
tcglevelrewards: 'tcglevelrewards',
tcgstatuseffects: 'tcgstatuseffects',
tcgsummons: 'tcgsummons'
};

const folders = Object.values(FoldersEnum);
const { folders, FoldersEnum } = require('./constants');

function autocompleteFolder(input) {
let result = fuzzysort.go(input, folders, { limit: 1 })[0];
Expand All @@ -54,7 +8,7 @@ function autocompleteFolder(input) {

/**
* @param folders - a string or array of strings
* @returns - autocompleted full name of the folder. see FoldersEnum.
* @returns {string | string[] | undefined} - autocompleted full name of the folder. see FoldersEnum.
* undefined if none of the strings are valid folders.
*/
function format(folders) {
Expand All @@ -72,7 +26,7 @@ function format(folders) {
}

module.exports = {
FoldersEnum: FoldersEnum,
folders: folders, // Object.values(FoldersEnum)
format: format
FoldersEnum,
folders, // Object.values(FoldersEnum)
format
};
10 changes: 5 additions & 5 deletions src/getdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ function addData(newdata, override = true) {
}

module.exports = {
addData: addData,
getData: getData,
getIndex: getIndex,
getImage: getImage,
getStats: getStats
addData,
getData,
getIndex,
getImage,
getStats
}
7 changes: 0 additions & 7 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,4 @@ helper.formatTalentLabels = function(attributes, talentlevel) {
return outlabels;
}








module.exports = helper;
75 changes: 8 additions & 67 deletions src/language.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,7 @@
// @ts-check
const fuzzysort = require('fuzzysort');
const { languageMap, LanguagesEnum, languages, languageCodes, localeMap, languageDict } = require('./constants');

const LanguagesEnum = {
'ChineseSimplified' : 'ChineseSimplified',
'ChineseTraditional' : 'ChineseTraditional',
'English' : 'English',
'French' : 'French',
'German' : 'German',
'Indonesian' : 'Indonesian',
'Italian' : 'Italian',
'Japanese' : 'Japanese',
'Korean' : 'Korean',
'Portuguese' : 'Portuguese',
'Russian' : 'Russian',
'Spanish' : 'Spanish',
'Thai' : 'Thai',
'Turkish' : 'Turkish',
'Vietnamese' : 'Vietnamese'
};

// converts Genshin's language codes into expanded strings
const languageMap = {
'CHS': 'ChineseSimplified',
'CHT': 'ChineseTraditional',
'DE': 'German',
'EN': 'English',
'ES': 'Spanish',
'FR': 'French',
'ID': 'Indonesian',
'IT': 'Italian',
'JP': 'Japanese',
'KR': 'Korean',
'PT': 'Portuguese',
'RU': 'Russian',
'TH': 'Thai',
'TR': 'Turkish',
'VI': 'Vietnamese'
};
// array of language strings
const languages = Object.values(languageMap);
// array of language codes
const languageCodes = Object.keys(languageMap);

// // converts expanded strings into javascript locale codes
const localeMap = {
'ChineseSimplified': 'zh-cn',
'ChineseTraditional': 'zh-tw',
'German': 'de',
'English': 'en',
'Spanish': 'es',
'French': 'fr',
'Indonesian': 'id',
'Italian': 'it',
'Japanese': 'ja',
'Korean': 'ko',
'Portuguese': 'pt',
'Russian': 'ru',
'Thai': 'th',
'Turkish': 'tr',
'Vietnamese': 'vi'
};

const languageDict = Object.keys(languageMap).concat(Object.values(languageMap));

function autocompleteLanguage(input, dict) {
let result = fuzzysort.go(input, dict, { limit: 1 })[0];
Expand Down Expand Up @@ -89,10 +30,10 @@ function format(langs) {
}

module.exports = {
LanguagesEnum: LanguagesEnum,
languages: languages, // array of strings
languageCodes: languageCodes,
languageMap: languageMap,
localeMap: localeMap,
format: format
LanguagesEnum,
languages, // array of strings
languageCodes,
languageMap,
localeMap,
format
};
Loading