npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pkmn/view

v0.6.24

Published

Library for building Pokémon Showdown client UIs

Downloads

238

Readme

@pkmn/view

Test Status License npm version

A library for building Pokémon Showdown client UIs.

Installation

$ npm install @pkmn/view

Usage

@pkmn/view provides a collection of view-related helpers and wrappers which build upon the @pkmn/client and extend its functionality in ways which are relevant for building client UIs.

This package is expected to grow in scope, as several primitives have yet to be completed (eg. AnimatedBattle). Currently, this package offers a LogFormatter for pretty-printing the battle protocol and a ChoiceBuilder helper to make it easier for humans to construct responses.

LogFormatter

The LogFormatter pretty-prints Pokémon Showdown's battle protocol, either as marked up text with formatText or as HTML with formatHTML (see the UI integration test for an example of the latter). The formatter can format the text from the perspective of either side.

import {Dex} from '@pkmn/dex';
import {Generations} from ('@pkmn/data');
import {Battle} from '@pkmn/client';
import {Protocol} from '@pkmn/protocol';
import {LogFormatter} from '@pkmn/view';

const gens = new Generations(Dex);
const battle = new Battle(gens);
const formatter = new LogFormatter(0 /* perspective */, battle);

for (const {args, kwArgs} of Protocol.parse(chunk)) {
  // NOTE: must come *before* handler
  const formatted = formatter.formatText(args, kwArgs);
  if (formatted) process.stdout.write(formatted);
  battle.add(args, kwArgs);
}

If the LogFormatter is used by itself the output will be less detailed and accurated, as it requires certain state about the battle that is more difficult to track to comphrensively display the proper output for every scenario. Instead, the LogFormatter can be instantiated with a 'Tracker' which handles tracking the full state, though importantly, LogFormatter operates on the pre-updated state and thus must be called before its Tracker. @pkmn/client's Battle is currently the only implementation of a Tracker.

The format-battle script productionizes the above example and is comparable to the parse test script in smogon/pokemon-showdown-client, though will return subtly different results because format-battle leverages the full Battle state (via the second parameter to the LogFormatter).

ChoiceBuilder

ChoiceBuilder provides a way to incrementally build up a player's response to a |request| message. It provides features such as filling in pass choices where appropriate, guarding against the wrong sorts of responses being issued for the various request types, and convenience helpers to allow for flexibly specifying choices in a more human-friendly and intuitive way.

import {ChoiceBuilder} from '@pkmn/view';
import {Protocol} from '@pkmn/protocol';

const request = Protocol.parseRequest(str);
const builder = new ChoiceBuilder(request);
builder.addChoice('switch Gengar');
builder.addChoice('move 3');
const choice = builder.toString();

Browser

The recommended way of using @pkmn/view in a web browser is to configure your bundler (Webpack, Rollup, Parcel, etc) to minimize it and package it with the rest of your application.

License

This package is distributed under the terms of the MIT License. Substantial amounts of the code have been derived from the portions of the Pokémon Showdown client which are distributed under the MIT License.