Giter Site home page Giter Site logo

fbosch / poke-types Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 0.0 821 KB

🔥💧🍃 Pokémon types, including — their weaknesses, strengths and immunities.

Home Page: https://www.npmjs.com/package/poke-types

License: MIT License

JavaScript 100.00%
pokemon resource nintendo npm-package package module types pokemon-types game game-freak

poke-types's Introduction

PokéTypes

Awesome Pokemon Downloads Downloads File Size Build Status JavaScript Style Guide Known Vulnerabilities


🔥 💧 🍃

A module that exposes all Pokémon types, including
— their weaknesses, strengths and immunities.

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

noEffect weak notVeryEffective normal superEffective ultra
0 0.25 0.5 1 2 4

.types: string[]

normal fire water electric grass ice fighting poison ground
flying psychic bug rock ghost dragon dark steel fairy

.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

poke-types's People

Contributors

dependabot[bot] avatar fbosch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.