pokescript

1.0.0 • Public • Published

PokeScript

PokeScript is an API wrapper for Pokéapi written in JavaScript.

Installation

It is recommended to install PokeScript using NPM:

npm install pokescript

Usage

PokeScript provides the following modules: Ability, Description, EggGroup, Move, Pokedex, Pokemon, Sprite, and Type. Each module must be passed the data returned by the corresponding Pokéapi endpoint, for example:

PokeScript.Ability({
	"created": "2013-11-03T15:05:59.496513",
	"description": "",
	"id": 4,
	"modified": "2013-11-03T15:05:59.496466",
	"name": "Battle-armor",
	"resource_uri": "/api/v1/ability/4/"
})

For convenience, the Pokedex module can be initialized using the PokeScript.loadPokedex method, which returns a Bluebird Promise, with a Pokedex parameter:

PokeScript.loadPokedex()
  .then(function(Pokedex){
    return Pokedex.search('pikachu');
  })

PokeScript also provides a PokeScript.get(resource, id) to get the initial data of other resources. Unfortunately, this method requires the id of the resource. Ex:

PokeScript.get('type', '2')
  .then(function(type){
    return PokeScript.Type(type);
  })

Note: You have to instantiate the module using this method, whereas PokeScript.loadPokedex returns the Pokedex module.

Some methods return Bluebird Promises, for example PokeScript.Pokemon.moves, where the callback parameter is an instance of the Moves module.

Sometimes, it is unnecessary to load additional data, so most promise methods also have a primitive version, e.g. PokeScript.Pokemon.moves_primitive, which returns an array of the names of each move available for the given Pokemon.

Examples

Finding Pikachu's available moves

Code

// Load the Pokedex
PokeScript.loadPokedex()
  // Search the Pokedex for Pikachu
  .then(function(Pokedex){
    return Promise.all(Pokedex.search('pikachu'));
  })
  // Load Pikachu's moves
  .then(function(results){
    return Promise.all(results[0].moves());
  })
  // Grab the name and description of each move
  .then(function(moves){
    return moves.map(function(move){
      return {
        'name': move.name(),
        'description': move.description()
      };
    });
  })
  // Log our data
  .then(function(data){
    console.log(data);
  });

Result

[{"name":"Covet","description":"Inflicts regular damage.  If the target is holding an item and the user is not, the user will permanently take the item.  Damage is still inflicted if an item cannot be taken.\n\nPokémon with sticky-hold or multitype are immune to the item theft effect.\n\nThe target cannot recover its item with recycle.\n\nThis move cannot be selected by assist or metronome."},{"name":"Wild-charge","description":"Inflicts regular damage.  User takes 1/4 the damage it inflicts in recoil."},{"name":"Volt-switch","description":"Inflicts regular damage, then the user immediately switches out, and the trainer selects a replacement Pokémon from the party.  If the target faint from this attack, the user's trainer selects the new Pokémon to send out first.  If the user is the last Pokémon in its party that can battle, it will not switch out.\n\nThe user may be hit by pursuit when it switches out, if it has been targeted and pursuit has not yet been used.\n\nThis move may be used even if the user is under the effect of ingrain.  ingrain's effect will end."},{"name":"Echoed-voice","description":"Inflicts regular damage.  If any friendly Pokémon used this move earlier this turn or on the previous turn, that use's power is added to this move's power, to a maximum of 200."},{"name":"Round","description":"Inflicts regular damage.  If round has already been used this turn, this move's power is doubled.  After this move is used, any other Pokémon using it this turn will immediately do so (in the order they would otherwise act), regardless of Speed or priority.  Pokémon using other moves will then continue to act as usual."},{"name":"Electro-ball","description":"Inflicts regular damage.  The greater the user's Speed compared to the target's, the higher power this move has, to a maximum of 150.\n\nUser's Speed                     | Power\n-------------------------------- | ----:\nUp to 2× the target's Speed      |    60\nUp to 3× the target's Speed      |    80\nUp to 4× the target's Speed      |   120\nMore than 4× the target's Speed  |   150\n"},{"name":"Magnet-rise","description":"For five turns, the user is immune to ground moves.\n\nIf the user is under the effect of ingrain or has levitate, this move will fail.\n\nThis effect is temporarily disabled by and cannot be used during gravity.\n\nThis effect is passed on by baton-pass."},{"name":"Signal-beam","description":"Inflicts regular damage.  Has a 10% chance to confuse the target."},{"name":"Knock-off","description":"Inflicts regular damage.  Target loses its held item.\n\nNeither the user nor the target can recover its item with recycle.\n\nIf the target has multitype or sticky-hold, it will take damage but not lose its item."},{"name":"Helping-hand","description":"Boosts the power of the target's moves by 50% until the end of this turn.\n\nThis move cannot be copied by mirror-move, nor selected by assist or metronome."},{"name":"Charge-beam","description":"Inflicts regular damage.  Has a 70% chance to raise the user's Special Attack by one stage."},{"name":"Grass-knot","description":"Inflicts regular damage.  Power increases with the target's weight in kilograms, to a maximum of 120.\n\nTarget's weight | Power\n--------------- | ----:\nUp to 10kg      |    20\nUp to 25kg      |    40\nUp to 50kg      |    60\nUp to 100kg     |    80\nUp to 200kg     |   100\nAbove 200kg     |   120\n"},{"name":"Captivate","description":"Lowers the target's Special Attack by two stages.  If the user and target are the same gender, or either is genderless, this move will fail."},{"name":"Discharge","description":"Inflicts regular damage.  Has a 30% chance to paralyze the target."},{"name":"Fling","description":"Inflicts regular damage.  Power and type are determined by the user's held item.  The item is consumed.  If the user is not holding an item, or its item has no set type and power, this move will fail.\n\nThis move ignores sticky-hold.\n\nIf the user is under the effect of embargo, this move will fail."},{"name":"Feint","description":"Inflicts regular damage.  Removes the effects of detect or protect from the target before hitting.\n\nThis move cannot be copied by mirror-move, nor selected by assist or metronome."},{"name":"Natural-gift","description":"Inflicts regular damage.  Power and type are determined by the user's held berry.  The berry is consumed.  If the user is not holding a berry, this move will fail."},{"name":"Counter","description":"Targets the last opposing Pokémon to hit the user with a physical move this turn.  Inflicts twice the damage that move did to the user.  If there is no eligible target, this move will fail.  Type immunity applies, but other type effects are ignored.\n\nThis move cannot be copied by mirror-move, nor selected by assist or metronome."},{"name":"Shock-wave","description":"Inflicts regular damage.  Ignores accuracy and evasion modifiers."},{"name":"Secret-power","description":"Inflicts regular damage.  Has a 30% chance to inflict an effect chosen according to the terrain.\n\nTerrain        | Effect\n-------------- | -------------------------------------------------------------\nBuilding       | Paralyze target\nCave           | Makes target flinch\nDeep water     | Lowers target's Attack by one stage\nDesert         | Lowers target's accuracy by one stage\nGrass          | Puts target to sleep\nMountain       | Makes target flinch\nRoad           | Lowers target's accuracy by one stage\nShallow water  | Lowers target's Attack by one stage\nSnow           | Freezes target\nTall grass     | Puts target to sleep\n\nIn Pokémon Battle Revolution:\n\nTerrain        | Effect\n-------------- | -------------------------------------------------------------\nCourtyard      | Paralyze target\nCrystal        | Makes target flinch\nGateway        | Lowers target's Attack by one stage\nMagma          | Makes target flinch\nMain Street    | Paralyze target\nNeon           | Paralyze target\nStargazer      | Makes target flinch\nSunny Park     | Puts target to sleep\nSunset         | Lowers target's accuracy by one stage\nWaterfall      | Puts target to sleep\n"},{"name":"Brick-break","description":"Destroys any light-screen or reflect on the target's side of the field, then inflicts regular damage.  The barriers are destroyed even if this move has no effect."},{"name":"Focus-punch","description":"Inflicts regular damage.  If the user takes damage this turn before hitting, this move will fail.\n\nThis move cannot be copied by mirror-move, nor selected by assist, metronome, or sleep-talk."},{"name":"Facade","description":"Inflicts regular damage.  If the user is burned, paralyzed, or poisoned, this move has double power."},{"name":"Rock-smash","description":"Inflicts regular damage.  Has a 50% chance to lower the target's Defense by one stage."},{"name":"Dig","description":"Inflicts regular damage.  User digs underground for one turn, becoming immune to attack, and hits on the second turn.\n\nDuring the immune turn, earthquake, fissure, and magnitude still hit the user normally, and their power is doubled if appropriate.\n\nThe user may be hit during its immune turn if under the effect of lock-on, mind-reader, or no-guard.\n\nThis move cannot be selected by sleep-talk."},{"name":"Rain-dance","description":"Changes the weather to rain for five turns, during which water moves inflict 50% extra damage, and fire moves inflict half damage.\n\nIf the user is holding damp-rock, this effect lasts for eight turns.\n\nthunder has 100% accuracy.  If the target has used detect or protect, thunder has a (100 - accuracy)% chance to break through the protection.\n\nsolar-beam has half power.\n\nmoonlight, morning-sun, and synthesis heal only 1/4 of the user's max HP.\n\nPokémon with swift-swim have doubled original Speed.\n\nPokémon with forecast become water.\n\nPokémon with dry-skin heal 1/8 max HP, Pokémon with hydration are cured of major status effects-effects, and Pokémon with rain-dish heal 1/16 max HP at the end of each turn."},{"name":"Hidden-power","description":"Inflicts regular damage.  Power and type are determined by the user's IV.\n\nPower is given by `x * 40 / 63 + 30`.  `x` is obtained by arranging bit 1 from the IV for each of Special Defense, Special Attack, Speed, Defense, Attack, and HP in that order.  (Bit 1 is 1 if the IV is of the form `4n + 2` or `4n + 3`.  `x` is then 64 * Special Defense IV bit 1, plus 32 * Special Attack IV bit 1, etc.)\n\nPower is always between 30 and 70, inclusive.  Average power is 49.5.\n\nType is given by `y * 15 / 63`, where `y` is similar to `x` above, except constructed from bit 0.  (Bit 0 is 1 if the IV is odd.)  The result is looked up in the following table.\n\nValue | Type\n----: | --------\n    0 | fighting\n    1 | flying\n    2 | poison\n    3 | ground\n    4 | rock\n    5 | bug\n    6 | ghost\n    7 | steel\n    8 | fire\n    9 | water\n   10 | grass\n   11 | electric\n   12 | psychic\n   13 | ice\n   14 | dragon\n   15 | dark\n\nThis move thus cannot be normal.  Most other types have an equal 1/16 chance to be selected, given random IV.  However, due to the flooring used here, bug, fighting, and grass appear 5/64 of the time, and dark only 1/64 of the time."},{"name":"Iron-tail","description":"Inflicts regular damage.  Has a 30% chance to lower the target's Defense by one stage."},{"name":"Dynamicpunch","description":"Inflicts regular damage.  Has a 100% chance to confuse the target."},{"name":"Frustration","description":"Inflicts regular damage.  Power increases inversely with happiness, given by `(255 - happiness) * 2 / 5`, to a maximum of 102.  Power bottoms out at 1."},{"name":"Return","description":"Inflicts regular damage.  Power increases with happiness, given by `happiness * 2 / 5`, to a maximum of 102.  Power bottoms out at 1."},{"name":"Sleep-talk","description":"Only usable if the user is sleep.  Randomly selects and uses one of the user's other three moves.  Use of the selected move requires and costs 0 PP.\n\nThis move will not select assist, bide, bounce, chatter, copycat, dig, dive, fly, focus-punch, me-first, metronome, mirror-move, shadow-force, skull-bash, sky-attack, sky-drop, sleep-talk, solar-beam, razor-wind, or uproar.\n\nIf the selected move requires a recharge turn—i.e., one of blast-burn, frenzy-plant, giga-impact, hydro-cannon, hyper-beam, roar-of-time, or rock-wrecker—and the user is still sleep next turn, then it's forced to use this move again and pay another PP for the recharge turn.\n\nThis move cannot be copied by mirror-move, nor selected by assist, metronome, or sleep-talk."},{"name":"Attract","description":"Causes the target to fall in love with the user, giving it a 50% chance to do nothing each turn.  If the user and target are the same gender, or either is genderless, this move will fail.  If either Pokémon leaves the field, this effect ends."},{"name":"Swagger","description":"Raises the target's Attack by two stages, then confuses it.  If the target's Attack cannot be raised by two stages, the confusion is not applied."},{"name":"Rollout","description":"Inflicts regular damage.  User is forced to use this move for five turns.  Power doubles every time this move is used in succession to a maximum of 16x, and resets to normal after the lock-in ends.  If this move misses or becomes unusable, the lock-in ends.\n\nIf the user has used defense-curl since entering the field, this move has double power."},{"name":"Endure","description":"The user's HP cannot be lowered below 1 by any means for the remainder of this turn.\n\nIf the user successfully used detect, endure, protect, quick-guard, or wide-guard on the last turn, this move has a 50% chance to fail.\n\nThis move cannot be selected by assist or metronome."},{"name":"Detect","description":"No moves will hit the user for the remainder of this turn.  If the user is last to act this turn, this move will fail.\n\nIf the user successfully used detect, endure, protect, quick-guard, or wide-guard on the last turn, this move has a 50% chance to fail.\n\nlock-on, mind-reader, and no-guard provide a (100 – accuracy)% chance for moves to break through this move.  This does not apply to one-hit KO moves (fissure, guillotine, horn-drill, and sheer-cold); those are always blocked by this move.\n\nthunder during rain-dance and blizzard during hail have a 30% chance to break through this move.\n\nThe following effects are not prevented by this move:\n\n* acupressure from an ally\n* curse's curse effect\n* Delayed damage from doom-desire and future-sight; however, these moves will be prevented if they are used this turn\n* feint, which will also end this move's protection after it hits\n* imprison\n* perish-song\n* shadow-force\n* Moves that merely copy the user, such as transform or psych-up\n\nThis move cannot be selected by assist or metronome."},{"name":"Zap-cannon","description":"Inflicts regular damage.  Has a 100% chance to paralyze the target."},{"name":"Mud-slap","description":"Inflicts regular damage.  Has a 100% chance to lower the target's accuracy by one stage."},{"name":"Protect","description":"No moves will hit the user for the remainder of this turn.  If the user is last to act this turn, this move will fail.\n\nIf the user successfully used detect, endure, protect, quick-guard, or wide-guard on the last turn, this move has a 50% chance to fail.\n\nlock-on, mind-reader, and no-guard provide a (100 – accuracy)% chance for moves to break through this move.  This does not apply to one-hit KO moves (fissure, guillotine, horn-drill, and sheer-cold); those are always blocked by this move.\n\nthunder during rain-dance and blizzard during hail have a 30% chance to break through this move.\n\nThe following effects are not prevented by this move:\n\n* acupressure from an ally\n* curse's curse effect\n* Delayed damage from doom-desire and future-sight; however, these moves will be prevented if they are used this turn\n* feint, which will also end this move's protection after it hits\n* imprison\n* perish-song\n* shadow-force\n* Moves that merely copy the user, such as transform or psych-up\n\nThis move cannot be selected by assist or metronome."},{"name":"Curse","description":"If the user is a ghost: user pays half its max HP to place a curse on the target, damaging it for 1/4 its max HP every turn.\nOtherwise: Lowers the user's Speed by one stage, and raises its Attack and Defense by one stage each.\n\nThe curse effect is passed on by baton-pass.\n\nThis move cannot be copied by mirror-move."},{"name":"Snore","description":"Only usable if the user is sleep.  Inflicts regular damage.  Has a 30% chance to make the target flinch."},{"name":"Defense-curl","description":"Raises user's Defense by one stage.\n\nAfter this move is used, the power of ice-ball and rollout are doubled until the user leaves the field."},{"name":"Strength","description":"Inflicts regular damage."},{"name":"Headbutt","description":"Inflicts regular damage.  Has a 30% chance to make the target flinch."},{"name":"Thunderpunch","description":"Inflicts regular damage.  Has a 10% chance to paralyze the target."},{"name":"Light-screen","description":"Erects a barrier around the user's side of the field that reduces damage from special attacks by half for five turns.  In double battles, the reduction is 1/3.  Critical hit are not affected by the barrier.\n\nIf the user is holding light-clay, the barrier lasts for eight turns.\n\nbrick-break or defog used by an opponent will destroy the barrier."},{"name":"Tail-whip","description":"Lowers the target's Defense by one stage."},{"name":"Slam","description":"Inflicts regular damage."},{"name":"Substitute","description":"Transfers 1/4 the user's max HP into a doll that absorbs damage and causes most negative move effects to fail.  If the user leaves the field, the doll will vanish.  If the user cannot pay the HP cost, this move will fail.\n\nThe doll takes damage as normal, using the user's stats and types, and will break when its HP reaches zero.  Self-inflicted damage from confusion or recoil is not absorbed.  Healing effects from opponents ignore the doll and heal the user as normal.  Moves that work based on the user's HP still do so; the doll's HP does not influence any move.\n\nThe doll will block major status effect-effects, confusion, and flinch.  The effects of smelling-salts and wake-up-slap do not trigger against a doll, even if the Pokémon behind the doll has the appropriate major status effect-effect.  Multi-turn trapping moves like wrap will hit the doll for their regular damage, but the multi-turn trapping and damage effects will not activate.\n\nMoves blocked or damage absorbed by the doll do not count as hitting the user or inflicting damage for any effects that respond to such, e.g., avalanche, counter, or a rowap-berry.  magic-coat still works as normal, even against moves the doll would block.  Opposing Pokémon that damage the doll with a leech move like absorb are healed as normal.\n\nIt will also block acupressure, block, the curse effect of curse, dream-eater, embargo, flatter, gastro-acid, grudge, heal-block, leech-seed, lock-on, mean-look, mimic, mind-reader, nightmare, pain-split, psycho-shift, spider-web, sketch, swagger, switcheroo, trick, worry-seed, and yawn.  A Pokémon affected by yawn before summoning the doll will still fall to sleep.\n\nThe doll blocks intimidate, but all other abilities act as though the doll did not exist.  If the user has an ability that absorbs moves of a certain type for HP (such as volt-absorb absorbing thunder-wave), such moves will not be blocked.\n\nlife-orb and berries that cause confusion still work as normal, but their respective HP loss and confusion are absorbed/blocked by the doll.\n\nThe user is still vulnerable to damage inflicted when entering or leaving the field, such as by pursuit or spikes; however, the doll will block the poison effect of toxic-spikes.\n\nThe doll is passed on by baton-pass.  It keeps its existing HP, but uses the replacement Pokémon's stats and types for damage calculation.\n\nAll other effects work as normal."},{"name":"Rest","description":"User falls to sleep and immediately regains all its HP.  If the user has another major status effect-effect, sleep will replace it.  The user will always wake up after two turns, or one turn with early-bird.\n\nThis move fail if the Pokémon cannot fall asleep due to uproar, insomnia, or vital-spirit.  It also fails if the Pokémon is at full health or is already asleep."},{"name":"Flash","description":"Lowers the target's accuracy by one stage."},{"name":"Skull-bash","description":"Inflicts regular damage.  Raises the user's Defense by one stage.  User then charges for one turn before attacking.\n\nThis move cannot be selected by sleep-talk."},{"name":"Swift","description":"Inflicts regular damage.  Ignores accuracy and evasion modifiers."},{"name":"Bide","description":"User waits for two turns.  On the second turn, the user inflicts twice the damage it accumulated on the last Pokémon to hit it.  Damage inflicted is typeless.\n\nThis move cannot be selected by sleep-talk."},{"name":"Reflect","description":"Erects a barrier around the user's side of the field that reduces damage from physical attacks by half for five turns.  In double battles, the reduction is 1/3.  Critical hit are not affected by the barrier.\n\nIf the user is holding light-clay, the barrier lasts for eight turns.\n\nbrick-break or defog used by an opponent will destroy the barrier."},{"name":"Double-team","description":"Raises the user's evasion by one stage."},{"name":"Mimic","description":"This move is replaced by the target's last successfully used move, and its PP changes to 5.  If the target hasn't used a move since entering the field, if it tried to use a move this turn and failed, or if the user already knows the targeted move, this move will fail.  This effect vanishes when the user leaves the field.\n\nIf chatter, metronome, mimic, sketch, or struggle is selected, this move will fail.\n\nThis move cannot be copied by mirror-move, nor selected by assist or metronome, nor forced by encore."},{"name":"Rage","description":"Inflicts regular damage.  Every time the user is hit after it uses this move but before its next action, its Attack raises by one stage."},{"name":"Quick-attack","description":"Inflicts regular damage."},{"name":"Agility","description":"Raises the user's Speed by two stages."},{"name":"Toxic","description":"Badly poisons the target.  Never misses when used by a poison-type Pokémon."},{"name":"Thunder","description":"Inflicts regular damage.  Has a 30% chance to paralyze the target.\n\nDuring rain-dance, this move has 100% accuracy.  It also has a (100 - accuracy)% chance to break through the protection of protect and detect.\n\nDuring sunny-day, this move has 50% accuracy."},{"name":"Thunder-wave","description":"Paralyzes the target."},{"name":"Thunderbolt","description":"Inflicts regular damage.  Has a 10% chance to paralyze the target."},{"name":"Thundershock","description":"Inflicts regular damage.  Has a 10% chance to paralyze the target."},{"name":"Seismic-toss","description":"Inflicts damage equal to the user's level.  Type immunity applies, but other type effects are ignored."},{"name":"Submission","description":"Inflicts regular damage.  User takes 1/4 the damage it inflicts in recoil."},{"name":"Surf","description":"Inflicts regular damage.\n\nIf the target is in the first turn of dive, this move will hit with double power."},{"name":"Growl","description":"Lowers the target's Attack by one stage."},{"name":"Double-edge","description":"Inflicts regular damage.  User takes 1/3 the damage it inflicts in recoil."},{"name":"Take-down","description":"Inflicts regular damage.  User takes 1/4 the damage it inflicts in recoil."},{"name":"Body-slam","description":"Inflicts regular damage.  Has a 30% chance to paralyze the target."},{"name":"Mega-kick","description":"Inflicts regular damage."},{"name":"Pay-day","description":"Inflicts regular damage.  After the battle ends, the winner receives five times the user's level in extra money for each time this move was used."},{"name":"Mega-punch","description":"Inflicts regular damage."}]

Find the weaknesses of each type that Fighting is ineffective against

Code

// Load the Fighting type (type 2)
PokeScript.get('type', '2')
  .then(function(type){
    return PokeScript.Type(type);
  })
  // Load each type that Fighting is ineffective against
  .then(function(Fighting){
    return Promise.all(Fighting.ineffective());
  })
  // Grab the weaknesses of each of these types
  .then(function(ineffectives){
    return ineffectives.map(function(type){
      return {
        'name': type.name(),
        'weaknesses': type.weakness_primitive() // We just want the names of the types, so we'll use weakness_primitive
      };
    });
  })
  .then(function(data){
    console.log(data);
  });

Result

[ { name: 'Poison', weaknesses: [ 'ground', 'psychic' ] }, { name: 'Flying', weaknesses: [ 'electric', 'ice', 'rock' ] }, { name: 'Psychic', weaknesses: [ 'bug', 'ghost', 'dark' ] }, { name: 'Bug', weaknesses: [ 'fire', 'flying', 'rock' ] }, { name: 'Fairy', weaknesses: [ 'poison', 'steel' ] } ]

Caching

PokeScript caches each request automatically, so you don't need to worry about making superfluous requests. This currently cannot be disabled.

Additional Documentation

PokeScript directly mirrors Pokéapi, so check out their documentation to see what properties are available for each module.

Package Sidebar

Install

npm i pokescript

Weekly Downloads

1

Version

1.0.0

License

ISC

Last publish

Collaborators

  • zubry