🔥 💧 🍃
A module that exposes all Pokémon types, including
— their weaknesses, strengths and immunities.
$ yarn add poke-types
$ npm install --save poke-types
import { getTypeWeaknesses } from 'poke-types'
import { noEffect, notVeryEffective, superEffective, ultraEffective } from 'poke-types/effectiveness'
const abilityEffectiveness = (targetType, abilityType) => {
switch (getTypeWeaknesses(...targetType)[abilityType]) {
case noEffect: return 'It has no effect...'
case notVeryEffective: return 'It\'s not very effective...'
case superEffective: case ultraEffective: return 'It\'s super effective!'
default: return ''
}
}
const attack = pokemon => target => ability => {
return `
${pokemon.name} used ${ability.name}!
💥
${abilityEffectiveness(target.type, ability.type)}
`
}
const pikachu = {
name: 'Pikachu',
type: 'electric',
abilities: {
thunderbolt: {
name: 'Thunderbolt',
type: 'electric'
}
},
attack: target => ability => attack(pikachu)(target)(pikachu.abilities[ability])
}
const gyarados = {
name: 'Gyarados',
type: ['water', 'flying']
}
console.log(pikachu.attack(gyarados)('thunderbolt'))
// Pikachu used Thunderbolt!
// 💥
// It's super effective!
noEffect | weak | notVeryEffective | normal | superEffective | ultra |
---|---|---|---|---|---|
0 | 0.25 | 0.5 | 1 | 2 | 4 |
normal | fire | water | electric | grass | ice | fighting | poison | ground |
---|---|---|---|---|---|---|---|---|
flying | psychic | bug | rock | ghost | dragon | dark | steel | fairy |
type name to get weaknesses for
the second type to get dual type weaknesses for
pokeTypes.getTypeWeaknesses('grass')
// { normal: 1, fire: 2, water: 0.5, ... }
pokeTypes.getTypeWeaknesses('fire', 'bug')
// { normal: 1, fire: 1, water: 2, ... }
type name to get type strengths for.
pokeTypes.getTypeStrengths('electric')
// { normal: 1, fire: 1, water: 2, ... }
pokeType.getTypeStrengths('fighting')
// { normal: 2, fire: 1, water: 1, ... }
MIT @ Frederik Bosch