Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pkmn/data

Package Overview
Dependencies
Maintainers
1
Versions
198
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pkmn/data - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

20

build/index.d.ts

@@ -1,9 +0,10 @@

import { AbilityName, Condition, Dex, Effect, EggGroup, EvoType, FormeName, GenderName, GenerationNum, ID, ItemName, MoveCategory, MoveName, Nature, Nonstandard, Species as DexSpecies, SpeciesAbility, SpeciesName, StatName, StatsTable, Tier, Type as DexType, TypeName } from '@pkmn/dex-types';
declare const DEFAULT_EXISTS: (e: Effect | DexSpecies) => boolean;
import { AbilityName, Condition, Data, Dex, EggGroup, EvoType, FormeName, GenderName, GenerationNum, ID, ItemName, MoveCategory, MoveName, Nature, Nonstandard, Species as DexSpecies, SpeciesAbility, SpeciesName, StatName, StatsTable, Tier, Type as DexType, TypeName } from '@pkmn/dex-types';
declare const DEFAULT_EXISTS: (d: Data) => boolean;
declare type ExistsFn = typeof DEFAULT_EXISTS;
export declare function toID(text: any): ID;
export declare class Generations {
private readonly cache;
private readonly dex;
private readonly exists;
constructor(dex: Dex, exists?: (e: DexSpecies | Condition | import("@pkmn/dex-types").Ability | import("@pkmn/dex-types").Item | import("@pkmn/dex-types").Move) => boolean);
constructor(dex: Dex, exists?: (d: Data) => boolean);
get(gen: GenerationNum): Generation;

@@ -122,7 +123,8 @@ [Symbol.iterator](): Generator<Generation, void, unknown>;

constructor(dex: Dex, exists: ExistsFn);
get(name: string): Condition | import("@pkmn/dex-types").Ability | import("@pkmn/dex-types").Item | import("@pkmn/dex-types").Move | undefined;
get(name: string): import("@pkmn/dex-types").Ability | import("@pkmn/dex-types").Item | import("@pkmn/dex-types").Move | Condition | undefined;
}
export declare class Natures {
private readonly dex;
constructor(dex: Dex);
private readonly exists;
constructor(dex: Dex, exists: ExistsFn);
get(name: string): Nature | undefined;

@@ -140,3 +142,4 @@ [Symbol.iterator](): Generator<Nature, void, unknown>;

private readonly dex;
constructor(dex: Dex);
private readonly exists;
constructor(dex: Dex, exists: ExistsFn);
get(name: string): Type | undefined;

@@ -176,3 +179,4 @@ [Symbol.iterator](): Generator<Type, void, unknown>;

private readonly dex;
constructor(dex: Dex);
private readonly exists;
constructor(dex: Dex, exists: ExistsFn);
get(name: string): Promise<import("@pkmn/dex-types").Learnset | undefined>;

@@ -194,2 +198,2 @@ [Symbol.iterator](): AsyncGenerator<import("@pkmn/dex-types").Learnset, void, unknown>;

}
export { ID, As, Weather, FieldCondition, SideCondition, GenerationNum, GenderName, StatName, StatsTable, BoostName, BoostsTable, MoveCategory, MoveTarget, Nonstandard, EvoType, EggGroup, SideID, Player, GameType, HPColor, StatusName, NatureName, TypeName, HPTypeName, Tier, PokemonSet, AbilityName, ItemName, MoveName, SpeciesName, FormeName, EffectType, DataKind, Effect, EffectData, HitEffect, SecondaryEffect, ConditionData, AbilityData, ItemData, MoveData, SpeciesData, MoveSource, EventInfoData, LearnsetData, TypeData, NatureData, BasicEffect, Condition, Ability, Item, Move, EventInfo, Learnset, Nature, GenID, Dex, } from '@pkmn/dex-types';
export { ID, As, Weather, FieldCondition, SideCondition, GenerationNum, GenderName, StatName, StatsTable, BoostName, BoostsTable, MoveCategory, MoveTarget, Nonstandard, EvoType, EggGroup, SideID, Player, GameType, HPColor, StatusName, NatureName, TypeName, HPTypeName, Tier, PokemonSet, AbilityName, ItemName, MoveName, SpeciesName, FormeName, EffectType, Effect, DataKind, Data, EffectData, HitEffect, SecondaryEffect, ConditionData, AbilityData, ItemData, MoveData, SpeciesData, MoveSource, EventInfoData, LearnsetData, TypeData, NatureData, BasicEffect, Condition, Ability, Item, Move, EventInfo, Learnset, Nature, GenID, Dex, } from '@pkmn/dex-types';

39

build/index.js

@@ -16,6 +16,10 @@ "use strict";

exports.Stats = exports.Learnsets = exports.Type = exports.Types = exports.Natures = exports.Effects = exports.Specie = exports.Species = exports.Moves = exports.Items = exports.Abilities = exports.Generation = exports.Generations = exports.toID = void 0;
const DEFAULT_EXISTS = (e) => {
if (!e.exists || e.isNonstandard || e.id === 'noability')
const DEFAULT_EXISTS = (d) => {
if (!d.exists)
return false;
return !('tier' in e && ['Illegal', 'Unreleased'].includes(e.tier));
if ('isNonstandard' in d && d.isNonstandard)
return false;
if (d.kind === 'Ability' && d.id === 'noability')
return false;
return !('tier' in d && ['Illegal', 'Unreleased'].includes(d.tier));
};

@@ -37,5 +41,5 @@ function assignWithout(a, b, exclude) {

exports.toID = toID;
const GENERATIONS = Object.create(null);
class Generations {
constructor(dex, exists = DEFAULT_EXISTS) {
this.cache = Object.create(null);
this.dex = dex;

@@ -45,5 +49,5 @@ this.exists = exists;

get(gen) {
if (GENERATIONS[gen])
return GENERATIONS[gen];
return (GENERATIONS[gen] = new Generation(this.dex.forGen(gen), this.exists));
if (this.cache[gen])
return this.cache[gen];
return (this.cache[gen] = new Generation(this.dex.forGen(gen), this.exists));
}

@@ -65,5 +69,5 @@ *[Symbol.iterator]() {

this.species = new Species(this.dex, this.exists);
this.natures = new Natures(this.dex);
this.types = new Types(this.dex);
this.learnsets = new Learnsets(this.dex);
this.natures = new Natures(this.dex, this.exists);
this.types = new Types(this.dex, this.exists);
this.learnsets = new Learnsets(this.dex, this.exists);
this.effects = new Effects(this.dex, this.exists);

@@ -216,4 +220,5 @@ this.stats = new Stats(this.dex);

class Natures {
constructor(dex) {
constructor(dex, exists) {
this.dex = dex;
this.exists = exists;
}

@@ -224,3 +229,3 @@ get(name) {

const nature = this.dex.getNature(name);
return nature.exists ? nature : undefined;
return this.exists(nature) ? nature : undefined;
}

@@ -244,5 +249,6 @@ *[Symbol.iterator]() {

class Types {
constructor(dex) {
constructor(dex, exists) {
this.cache = Object.create(null);
this.dex = dex;
this.exists = exists;
// PS doesn't contain data for the '???' type

@@ -269,3 +275,3 @@ this.unknown = new Type({

const type = this.dex.getType(name);
if (!type.exists)
if (!this.exists(type))
return undefined;

@@ -322,8 +328,9 @@ const cached = this.cache[type.id];

class Learnsets {
constructor(dex) {
constructor(dex, exists) {
this.dex = dex;
this.exists = exists;
}
async get(name) {
const learnset = await this.dex.getLearnset(toID(name));
return learnset.exists ? learnset : undefined;
return this.exists(learnset) ? learnset : undefined;
}

@@ -330,0 +337,0 @@ [Symbol.iterator]() {

@@ -36,5 +36,14 @@ "use strict";

const Gen = (num) => gens.get(num);
// FIXME test exists override!
describe('exists', () => {
const gens2 = new index_1.Generations(Dex, e => !!e.exists && (!('num' in e) || e.num < 10));
expect(gens2.get(5).species.get('Bulbasaur')).toBeDefined();
expect(gens2.get(5).species.get('Gengar')).toBeUndefined();
expect(gens2.get(1).species.get('Chikorita')).toBeUndefined();
expect(gens2.get(4).abilities.get('Foo')).toBeUndefined();
expect(gens2.get(5).abilities.get('Stench')).toBeDefined();
expect(gens2.get(5).abilities.get('Adaptability')).toBeUndefined();
});
describe('Abilities', () => {
it('#get', () => {
expect(Gen(1).abilities.get('No Ability')).toBeUndefined();
expect(Gen(7).abilities.get('foo')).toBeUndefined();

@@ -41,0 +50,0 @@ expect(Gen(7).abilities.get('Illuminate').effectType).toBe('Ability');

@@ -1,1 +0,1 @@

var _this=this;function _defineProperties(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,i){return t&&_defineProperties(e.prototype,t),i&&_defineProperties(e,i),e}!function(){"use strict";var e={},t=_this&&_this.__await||function(e){return this instanceof t?(this.v=e,this):new t(e)},i=_this&&_this.__asyncGenerator||function(e,i,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s,r=n.apply(e,i||[]),o=[];return s={},a("next"),a("throw"),a("return"),s[Symbol.asyncIterator]=function(){return this},s;function a(e){r[e]&&(s[e]=function(t){return new Promise((function(i,n){o.push([e,t,i,n])>1||h(e,t)}))})}function h(e,i){try{(n=r[e](i)).value instanceof t?Promise.resolve(n.value.v).then(d,c):f(o[0][2],n)}catch(e){f(o[0][3],e)}var n}function d(e){h("next",e)}function c(e){h("throw",e)}function f(e,t){e(t),o.shift(),o.length&&h(o[0][0],o[0][1])}};e.Stats=e.Learnsets=e.Type=e.Types=e.Natures=e.Effects=e.Specie=e.Species=e.Moves=e.Items=e.Abilities=e.Generation=e.Generations=e.toID=void 0;var n=function(e){return!(!e.exists||e.isNonstandard||"noability"===e.id)&&!("tier"in e&&["Illegal","Unreleased"].includes(e.tier))};function s(e){return(null==e?void 0:e.id)&&(e=e.id),"string"!=typeof e&&"number"!=typeof e?"":(""+e).toLowerCase().replace(/[^a-z0-9]+/g,"")}e.toID=s;var r=Object.create(null),o=function(){function e(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n;this.dex=e,this.exists=t}var t=e.prototype;return t.get=function(e){return r[e]?r[e]:r[e]=new a(this.dex.forGen(e),this.exists)},t[Symbol.iterator]=function*(){for(var e=1;e<=8;e++)yield this.get(e)},e}();e.Generations=o;var a=function(){function e(e,t){this.dex=e,this.exists=t,this.abilities=new h(this.dex,this.exists),this.items=new d(this.dex,this.exists),this.moves=new c(this.dex,this.exists),this.species=new f(this.dex,this.exists),this.natures=new v(this.dex),this.types=new x(this.dex),this.learnsets=new S(this.dex),this.effects=new p(this.dex,this.exists),this.stats=new k(this.dex)}return _createClass(e,[{key:"num",get:function(){return this.dex.gen}}]),e}();e.Generation=a;var h=function(){function e(e,t){this.dex=e,this.exists=t}var t=e.prototype;return t.get=function(e){var t=this.dex.getAbility(e);return this.exists(t)?t:void 0},t[Symbol.iterator]=function*(){for(var e in this.dex.data.Abilities){var t=this.get(e);t&&(yield t)}},e}();e.Abilities=h;var d=function(){function e(e,t){this.dex=e,this.exists=t}var t=e.prototype;return t.get=function(e){var t=this.dex.getItem(e);return this.exists(t)?t:void 0},t[Symbol.iterator]=function*(){for(var e in this.dex.data.Items){var t=this.get(e);t&&(yield t)}},e}();e.Items=d;var c=function(){function e(e,t){this.dex=e,this.exists=t}var t=e.prototype;return t.get=function(e){var t=this.dex.getMove(e);return this.exists(t)?t:void 0},t[Symbol.iterator]=function*(){for(var e in this.dex.data.Moves){var t=this.get(e);t&&(yield t)}},e}();e.Moves=c;var f=function(){function e(e,t){this.cache=Object.create(null),this.dex=e,this.exists=t}var t=e.prototype;return t.get=function(e){var t=this.dex.getSpecies(e);if(this.exists(t)){var i=t.speciesid||t.id,n=this.cache[i];return n||(this.cache[i]=new u(this.dex,this.exists,t))}},t[Symbol.iterator]=function*(){for(var e in this.dex.data.Species){var t=this.get(e);t&&(yield t)}},e}();e.Species=f;var u=function(){function e(t,i,n){var s,r,o,a,h,d,c,f,u,p=this;!function(e,t,i){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&!i.has(n)&&(e[n]=t[n])}(this,n,e.EXCLUDE),this.dex=t,this.dex.gen>=2?(this.gender=n.gender,this.genderRatio=n.genderRatio):this.genderRatio={M:0,F:0},this.evos=null===(s=n.evos)||void 0===s?void 0:s.filter((function(e){return i(p.dex.getSpecies(e))})),this.nfe=!!(null===(r=this.evos)||void 0===r?void 0:r.length),this.nfe||(this.evos=void 0),this.cosmeticFormes=null===(o=n.cosmeticFormes)||void 0===o?void 0:o.filter((function(e){return i(p.dex.getSpecies(e))})),(null===(a=this.cosmeticFormes)||void 0===a?void 0:a.length)||(this.cosmeticFormes=void 0),this.otherFormes=null===(h=n.otherFormes)||void 0===h?void 0:h.filter((function(e){return i(p.dex.getSpecies(e))})),(null===(d=this.otherFormes)||void 0===d?void 0:d.length)||(this.otherFormes=void 0),this.formeOrder=null===(c=n.formeOrder)||void 0===c?void 0:c.filter((function(e){return i(p.dex.getSpecies(e))})),(null===(f=this.formeOrder)||void 0===f?void 0:f.length)||(this.formeOrder=void 0),this.formes=null===(u=this.formeOrder)||void 0===u?void 0:u.filter((function(e){return!p.dex.getSpecies(e).isGigantamax})),this.prevo=n.prevo&&i(this.dex.getSpecies(n.prevo))?n.prevo:void 0}return e.prototype.hasAbility=function(e){return this.dex.hasAbility(this,e)},_createClass(e,[{key:"formeNum",get:function(){var e=this;return this.baseSpecies===this.name?this.formeOrder?this.formeOrder.findIndex((function(t){return t===e.name})):0:this.dex.getSpecies(this.baseSpecies).formeOrder.findIndex((function(t){return t===(e.isGigantamax?e.baseSpecies:e.name)}))}}]),e}();e.Specie=u,u.EXCLUDE=new Set(["evos","gender","genderRatio","cosmeticFormes","nfe","otherFormes","prevo"]);var p=function(){function e(e,t){this.dex=e,this.exists=t}return e.prototype.get=function(e){var t=this.dex.getEffect(e);return this.exists(t)?t:void 0},e}();e.Effects=p;var v=function(){function e(e){this.dex=e}var t=e.prototype;return t.get=function(e){if(!(this.dex.gen<3)){var t=this.dex.getNature(e);return t.exists?t:void 0}},t[Symbol.iterator]=function*(){for(var e in this.dex.data.Natures){var t=this.get(e);t&&(yield t)}},e}();e.Natures=v;var l={"-2":.25,"-1":.5,0:1,1:2,2:4},x=function(){function e(e){this.cache=Object.create(null),this.dex=e,this.unknown=new m({effectType:"Type",kind:"Type",id:"",name:"???",exists:e.gen<=4,gen:1,damageTaken:{},HPivs:{},HPdvs:{}},e,this)}var t=e.prototype;return t.get=function(e){if("???"===e)return this.unknown;var t=this.dex.getType(e);if(t.exists){var i=this.cache[t.id];return i||(this.cache[t.id]=new m(t,this.dex,this))}},t[Symbol.iterator]=function*(){for(var e in this.dex.data.Types)yield this.get(e);this.dex.gen>=2&&this.dex.gen<=4&&(yield this.unknown)},t.getHiddenPower=function(e){return this.dex.getHiddenPower(e)},t.canDamage=function(e,t){return this.dex.getImmunity(e,t)},t.totalEffectiveness=function(e,t){var i=""+this.dex.getEffectiveness(e,t);return l[i]},e}();e.Types=x;var g=[1,2,.5,0],y=["Fire","Water","Grass","Electric","Ice","Psychic","Dark","Dragon"],m=function(){function e(e,t,i){for(var n in Object.assign(this,e),this.types=i,this.category="Fairy"===this.name?void 0:y.includes(this.name)?"Special":"Physical",this.effectiveness={"???":1},t.data.Types){var s=n;this.effectiveness[s]=g[t.data.Types[s].damageTaken[this.name]||0]}}var t=e.prototype;return t.canDamage=function(e){return this.types.canDamage(this.name,e)},t.totalEffectiveness=function(e){return this.types.totalEffectiveness(this.name,e)},e}();e.Type=m;var S=function(){function e(e){this.dex=e}var n=e.prototype;return n.get=async function(e){var t=await this.dex.getLearnset(s(e));return t.exists?t:void 0},n[Symbol.iterator]=function(){return i(this,arguments,(function*(){for(var e in this.dex.data.Learnsets||(yield t(this.dex.getLearnset("LOAD"))),this.dex.data.Learnsets){var i=yield t(this.get(e));i&&(yield yield t(i))}}))},e}();e.Learnsets=S;var b=["hp","atk","def","spe","spa","spd"],w={HP:"hp",hp:"hp",Attack:"atk",Atk:"atk",atk:"atk",Defense:"def",Def:"def",def:"def","Special Attack":"spa",SpA:"spa",SAtk:"spa",SpAtk:"spa",spa:"spa",Special:"spa",spc:"spa",Spc:"spa","Special Defense":"spd",SpD:"spd",SDef:"spd",SpDef:"spd",spd:"spd",Speed:"spe",Spe:"spe",Spd:"spe",spe:"spe"},D={hp:["HP","HP"],atk:["Atk","Attack"],def:["Def","Defense"],spa:["SpA","Special Attack"],spd:["SpD","Special Defense"],spe:["Spd","Speed"],spc:["Spc","Special"]},k=function(){function e(e){this.dex=e}var t=e.prototype;return t.calc=function(e,t){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:31,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:252,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:100,r=arguments.length>5?arguments[5]:void 0;return this.dex.gen<3?A(e,t,this.toDV(i),n,s):P(e,t,i,n,s,r)},t.get=function(e){return w[e]},t.display=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=w[e];return void 0===i?e:(1===this.dex.gen&&"spa"===i&&(i="spc"),D[i][+t])},t.fill=function(e,t){for(var i=0;i<b.length;i++){var n=b[i];n in e||(e[n]=t)}return e},t.getHPDV=function(e){return this.toDV(void 0===e.atk?31:e.atk)%2*8+this.toDV(void 0===e.def?31:e.def)%2*4+this.toDV(void 0===e.spe?31:e.spe)%2*2+this.toDV(void 0===e.spa?31:e.spa)%2},t[Symbol.iterator]=function*(){for(var e=0;e<b.length;e++){var t=b[e];yield t}},t.toDV=function(e){return Math.floor(e/2)},t.toIV=function(e){return 2*e+1},e}();function A(e,t,i,n,s){return"hp"===e?Math.floor((2*(t+i)+63)*s/100)+s+10:Math.floor((2*(t+i)+63)*s/100)+5}function P(e,t,i,n,s,r){if("hp"===e)return 1===t?t:Math.floor((2*t+i+Math.floor(n/4))*s/100)+s+10;var o=1;return void 0!==r&&(r.plus===e?o=1.1:r.minus===e&&(o=.9)),Math.floor((Math.floor((2*t+i+Math.floor(n/4))*s/100)+5)*o)}e.Stats=k,window.Generations=e.Generations}();
var _this=this;function _defineProperties(t,e){for(var i=0;i<e.length;i++){var s=e[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(t,s.key,s)}}function _createClass(t,e,i){return e&&_defineProperties(t.prototype,e),i&&_defineProperties(t,i),t}!function(){"use strict";var t={},e=_this&&_this.__await||function(t){return this instanceof e?(this.v=t,this):new e(t)},i=_this&&_this.__asyncGenerator||function(t,i,s){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,r=s.apply(t,i||[]),o=[];return n={},a("next"),a("throw"),a("return"),n[Symbol.asyncIterator]=function(){return this},n;function a(t){r[t]&&(n[t]=function(e){return new Promise((function(i,s){o.push([t,e,i,s])>1||h(t,e)}))})}function h(t,i){try{(s=r[t](i)).value instanceof e?Promise.resolve(s.value.v).then(c,d):f(o[0][2],s)}catch(t){f(o[0][3],t)}var s}function c(t){h("next",t)}function d(t){h("throw",t)}function f(t,e){t(e),o.shift(),o.length&&h(o[0][0],o[0][1])}};t.Stats=t.Learnsets=t.Type=t.Types=t.Natures=t.Effects=t.Specie=t.Species=t.Moves=t.Items=t.Abilities=t.Generation=t.Generations=t.toID=void 0;var s=function(t){return!!t.exists&&((!("isNonstandard"in t)||!t.isNonstandard)&&(("Ability"!==t.kind||"noability"!==t.id)&&!("tier"in t&&["Illegal","Unreleased"].includes(t.tier))))};function n(t){return(null==t?void 0:t.id)&&(t=t.id),"string"!=typeof t&&"number"!=typeof t?"":(""+t).toLowerCase().replace(/[^a-z0-9]+/g,"")}t.toID=n;var r=function(){function t(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s;this.cache=Object.create(null),this.dex=t,this.exists=e}var e=t.prototype;return e.get=function(t){return this.cache[t]?this.cache[t]:this.cache[t]=new o(this.dex.forGen(t),this.exists)},e[Symbol.iterator]=function*(){for(var t=1;t<=8;t++)yield this.get(t)},t}();t.Generations=r;var o=function(){function t(t,e){this.dex=t,this.exists=e,this.abilities=new a(this.dex,this.exists),this.items=new h(this.dex,this.exists),this.moves=new c(this.dex,this.exists),this.species=new d(this.dex,this.exists),this.natures=new p(this.dex,this.exists),this.types=new l(this.dex,this.exists),this.learnsets=new m(this.dex,this.exists),this.effects=new u(this.dex,this.exists),this.stats=new k(this.dex)}return _createClass(t,[{key:"num",get:function(){return this.dex.gen}}]),t}();t.Generation=o;var a=function(){function t(t,e){this.dex=t,this.exists=e}var e=t.prototype;return e.get=function(t){var e=this.dex.getAbility(t);return this.exists(e)?e:void 0},e[Symbol.iterator]=function*(){for(var t in this.dex.data.Abilities){var e=this.get(t);e&&(yield e)}},t}();t.Abilities=a;var h=function(){function t(t,e){this.dex=t,this.exists=e}var e=t.prototype;return e.get=function(t){var e=this.dex.getItem(t);return this.exists(e)?e:void 0},e[Symbol.iterator]=function*(){for(var t in this.dex.data.Items){var e=this.get(t);e&&(yield e)}},t}();t.Items=h;var c=function(){function t(t,e){this.dex=t,this.exists=e}var e=t.prototype;return e.get=function(t){var e=this.dex.getMove(t);return this.exists(e)?e:void 0},e[Symbol.iterator]=function*(){for(var t in this.dex.data.Moves){var e=this.get(t);e&&(yield e)}},t}();t.Moves=c;var d=function(){function t(t,e){this.cache=Object.create(null),this.dex=t,this.exists=e}var e=t.prototype;return e.get=function(t){var e=this.dex.getSpecies(t);if(this.exists(e)){var i=e.speciesid||e.id,s=this.cache[i];return s||(this.cache[i]=new f(this.dex,this.exists,e))}},e[Symbol.iterator]=function*(){for(var t in this.dex.data.Species){var e=this.get(t);e&&(yield e)}},t}();t.Species=d;var f=function(){function t(e,i,s){var n,r,o,a,h,c,d,f,u,p=this;!function(t,e,i){for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&!i.has(s)&&(t[s]=e[s])}(this,s,t.EXCLUDE),this.dex=e,this.dex.gen>=2?(this.gender=s.gender,this.genderRatio=s.genderRatio):this.genderRatio={M:0,F:0},this.evos=null===(n=s.evos)||void 0===n?void 0:n.filter((function(t){return i(p.dex.getSpecies(t))})),this.nfe=!!(null===(r=this.evos)||void 0===r?void 0:r.length),this.nfe||(this.evos=void 0),this.cosmeticFormes=null===(o=s.cosmeticFormes)||void 0===o?void 0:o.filter((function(t){return i(p.dex.getSpecies(t))})),(null===(a=this.cosmeticFormes)||void 0===a?void 0:a.length)||(this.cosmeticFormes=void 0),this.otherFormes=null===(h=s.otherFormes)||void 0===h?void 0:h.filter((function(t){return i(p.dex.getSpecies(t))})),(null===(c=this.otherFormes)||void 0===c?void 0:c.length)||(this.otherFormes=void 0),this.formeOrder=null===(d=s.formeOrder)||void 0===d?void 0:d.filter((function(t){return i(p.dex.getSpecies(t))})),(null===(f=this.formeOrder)||void 0===f?void 0:f.length)||(this.formeOrder=void 0),this.formes=null===(u=this.formeOrder)||void 0===u?void 0:u.filter((function(t){return!p.dex.getSpecies(t).isGigantamax})),this.prevo=s.prevo&&i(this.dex.getSpecies(s.prevo))?s.prevo:void 0}return t.prototype.hasAbility=function(t){return this.dex.hasAbility(this,t)},_createClass(t,[{key:"formeNum",get:function(){var t=this;return this.baseSpecies===this.name?this.formeOrder?this.formeOrder.findIndex((function(e){return e===t.name})):0:this.dex.getSpecies(this.baseSpecies).formeOrder.findIndex((function(e){return e===(t.isGigantamax?t.baseSpecies:t.name)}))}}]),t}();t.Specie=f,f.EXCLUDE=new Set(["evos","gender","genderRatio","cosmeticFormes","nfe","otherFormes","prevo"]);var u=function(){function t(t,e){this.dex=t,this.exists=e}return t.prototype.get=function(t){var e=this.dex.getEffect(t);return this.exists(e)?e:void 0},t}();t.Effects=u;var p=function(){function t(t,e){this.dex=t,this.exists=e}var e=t.prototype;return e.get=function(t){if(!(this.dex.gen<3)){var e=this.dex.getNature(t);return this.exists(e)?e:void 0}},e[Symbol.iterator]=function*(){for(var t in this.dex.data.Natures){var e=this.get(t);e&&(yield e)}},t}();t.Natures=p;var v={"-2":.25,"-1":.5,0:1,1:2,2:4},l=function(){function t(t,e){this.cache=Object.create(null),this.dex=t,this.exists=e,this.unknown=new y({effectType:"Type",kind:"Type",id:"",name:"???",exists:t.gen<=4,gen:1,damageTaken:{},HPivs:{},HPdvs:{}},t,this)}var e=t.prototype;return e.get=function(t){if("???"===t)return this.unknown;var e=this.dex.getType(t);if(this.exists(e)){var i=this.cache[e.id];return i||(this.cache[e.id]=new y(e,this.dex,this))}},e[Symbol.iterator]=function*(){for(var t in this.dex.data.Types)yield this.get(t);this.dex.gen>=2&&this.dex.gen<=4&&(yield this.unknown)},e.getHiddenPower=function(t){return this.dex.getHiddenPower(t)},e.canDamage=function(t,e){return this.dex.getImmunity(t,e)},e.totalEffectiveness=function(t,e){var i=""+this.dex.getEffectiveness(t,e);return v[i]},t}();t.Types=l;var x=[1,2,.5,0],g=["Fire","Water","Grass","Electric","Ice","Psychic","Dark","Dragon"],y=function(){function t(t,e,i){for(var s in Object.assign(this,t),this.types=i,this.category="Fairy"===this.name?void 0:g.includes(this.name)?"Special":"Physical",this.effectiveness={"???":1},e.data.Types){var n=s;this.effectiveness[n]=x[e.data.Types[n].damageTaken[this.name]||0]}}var e=t.prototype;return e.canDamage=function(t){return this.types.canDamage(this.name,t)},e.totalEffectiveness=function(t){return this.types.totalEffectiveness(this.name,t)},t}();t.Type=y;var m=function(){function t(t,e){this.dex=t,this.exists=e}var s=t.prototype;return s.get=async function(t){var e=await this.dex.getLearnset(n(t));return this.exists(e)?e:void 0},s[Symbol.iterator]=function(){return i(this,arguments,(function*(){for(var t in this.dex.data.Learnsets||(yield e(this.dex.getLearnset("LOAD"))),this.dex.data.Learnsets){var i=yield e(this.get(t));i&&(yield yield e(i))}}))},t}();t.Learnsets=m;var S=["hp","atk","def","spe","spa","spd"],b={HP:"hp",hp:"hp",Attack:"atk",Atk:"atk",atk:"atk",Defense:"def",Def:"def",def:"def","Special Attack":"spa",SpA:"spa",SAtk:"spa",SpAtk:"spa",spa:"spa",Special:"spa",spc:"spa",Spc:"spa","Special Defense":"spd",SpD:"spd",SDef:"spd",SpDef:"spd",spd:"spd",Speed:"spe",Spe:"spe",Spd:"spe",spe:"spe"},w={hp:["HP","HP"],atk:["Atk","Attack"],def:["Def","Defense"],spa:["SpA","Special Attack"],spd:["SpD","Special Defense"],spe:["Spd","Speed"],spc:["Spc","Special"]},k=function(){function t(t){this.dex=t}var e=t.prototype;return e.calc=function(t,e){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:31,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:252,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:100,r=arguments.length>5?arguments[5]:void 0;return this.dex.gen<3?D(t,e,this.toDV(i),s,n):A(t,e,i,s,n,r)},e.get=function(t){return b[t]},e.display=function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=b[t];return void 0===i?t:(1===this.dex.gen&&"spa"===i&&(i="spc"),w[i][+e])},e.fill=function(t,e){for(var i=0;i<S.length;i++){var s=S[i];s in t||(t[s]=e)}return t},e.getHPDV=function(t){return this.toDV(void 0===t.atk?31:t.atk)%2*8+this.toDV(void 0===t.def?31:t.def)%2*4+this.toDV(void 0===t.spe?31:t.spe)%2*2+this.toDV(void 0===t.spa?31:t.spa)%2},e[Symbol.iterator]=function*(){for(var t=0;t<S.length;t++){var e=S[t];yield e}},e.toDV=function(t){return Math.floor(t/2)},e.toIV=function(t){return 2*t+1},t}();function D(t,e,i,s,n){return"hp"===t?Math.floor((2*(e+i)+63)*n/100)+n+10:Math.floor((2*(e+i)+63)*n/100)+5}function A(t,e,i,s,n,r){if("hp"===t)return 1===e?e:Math.floor((2*e+i+Math.floor(s/4))*n/100)+n+10;var o=1;return void 0!==r&&(r.plus===t?o=1.1:r.minus===t&&(o=.9)),Math.floor((Math.floor((2*e+i+Math.floor(s/4))*n/100)+5)*o)}t.Stats=k,window.Generations=t.Generations}();
{
"name": "@pkmn/data",
"version": "0.1.2",
"version": "0.1.3",
"main": "build/index.js",

@@ -13,7 +13,7 @@ "types": "build/index.d.ts",

"dependencies": {
"@pkmn/dex-types": "^0.1.2"
"@pkmn/dex-types": "^0.1.3"
},
"devDependencies": {
"@pkmn/dex": "^0.1.2",
"@pkmn/sim": "^0.1.2",
"@pkmn/dex": "^0.1.3",
"@pkmn/sim": "^0.1.3",
"@smogon/calc": "^0.4.4"

@@ -20,0 +20,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc