method param { Object } avatars import { CharacterNickname } from '.' ; import { Character } from '../types/Character' ; export class CharactersFilter { _list : Character [ ] = [ ] ; nicknameFilter : CharacterNickname ; constructor ( avatars ) { this . _list = avatars ; this . nicknameFilter = new CharacterNickname ( ) ; } function name ( nameFind ) { const id = this . nicknameFilter . getIdByNickname ( nameFind ) ; if ( id ) { return this . id ( id ) ; } return this . _list . find ( ( { name } ) => name === nameFind ) ; } id ( idFind ) { return this . _list . find ( ( { id } ) => id === idFind ) ; } function element ( el ) { el = el . toLocaleLowerCase ( ) ; const elAlias = { 火 : 'pyro' , fire : 'pyro' , 水 : 'hydro' , water : 'hydro' , 风 : 'anemo' , wind : 'anemo' , 雷 : 'electro' , thunder : 'electro' , 冰 : 'cryo' , ice : 'cryo' , 岩 : 'geo' , rock : 'geo' , 草 : 'dendro' , grass : 'dendro' , } ; el = elAlias [ el ] || el ; return this . _list . filter ( ( { element } ) => element . toLowerCase ( ) === el ) ; } function param { Array | Number } rarity ( rarity ) { let queryRarity = [ ] ; if ( typeof rarity === 'number' ) { queryRarity = [ rarity ] ; } else if ( rarity . constructor !== Array ) { return [ ] ; } return this . _list . filter ( ( { rarity } ) => queryRarity . includes ( rarity ) ) ; } function all ( ) { return this . _list ; } }