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.0.1 to 0.0.3

pnpm-debug.log

39

build/index.d.ts

@@ -1,7 +0,9 @@

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

@@ -21,3 +23,4 @@ [Symbol.iterator](): Generator<Generation, void, unknown>;

readonly dex: Dex;
constructor(dex: Dex);
private readonly exists;
constructor(dex: Dex, exists: ExistsFn);
get num(): GenerationNum;

@@ -27,3 +30,4 @@ }

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

@@ -34,3 +38,4 @@ [Symbol.iterator](): Generator<import("@pkmn/dex-types").Ability, void, unknown>;

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

@@ -41,3 +46,4 @@ [Symbol.iterator](): Generator<import("@pkmn/dex-types").Item, void, unknown>;

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

@@ -49,3 +55,4 @@ [Symbol.iterator](): Generator<import("@pkmn/dex-types").Move, void, unknown>;

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

@@ -88,2 +95,4 @@ [Symbol.iterator](): Generator<Specie, void, unknown>;

readonly otherFormes?: SpeciesName[];
readonly formeOrder?: SpeciesName[];
readonly formes?: SpeciesName[];
readonly genderRatio: {

@@ -111,9 +120,11 @@ M: number;

private static readonly EXCLUDE;
constructor(dex: Dex, species: DexSpecies);
constructor(dex: Dex, exists: ExistsFn, species: DexSpecies);
hasAbility(ability: string): boolean;
get formeNum(): number;
}
export declare class Effects {
private readonly dex;
constructor(dex: Dex);
get(name: string): PureEffect | import("@pkmn/dex-types").Ability | import("@pkmn/dex-types").Item | import("@pkmn/dex-types").Move | undefined;
private readonly exists;
constructor(dex: Dex, exists: ExistsFn);
get(name: string): import("@pkmn/dex-types").Ability | import("@pkmn/dex-types").Item | import("@pkmn/dex-types").Move | PureEffect | undefined;
}

@@ -184,5 +195,5 @@ export declare class Natures {

[Symbol.iterator](): IterableIterator<StatName>;
itod(iv: number): number;
dtoi(dv: number): number;
toDV(iv: number): number;
toIV(dv: number): number;
}
export {};
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, PokemonSet, AbilityName, ItemName, MoveName, SpeciesName, FormeName, EffectType, DataKind, Effect, EffectData, HitEffect, SecondaryEffect, PureEffectData, AbilityData, ItemData, MoveData, SpeciesData, MoveSource, EventInfoData, LearnsetData, TypeData, NatureData, BasicEffect, PureEffect, Ability, Item, Move, EventInfo, Learnset, Nature, GenID, Dex, } from '@pkmn/dex-types';

@@ -15,7 +15,8 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
function exists(e) {
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')
return false;
return !('tier' in e && ['Illegal', 'Unreleased'].includes(e.tier));
}
};
function assignWithout(a, b, exclude) {

@@ -38,4 +39,5 @@ for (const key in b) {

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

@@ -45,3 +47,3 @@ get(gen) {

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

@@ -56,12 +58,13 @@ *[Symbol.iterator]() {

class Generation {
constructor(dex) {
constructor(dex, exists) {
this.dex = dex;
this.abilities = new Abilities(this.dex);
this.items = new Items(this.dex);
this.moves = new Moves(this.dex);
this.species = new Species(this.dex);
this.exists = exists;
this.abilities = new Abilities(this.dex, this.exists);
this.items = new Items(this.dex, this.exists);
this.moves = new Moves(this.dex, this.exists);
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.effects = new Effects(this.dex);
this.effects = new Effects(this.dex, this.exists);
this.stats = new Stats(this.dex);

@@ -75,8 +78,9 @@ }

class Abilities {
constructor(dex) {
constructor(dex, exists) {
this.dex = dex;
this.exists = exists;
}
get(name) {
const ability = this.dex.getAbility(name);
return exists(ability) ? ability : undefined;
return this.exists(ability) ? ability : undefined;
}

@@ -93,8 +97,9 @@ *[Symbol.iterator]() {

class Items {
constructor(dex) {
constructor(dex, exists) {
this.dex = dex;
this.exists = exists;
}
get(name) {
const item = this.dex.getItem(name);
return exists(item) ? item : undefined;
return this.exists(item) ? item : undefined;
}

@@ -111,8 +116,9 @@ *[Symbol.iterator]() {

class Moves {
constructor(dex) {
constructor(dex, exists) {
this.dex = dex;
this.exists = exists;
}
get(name) {
const move = this.dex.getMove(name);
return exists(move) ? move : undefined;
return this.exists(move) ? move : undefined;
}

@@ -129,9 +135,10 @@ *[Symbol.iterator]() {

class Species {
constructor(dex) {
constructor(dex, exists) {
this.cache = Object.create(null);
this.dex = dex;
this.exists = exists;
}
get(name) {
const species = this.dex.getSpecies(name);
if (!exists(species))
if (!this.exists(species))
return undefined;

@@ -142,3 +149,3 @@ const id = species.speciesid || species.id; // FIXME Event-only ability hack

return cached;
return (this.cache[id] = new Specie(this.dex, species));
return (this.cache[id] = new Specie(this.dex, this.exists, species));
}

@@ -154,48 +161,61 @@ *[Symbol.iterator]() {

exports.Species = Species;
class Specie {
constructor(dex, species) {
var _a, _b, _c, _d, _e, _f;
assignWithout(this, species, Specie.EXCLUDE);
this.dex = dex;
if (this.dex.gen >= 2) {
this.gender = species.gender;
this.genderRatio = species.genderRatio;
let Specie = /** @class */ (() => {
class Specie {
constructor(dex, exists, species) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
assignWithout(this, species, Specie.EXCLUDE);
this.dex = dex;
if (this.dex.gen >= 2) {
this.gender = species.gender;
this.genderRatio = species.genderRatio;
}
else {
this.genderRatio = { M: 0, F: 0 };
}
this.evos = (_a = species.evos) === null || _a === void 0 ? void 0 : _a.filter(s => exists(this.dex.getSpecies(s)));
this.nfe = !!((_b = this.evos) === null || _b === void 0 ? void 0 : _b.length);
if (!this.nfe)
this.evos = undefined;
this.cosmeticFormes = (_c = species.cosmeticFormes) === null || _c === void 0 ? void 0 : _c.filter(s => exists(this.dex.getSpecies(s)));
if (!((_d = this.cosmeticFormes) === null || _d === void 0 ? void 0 : _d.length))
this.cosmeticFormes = undefined;
this.otherFormes = (_e = species.otherFormes) === null || _e === void 0 ? void 0 : _e.filter(s => exists(this.dex.getSpecies(s)));
if (!((_f = this.otherFormes) === null || _f === void 0 ? void 0 : _f.length))
this.otherFormes = undefined;
this.formeOrder = (_g = species.formeOrder) === null || _g === void 0 ? void 0 : _g.filter(s => exists(this.dex.getSpecies(s)));
if (!((_h = this.formeOrder) === null || _h === void 0 ? void 0 : _h.length))
this.formeOrder = undefined;
this.formes = (_j = this.formeOrder) === null || _j === void 0 ? void 0 : _j.filter(s => !this.dex.getSpecies(s).isGigantamax);
this.prevo =
species.prevo && exists(this.dex.getSpecies(species.prevo)) ? species.prevo : undefined;
}
else {
this.genderRatio = { M: 0, F: 0 };
hasAbility(ability) {
return this.dex.hasAbility(this, ability);
}
this.evos = (_a = species.evos) === null || _a === void 0 ? void 0 : _a.filter(s => exists(this.dex.getSpecies(s)));
this.nfe = !!((_b = this.evos) === null || _b === void 0 ? void 0 : _b.length);
if (!this.nfe)
this.evos = undefined;
this.cosmeticFormes = (_c = species.cosmeticFormes) === null || _c === void 0 ? void 0 : _c.filter(s => exists(this.dex.getSpecies(s)));
if (!((_d = this.cosmeticFormes) === null || _d === void 0 ? void 0 : _d.length))
this.cosmeticFormes = undefined;
this.otherFormes = (_e = species.otherFormes) === null || _e === void 0 ? void 0 : _e.filter(s => exists(this.dex.getSpecies(s)));
if (!((_f = this.otherFormes) === null || _f === void 0 ? void 0 : _f.length))
this.otherFormes = undefined;
this.prevo =
species.prevo && exists(this.dex.getSpecies(species.prevo)) ? species.prevo : undefined;
get formeNum() {
return (this.baseSpecies === this.name
? this.formeOrder ? this.formeOrder.findIndex(name => name === this.name) : 0
: this.dex.getSpecies(this.baseSpecies).formeOrder.findIndex(name => name === (this.isGigantamax ? this.baseSpecies : this.name)));
}
}
hasAbility(ability) {
return this.dex.hasAbility(this, ability);
}
}
Specie.EXCLUDE = new Set([
'evos',
'gender',
'genderRatio',
'cosmeticFormes',
'nfe',
'otherFormes',
'prevo',
]);
return Specie;
})();
exports.Specie = Specie;
Specie.EXCLUDE = new Set([
'evos',
'gender',
'genderRatio',
'cosmeticFormes',
'nfe',
'otherFormes',
'prevo',
]);
class Effects {
constructor(dex) {
constructor(dex, exists) {
this.dex = dex;
this.exists = exists;
}
get(name) {
const effect = this.dex.getEffect(name);
return exists(effect) ? effect : undefined;
return this.exists(effect) ? effect : undefined;
}

@@ -352,3 +372,3 @@ }

return this.dex.gen < 3
? calcRBY(stat, base, this.itod(iv), ev, level)
? calcRBY(stat, base, this.toDV(iv), ev, level)
: calcADV(stat, base, iv, ev, level, nature);

@@ -375,6 +395,6 @@ }

getHPDV(ivs) {
return ((this.itod(ivs.atk === undefined ? 31 : ivs.atk) % 2) * 8 +
(this.itod(ivs.def === undefined ? 31 : ivs.def) % 2) * 4 +
(this.itod(ivs.spe === undefined ? 31 : ivs.spe) % 2) * 2 +
(this.itod(ivs.spa === undefined ? 31 : ivs.spa) % 2));
return ((this.toDV(ivs.atk === undefined ? 31 : ivs.atk) % 2) * 8 +
(this.toDV(ivs.def === undefined ? 31 : ivs.def) % 2) * 4 +
(this.toDV(ivs.spe === undefined ? 31 : ivs.spe) % 2) * 2 +
(this.toDV(ivs.spa === undefined ? 31 : ivs.spa) % 2));
}

@@ -386,6 +406,6 @@ *[Symbol.iterator]() {

}
itod(iv) {
toDV(iv) {
return Math.floor(iv / 2);
}
dtoi(dv) {
toIV(dv) {
return dv * 2 + 1;

@@ -392,0 +412,0 @@ }

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;

@@ -24,2 +36,3 @@ };

const Gen = (num) => gens.get(num);
// FIXME test exists override!
describe('Abilities', () => {

@@ -262,2 +275,18 @@ it('#get', () => {

});
test('formeNum', () => {
for (const gen of gens) {
for (const species of gen.species) {
expect(species.formeNum).toBeGreaterThanOrEqual(0);
}
}
expect(Gen(1).species.get('Pikachu').formeNum).toBe(0);
expect(Gen(6).species.get('Pikachu-Libre').formeNum).toBe(5);
expect(Gen(7).species.get('Pikachu-Kalos').formeNum).toBe(5);
expect(Gen(6).species.get('Vivillon').formeNum).toBe(6);
expect(Gen(6).species.get('Vivillon-Meadow').formeNum).toBe(6);
expect(Gen(6).species.get('Vivillon-Icy-Snow').formeNum).toBe(0);
expect(Gen(7).species.get('Minior-Meteor').formeNum).toBe(0);
expect(Gen(7).species.get('Minior').formeNum).toBe(7);
expect(Gen(7).species.get('Minior-Violet').formeNum).toBe(13);
});
test('fields', () => {

@@ -454,10 +483,10 @@ expect(Gen(7).species.get('Clefable').types).toEqual(['Fairy']);

const stats = Gen(8).stats;
expect(stats.getHPDV({ spa: stats.dtoi(15), spe: stats.dtoi(15) })).toBe(15);
expect(stats.getHPDV({ spa: stats.toIV(15), spe: stats.toIV(15) })).toBe(15);
expect(stats.getHPDV({
atk: stats.dtoi(5),
def: stats.dtoi(15),
spa: stats.dtoi(13),
spe: stats.dtoi(13),
atk: stats.toIV(5),
def: stats.toIV(15),
spa: stats.toIV(13),
spe: stats.toIV(13),
})).toBe(15);
expect(stats.getHPDV({ def: stats.dtoi(3), spa: stats.dtoi(11), spe: stats.dtoi(10) }))
expect(stats.getHPDV({ def: stats.toIV(3), spa: stats.toIV(11), spe: stats.toIV(10) }))
.toBe(13);

@@ -464,0 +493,0 @@ });

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

var _this=this;function _defineProperties(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}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,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,s=n.apply(t,i||[]),o=[];return r={},a("next"),a("throw"),a("return"),r[Symbol.asyncIterator]=function(){return this},r;function a(t){s[t]&&(r[t]=function(e){return new Promise((function(i,n){o.push([t,e,i,n])>1||h(t,e)}))})}function h(t,i){try{(n=s[t](i)).value instanceof e?Promise.resolve(n.value.v).then(d,c):u(o[0][2],n)}catch(t){u(o[0][3],t)}var n}function d(t){h("next",t)}function c(t){h("throw",t)}function u(t,e){t(e),o.shift(),o.length&&h(o[0][0],o[0][1])}};function n(t){return!(!t.exists||t.isNonstandard||"noability"===t.id)&&!("tier"in t&&["Illegal","Unreleased"].includes(t.tier))}function r(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=r;var s=Object.create(null),o=function(){function t(t){this.dex=t}var e=t.prototype;return e.get=function(t){return s[t]?s[t]:s[t]=new a(this.dex.forGen(t))},e[Symbol.iterator]=function*(){for(var t=1;t<=8;t++)yield this.get(t)},t}();t.Generations=o;var a=function(){function t(t){this.dex=t,this.abilities=new h(this.dex),this.items=new d(this.dex),this.moves=new c(this.dex),this.species=new u(this.dex),this.natures=new v(this.dex),this.types=new g(this.dex),this.learnsets=new S(this.dex),this.effects=new p(this.dex),this.stats=new D(this.dex)}return _createClass(t,[{key:"num",get:function(){return this.dex.gen}}]),t}();t.Generation=a;var h=function(){function t(t){this.dex=t}var e=t.prototype;return e.get=function(t){var e=this.dex.getAbility(t);return n(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=h;var d=function(){function t(t){this.dex=t}var e=t.prototype;return e.get=function(t){var e=this.dex.getItem(t);return n(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=d;var c=function(){function t(t){this.dex=t}var e=t.prototype;return e.get=function(t){var e=this.dex.getMove(t);return n(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 u=function(){function t(t){this.cache=Object.create(null),this.dex=t}var e=t.prototype;return e.get=function(t){var e=this.dex.getSpecies(t);if(n(e)){var i=e.speciesid||e.id,r=this.cache[i];return r||(this.cache[i]=new f(this.dex,e))}},e[Symbol.iterator]=function*(){for(var t in this.dex.data.Species){var e=this.get(t);e&&(yield e)}},t}();t.Species=u;var f=function(){function t(e,i){var r,s,o,a,h,d,c=this;!function(t,e,i){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&!i.has(n)&&(t[n]=e[n])}(this,i,t.EXCLUDE),this.dex=e,this.dex.gen>=2?(this.gender=i.gender,this.genderRatio=i.genderRatio):this.genderRatio={M:0,F:0},this.evos=null===(r=i.evos)||void 0===r?void 0:r.filter((function(t){return n(c.dex.getSpecies(t))})),this.nfe=!!(null===(s=this.evos)||void 0===s?void 0:s.length),this.nfe||(this.evos=void 0),this.cosmeticFormes=null===(o=i.cosmeticFormes)||void 0===o?void 0:o.filter((function(t){return n(c.dex.getSpecies(t))})),(null===(a=this.cosmeticFormes)||void 0===a?void 0:a.length)||(this.cosmeticFormes=void 0),this.otherFormes=null===(h=i.otherFormes)||void 0===h?void 0:h.filter((function(t){return n(c.dex.getSpecies(t))})),(null===(d=this.otherFormes)||void 0===d?void 0:d.length)||(this.otherFormes=void 0),this.prevo=i.prevo&&n(this.dex.getSpecies(i.prevo))?i.prevo:void 0}return t.prototype.hasAbility=function(t){return this.dex.hasAbility(this,t)},t}();t.Specie=f,f.EXCLUDE=new Set(["evos","gender","genderRatio","cosmeticFormes","nfe","otherFormes","prevo"]);var p=function(){function t(t){this.dex=t}return t.prototype.get=function(t){var e=this.dex.getEffect(t);return n(e)?e:void 0},t}();t.Effects=p;var v=function(){function t(t){this.dex=t}var e=t.prototype;return e.get=function(t){if(!(this.dex.gen<3)){var e=this.dex.getNature(t);return e.exists?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=v;var l={"-2":.25,"-1":.5,0:1,1:2,2:4},g=function(){function t(t){this.cache=Object.create(null),this.dex=t,this.unknown=new m({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(e.exists){var i=this.cache[e.id];return i||(this.cache[e.id]=new m(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 l[i]},t}();t.Types=g;var y=[1,2,.5,0],x=["Fire","Water","Grass","Electric","Ice","Psychic","Dark","Dragon"],m=function(){function t(t,e,i){for(var n in Object.assign(this,t),this.types=i,this.category="Fairy"===this.name?void 0:x.includes(this.name)?"Special":"Physical",this.effectiveness={"???":1},e.data.Types){var r=n;this.effectiveness[r]=y[e.data.Types[r].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=m;var S=function(){function t(t){this.dex=t}var n=t.prototype;return n.get=async function(t){var e=await this.dex.getLearnset(r(t));return e.exists?e:void 0},n[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=S;var w=["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"},k={hp:["HP","HP"],atk:["Atk","Attack"],def:["Def","Defense"],spa:["SpA","Special Attack"],spd:["SpD","Special Defense"],spe:["Spd","Speed"],spc:["Spc","Special"]},D=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,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:252,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:100,s=arguments.length>5?arguments[5]:void 0;return this.dex.gen<3?P(t,e,this.itod(i),n,r):A(t,e,i,n,r,s)},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"),k[i][+e])},e.fill=function(t,e){for(var i=0;i<w.length;i++){var n=w[i];n in t||(t[n]=e)}return t},e.getHPDV=function(t){return this.itod(void 0===t.atk?31:t.atk)%2*8+this.itod(void 0===t.def?31:t.def)%2*4+this.itod(void 0===t.spe?31:t.spe)%2*2+this.itod(void 0===t.spa?31:t.spa)%2},e[Symbol.iterator]=function*(){for(var t=0;t<w.length;t++){var e=w[t];yield e}},e.itod=function(t){return Math.floor(t/2)},e.dtoi=function(t){return 2*t+1},t}();function P(t,e,i,n,r){return"hp"===t?Math.floor((2*(e+i)+63)*r/100)+r+10:Math.floor((2*(e+i)+63)*r/100)+5}function A(t,e,i,n,r,s){if("hp"===t)return 1===e?e:Math.floor((2*e+i+Math.floor(n/4))*r/100)+r+10;var o=1;return void 0!==s&&(s.plus===t?o=1.1:s.minus===t&&(o=.9)),Math.floor((Math.floor((2*e+i+Math.floor(n/4))*r/100)+5)*o)}t.Stats=D,window.Generations=t.Generations}();
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 p(this.dex),this.types=new x(this.dex),this.learnsets=new S(this.dex),this.effects=new v(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(){var e=function(){function e(t,i,n){var s,r,o,a,h,d,c,f,u,v=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(v.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(v.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(v.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(v.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!v.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}();return e.EXCLUDE=new Set(["evos","gender","genderRatio","cosmeticFormes","nfe","otherFormes","prevo"]),e}();e.Specie=u;var v=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=v;var p=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=p;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}();

@@ -1,3 +0,2 @@

import {GenerationNum, StatsTable} from '@pkmn/types';
import {Dex as DexT, ItemName} from '@pkmn/dex-types';
import {GenerationNum, StatsTable, Dex as DexT, ItemName} from '@pkmn/dex-types';
import {Generations} from './index';

@@ -22,2 +21,4 @@

// FIXME test exists override!
describe('Abilities', () => {

@@ -285,2 +286,19 @@ it('#get', () => {

test('formeNum', () => {
for (const gen of gens) {
for (const species of gen.species) {
expect(species.formeNum).toBeGreaterThanOrEqual(0);
}
}
expect(Gen(1).species.get('Pikachu')!.formeNum).toBe(0);
expect(Gen(6).species.get('Pikachu-Libre')!.formeNum).toBe(5);
expect(Gen(7).species.get('Pikachu-Kalos')!.formeNum).toBe(5);
expect(Gen(6).species.get('Vivillon')!.formeNum).toBe(6);
expect(Gen(6).species.get('Vivillon-Meadow')!.formeNum).toBe(6);
expect(Gen(6).species.get('Vivillon-Icy-Snow')!.formeNum).toBe(0);
expect(Gen(7).species.get('Minior-Meteor')!.formeNum).toBe(0);
expect(Gen(7).species.get('Minior')!.formeNum).toBe(7);
expect(Gen(7).species.get('Minior-Violet')!.formeNum).toBe(13);
});
test('fields', () => {

@@ -497,12 +515,12 @@ expect(Gen(7).species.get('Clefable')!.types).toEqual(['Fairy']);

const stats = Gen(8).stats;
expect(stats.getHPDV({spa: stats.dtoi(15), spe: stats.dtoi(15)})).toBe(15);
expect(stats.getHPDV({spa: stats.toIV(15), spe: stats.toIV(15)})).toBe(15);
expect(
stats.getHPDV({
atk: stats.dtoi(5),
def: stats.dtoi(15),
spa: stats.dtoi(13),
spe: stats.dtoi(13),
atk: stats.toIV(5),
def: stats.toIV(15),
spa: stats.toIV(13),
spe: stats.toIV(13),
})
).toBe(15);
expect(stats.getHPDV({def: stats.dtoi(3), spa: stats.dtoi(11), spe: stats.dtoi(10)}))
expect(stats.getHPDV({def: stats.toIV(3), spa: stats.toIV(11), spe: stats.toIV(10)}))
.toBe(13);

@@ -509,0 +527,0 @@ });

import {
AbilityName,
Dex,
Effect,
EggGroup,
EvoType,
FormeName,
GenderName,
GenerationNum,
ID,
ItemName,
MoveCategory,
Nonstandard,
StatName,
StatsTable,
TypeName,
} from '@pkmn/types';
import {
AbilityName,
Dex,
Effect,
FormeName,
ItemName,
MoveName,
Nature,
Nonstandard,
PureEffect,

@@ -26,10 +20,15 @@ Species as DexSpecies,

SpeciesName,
StatName,
StatsTable,
Type as DexType,
TypeName,
} from '@pkmn/dex-types';
function exists(e: Effect | DexSpecies) {
const DEFAULT_EXISTS = (e: Effect | DexSpecies) => {
if (!e.exists || e.isNonstandard || e.id === 'noability') return false;
return !('tier' in e && ['Illegal', 'Unreleased'].includes(e.tier));
}
};
type ExistsFn = typeof DEFAULT_EXISTS;
function assignWithout(a: {[key: string]: any}, b: {[key: string]: any}, exclude: Set<string>) {

@@ -53,4 +52,7 @@ for (const key in b) {

private readonly dex: Dex;
constructor(dex: Dex) {
private readonly exists: ExistsFn;
constructor(dex: Dex, exists = DEFAULT_EXISTS) {
this.dex = dex;
this.exists = exists;
}

@@ -60,3 +62,3 @@

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

@@ -84,13 +86,16 @@

constructor(dex: Dex) {
private readonly exists: ExistsFn;
constructor(dex: Dex, exists: ExistsFn) {
this.dex = dex;
this.exists = exists;
this.abilities = new Abilities(this.dex);
this.items = new Items(this.dex);
this.moves = new Moves(this.dex);
this.species = new Species(this.dex);
this.abilities = new Abilities(this.dex, this.exists);
this.items = new Items(this.dex, this.exists);
this.moves = new Moves(this.dex, this.exists);
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.effects = new Effects(this.dex);
this.effects = new Effects(this.dex, this.exists);
this.stats = new Stats(this.dex);

@@ -106,4 +111,7 @@ }

private readonly dex: Dex;
constructor(dex: Dex) {
private readonly exists: ExistsFn;
constructor(dex: Dex, exists: ExistsFn) {
this.dex = dex;
this.exists = exists;
}

@@ -113,3 +121,3 @@

const ability = this.dex.getAbility(name);
return exists(ability) ? ability : undefined;
return this.exists(ability) ? ability : undefined;
}

@@ -127,4 +135,7 @@

private readonly dex: Dex;
constructor(dex: Dex) {
private readonly exists: ExistsFn;
constructor(dex: Dex, exists: ExistsFn) {
this.dex = dex;
this.exists = exists;
}

@@ -134,3 +145,3 @@

const item = this.dex.getItem(name);
return exists(item) ? item : undefined;
return this.exists(item) ? item : undefined;
}

@@ -148,4 +159,7 @@

private readonly dex: Dex;
constructor(dex: Dex) {
private readonly exists: ExistsFn;
constructor(dex: Dex, exists: ExistsFn) {
this.dex = dex;
this.exists = exists;
}

@@ -155,3 +169,3 @@

const move = this.dex.getMove(name);
return exists(move) ? move : undefined;
return this.exists(move) ? move : undefined;
}

@@ -171,4 +185,7 @@

private readonly dex: Dex;
constructor(dex: Dex) {
private readonly exists: ExistsFn;
constructor(dex: Dex, exists: ExistsFn) {
this.dex = dex;
this.exists = exists;
}

@@ -178,7 +195,7 @@

const species = this.dex.getSpecies(name);
if (!exists(species)) return undefined;
if (!this.exists(species)) return undefined;
const id = (species as any).speciesid || species.id; // FIXME Event-only ability hack
const cached = this.cache[id];
if (cached) return cached;
return (this.cache[id] = new Specie(this.dex, species));
return (this.cache[id] = new Specie(this.dex, this.exists, species));
}

@@ -230,2 +247,4 @@

readonly otherFormes?: SpeciesName[];
readonly formeOrder?: SpeciesName[];
readonly formes?: SpeciesName[];
readonly genderRatio: { M: number; F: number };

@@ -261,3 +280,3 @@ readonly isMega?: boolean;

constructor(dex: Dex, species: DexSpecies) {
constructor(dex: Dex, exists: ExistsFn, species: DexSpecies) {
assignWithout(this, species, Specie.EXCLUDE);

@@ -278,2 +297,5 @@ this.dex = dex;

if (!this.otherFormes?.length) this.otherFormes = undefined;
this.formeOrder = species.formeOrder?.filter(s => exists(this.dex.getSpecies(s)));
if (!this.formeOrder?.length) this.formeOrder = undefined;
this.formes = this.formeOrder?.filter(s => !this.dex.getSpecies(s).isGigantamax);
this.prevo =

@@ -286,2 +308,10 @@ species.prevo && exists(this.dex.getSpecies(species.prevo)) ? species.prevo : undefined;

}
get formeNum() {
return (this.baseSpecies === this.name
? this.formeOrder ? this.formeOrder.findIndex(name => name === this.name) : 0
: this.dex.getSpecies(this.baseSpecies).formeOrder!.findIndex(
name => name === (this.isGigantamax ? this.baseSpecies : this.name)
));
}
}

@@ -291,4 +321,7 @@

private readonly dex: Dex;
constructor(dex: Dex) {
private readonly exists: ExistsFn;
constructor(dex: Dex, exists: ExistsFn) {
this.dex = dex;
this.exists = exists;
}

@@ -298,3 +331,3 @@

const effect = this.dex.getEffect(name);
return exists(effect) ? effect : undefined;
return this.exists(effect) ? effect : undefined;
}

@@ -305,2 +338,3 @@ }

private readonly dex: Dex;
constructor(dex: Dex) {

@@ -486,3 +520,3 @@ this.dex = dex;

return this.dex.gen < 3
? calcRBY(stat, base, this.itod(iv), ev, level)
? calcRBY(stat, base, this.toDV(iv), ev, level)
: calcADV(stat, base, iv, ev, level, nature);

@@ -511,6 +545,6 @@ }

return (
(this.itod(ivs.atk === undefined ? 31 : ivs.atk) % 2) * 8 +
(this.itod(ivs.def === undefined ? 31 : ivs.def) % 2) * 4 +
(this.itod(ivs.spe === undefined ? 31 : ivs.spe) % 2) * 2 +
(this.itod(ivs.spa === undefined ? 31 : ivs.spa) % 2)
(this.toDV(ivs.atk === undefined ? 31 : ivs.atk) % 2) * 8 +
(this.toDV(ivs.def === undefined ? 31 : ivs.def) % 2) * 4 +
(this.toDV(ivs.spe === undefined ? 31 : ivs.spe) % 2) * 2 +
(this.toDV(ivs.spa === undefined ? 31 : ivs.spa) % 2)
);

@@ -525,7 +559,7 @@ }

itod(iv: number): number {
toDV(iv: number): number {
return Math.floor(iv / 2);
}
dtoi(dv: number): number {
toIV(dv: number): number {
return dv * 2 + 1;

@@ -568,1 +602,62 @@ }

}
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,
PokemonSet,
AbilityName,
ItemName,
MoveName,
SpeciesName,
FormeName,
EffectType,
DataKind,
Effect,
EffectData,
HitEffect,
SecondaryEffect,
PureEffectData,
AbilityData,
ItemData,
MoveData,
SpeciesData,
MoveSource,
EventInfoData,
LearnsetData,
TypeData,
NatureData,
BasicEffect,
PureEffect,
Ability,
Item,
Move,
// Species,
EventInfo,
Learnset,
// Type,
Nature,
GenID,
Dex,
} from '@pkmn/dex-types';
{
"name": "@pkmn/data",
"version": "0.0.1",
"version": "0.0.3",
"main": "build/index.js",

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

"repository": "github:pkmn/ps",
"author": "Kirk Scheibelhut <pre@pkmn.cc>",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pkmn/dex-types": "^0.0.1",
"@pkmn/types": "^0.1.0"
"@pkmn/dex-types": "^0.0.3"
},
"devDependencies": {
"@pkmn/dex": "^0.0.1",
"@pkmn/eslint-config": "^0.2.3",
"@pkmn/sim": "^0.0.2",
"@smogon/calc": "^0.3.0",
"@types/jest": "^25.2.1",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.9.0",
"eslint": "^6.8.0",
"jest": "^26.0.1",
"ts-jest": "^25.4.0",
"typescript": "^3.8.3"
"@pkmn/dex": "^0.0.3",
"@pkmn/sim": "^0.0.3",
"@smogon/calc": "^0.3.0"
},

@@ -36,3 +28,2 @@ "scripts": {

"test": "jest",
"prepare": "npm run build",
"pretest": "npm run build",

@@ -39,0 +30,0 @@ "posttest": "npm run lint"

@@ -1,6 +0,7 @@

# @pkmn/data
# `@pkmn/data`
[![npm version](https://img.shields.io/npm/v/@pkmn/data.svg)](https://www.npmjs.com/package/@pkmn/data)&nbsp;
![Test Status](https://github.com/pkmn/ps/workflows/Tests/badge.svg)
[![npm version](https://img.shields.io/npm/v/@pkmn/data.svg)](https://www.npmjs.com/package/@pkmn/data)
A higher level data API wrapper compatible with [`@pkmn/sim`][2] and [`@pkmn/dex`][11].
A higher level data API wrapper compatible with [`@pkmn/sim`](../sim) and [`@pkmn/dex`](../dex).

@@ -14,3 +15,4 @@ ## Installation

Alternatively, as [detailed below](#browser), if you are using `@pkmn/data` in the browser and want
a convenient way to get started, simply depend on a transpiled and minified version via [unpkg][5]:
a convenient way to get started, simply depend on a transpiled and minified version via
[unpkg](https://unpkg.com/):

@@ -22,3 +24,3 @@ ```html

*In this example, [`@pkmn/dex`][11] is included as well, because `@pkmn/data` requires a `Dex`
*In this example, [`@pkmn/dex`](../dex) is included as well, because `@pkmn/data` requires a `Dex`
implementation to be useful.*

@@ -28,6 +30,6 @@

This package can be used to wrap an implementation of the Pokémon Showdown [`@pkmn/dex-types`][12]
to provide an alternative data layer API. This package is not generally useful without a runtime
dependency - you must bring your own data layer. **You almost certainly should be using `@pkmn/dex`
instead of `@pkmn/sim` unless you know what you are doing**.
This package can be used to wrap an implementation of the Pokémon Showdown
[`@pkmn/dex-types`](../dex/types) to provide an alternative data layer API. This package is not
generally useful without a runtime dependency - you must bring your own data layer. **You almost
certainly should be using `@pkmn/dex` instead of `@pkmn/sim` unless you know what you are doing**.

@@ -71,6 +73,6 @@ ```ts

are not pruned. For example, Chansey's `prevo` field in Gen 3 will not be `happiny`, but a move from
the same generation may still have its `zMovePower` field populated as it should never be queried in
Gen 3 anyway. This is mostly an artifact of how the Pokémon Showdown `Dex` `Generations` is built on
top of works - for efficiency reasons its only worthwhile to clean up the fields which are actually
relevant to the generation in question.
the same generation may still have its `zMove.basePower` field populated as it should never be
queried in Gen 3 anyway. This is mostly an artifact of how the Pokémon Showdown `Dex` `Generations`
is built on top of works - for efficiency reasons its only worthwhile to clean up the fields which
are actually relevant to the generation in question.

@@ -87,3 +89,3 @@ ```ts

Please see the [unit tests][13] for more comprehensive usage examples.
Please see the [unit tests](index.test.ts) for more comprehensive usage examples.

@@ -93,6 +95,7 @@ ### Browser

The recommended way of using `@pkmn/data` in a web browser is to **configure your bundler**
([Webpack][6], [Rollup][7], [Parcel][8], etc) to minimize it and package it with the rest of your
([Webpack](https://webpack.js.org/), [Rollup](https://rollupjs.org/),
[Parcel](https://parceljs.org/), etc) to minimize it and package it with the rest of your
application. If you do not use a bundler, a convenience `production.min.js` is included in the
package. You simply need to depend on `./node_modules/@pkmn/data/production.min.js` in a `script`
tag (which is what the unpkg shortcut above is doing), after which **`Generations` will be
package. You simply need to depend on `./node_modules/@pkmn/data/build/production.min.js` in a
`script` tag (which is what the unpkg shortcut above is doing), after which **`Generations` will be
accessible as a global.**

@@ -102,27 +105,14 @@

This package is heavily constrained by Pokémon Showdown's data layer - because it simply serves as
a wrapper to the `Dex` it cannot doing anything too ambitious or making suitable optimizations.
As such, this package does **not** attempt to provide the 'ideal' data layer for any and all
Pokémon projects - please see [`@smogon/data`][4] for a project attempting to go after the more
ambitious goal of providing a powerful, type-safe and well thought out API that allows clients to
only depend on the data they need ([design doc][9]).
This package is heavily constrained by Pokémon Showdown's data layer - because it simply serves as a
wrapper to the `Dex` it cannot doing anything too ambitious or making suitable optimizations. As
such, this package does **not** attempt to provide the 'ideal' data layer for any and all Pokémon
projects - please see the [Pokémon Showdown Core design doc](https://pkmn.cc/ps-core-design) which
provides details on a design for the ambitious goal of providing a powerful, type-safe and well
thought out API that allows clients to only depend on the data they need.
## License
This package is distributed under the terms of the [MIT License][1].
Substantial amounts of the code have been derived from the portions of Guangcong
Luo's [Pokémon Showdown client][3] which are distributed under the [MIT License][10].
[1]: https://github.com/pkmn/ps/blob/master/data/LICENSE
[2]: https://github.com/pkmn/ps/blob/master/sim
[3]: https://github.com/smogon/pokemon-showdown-client
[4]: https://github.com/smogon/data
[5]: https://unpkg.com/
[6]: https://webpack.js.org/
[7]: https://rollupjs.org/
[8]: https://parceljs.org/
[9]: https://pkmn.cc/ps-core-design
[10]: https://github.com/smogon/pokemon-showdown-client/blob/master/src/battle.ts#L6
[11]: https://github.com/pkmn/ps/blob/master/dex
[12]: https://github.com/pkmn/ps/blob/master/dex/types/index.d.ts
[13]: https://github.com/pkmn/ps/blob/master/data/index.test.ts
This package is distributed under the terms of the [MIT License](LICENSE). Substantial amounts of
the code have been derived from the portions of the [Pokémon Showdown
client](https://github.com/smogon/pokemon-showdown-client) which are distributed under the [MIT
License](https://github.com/smogon/pokemon-showdown-client/blob/master/src/battle.ts#L6).

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

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