mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-14 08:08:34 +02:00
Use slugs in whos-that-pokemon
This commit is contained in:
@@ -34,7 +34,7 @@ module.exports = class Pokemon {
|
||||
}
|
||||
|
||||
get slug() {
|
||||
return encodeURIComponent(this.name.toLowerCase().replace(/ /g, '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
return this.store.makeSlug(this.name);
|
||||
}
|
||||
|
||||
get spriteImageURL() {
|
||||
|
||||
@@ -5,7 +5,7 @@ const missingno = require('../../assets/json/missingno');
|
||||
|
||||
module.exports = class PokemonStore extends Collection {
|
||||
async fetch(query) {
|
||||
query = encodeURIComponent(query.toLowerCase().replace(/ /g, '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
query = this.makeSlug(query);
|
||||
if (!query) return null;
|
||||
const num = Number.parseInt(query, 10);
|
||||
if (this.has(num)) return this.get(num);
|
||||
@@ -26,4 +26,8 @@ module.exports = class PokemonStore extends Collection {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
makeSlug(query) {
|
||||
return encodeURIComponent(query.toLowerCase().replace(/ /g, '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user