1.0.22 β€’ Published 5 years ago

poke-types v1.0.22

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

PokΓ©Types

Awesome Pokemon Build Status JavaScript Style Guide File Size

Known Vulnerabilities

Install

yarn

$ yarn add poke-types

npm

$ npm install --save poke-types

Usage

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!

API

.effectiveness: Object

noEffectweaknotVeryEffectivenormalsuperEffectiveultra
00.250.5124

.types: string[]

normalfirewaterelectricgrassicefightingpoisonground
flyingpsychicbugrockghostdragondarksteelfairy

.getTypeWeaknesses(type: string, ?secondType: string): Object

type

type name to get weaknesses for

secondType

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, ... }

.getTypeStrengths(type: string): Object

type:

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, ... }

License

MIT @ Frederik Bosch

1.0.22

5 years ago

1.0.21

5 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago