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

tps-ninja

v1.1.11

Published

Generate images from Tak Positional System (TPS) strings

Downloads

9

Readme

TPS Ninja

Install for including in JavaScript project:

npm i --save 'tps-ninja'

or

yarn add 'tps-ninja'

then

import { PTNtoTPS, TPStoPNG, TPStoGIF } from "tps-ninja";

Install for global CLI usage:

npm i -g tps-ninja

OR

Download the project, cd into its directory, then...

npm i && npm link

PTN to TPS

Portable Tak Notation to Tak Positional System

JS Usage:

const tps = PTNtoTPS({ plies, [tps or size], [...options] });

Required options are plies and either tps or size.

Examples:

PTNtoTPS({ tps: "x5/x5/x5/x5/2,x4 2 1", plies: ["a5", "b5", "c5"] });
// Returns "1,1,2,x2/x5/x5/x5/2,x4 1 3"
PTNtoTPS({ size: 6, plies: ["a6", "b6", "c6"], opening: "no-swap" });
// Returns "1,2,1,x3/x6/x6/x6/x6/x6 2 2"

CLI Usage:

PTNtoTPS <TPS|board size> [OPTION=VALUE ...] <ply1> [<ply2> ...]

Examples:

$ PTNtoTPS "x5/x5/x5/x5/2,x4 2 1" a5 b5 c5
> 1,1,2,x2/x5/x5/x5/2,x4 1 3
$ PTNtoTPS 6 opening=no-swap a6 b6 c6
> 1,2,1,x3/x6/x6/x6/x6/x6 2 2

Options:

opening        [swap|no-swap] Opening variations
caps           Override number of cap stones for both players
flats          Override number of flat stones for both players
caps1          Override number of cap stones for Player 1
flats1         Override number of flat stones for Player 1
caps2          Override number of cap stones for Player 2
flats2         Override number of flat stones for Player 2

TPS to PNG

Tak Positional System to Portable Network Graphics

JS Usage:

const canvas = TPStoPNG(args, (streamTo = null));

The args argument is a map of options, of which size or tps are required.

If streamTo is defined, the image will be piped to the specified write stream. Otherwise, in a node environment, it will be output to ./takboard.png. The canvas is returned either way.

The canvas returned has the following additional proprties:

  • ctx: Canvas context
  • isGameEnd: Boolean denoting whether the game is in a finished state
  • linenum: Integer denoting current move number
  • player: Integer (1 or 2) denoting current player
  • tps: TPS string of current board state
  • id: String denoting either the game result (if isGameEnd) or current TPS

### CLI Usage:

```bash
TPStoPNG <TPS|board size> [OPTION=VALUE ...]

Examples:

Example 1:

TPStoPNG({
  tps: "1,1,12,x2/x5/x5/x5/2,x4 1 4",
  komi: 1,
  imageSize: "sm",
  name: "example1",
});

OR

$ TPStoPNG "1,1,12,x2/x5/x5/x5/2,x4 1 4" komi=1 imageSize=sm name=example1

Example 1

Output: example1.png

Example 2:

TPStoPNG({
  size: 6,
  opening: "no-swap",
  ply: "a6",
  imageSize: "sm",
  theme: "zen",
  bgAlpha: 0,
  name: "example2",
});

OR

$ TPStoPNG 6 opening=no-swap ply=a6 imageSize=sm theme=zen bgAlpha=0 name=example2

Example 2

Output: example2.png

Options:

theme          [ID|JSON] Theme
imageSize      [xs|sm|md|lg|xl] Image size
textSize       [xs|sm|md|lg|xl] Text size
bgAlpha        [0, 1] Background opacity
hlSquares      [true|false] Highlight last ply's squares
axisLabels     [true|false] Show board coordinate labels
turnIndicator  [true|false] Show turn indicator and player names
flatCounts     [true|false] Show flat counts
stackCounts    [true|false] Show stack counts
moveNumber     [true|false|<number>] Show current move number
evalText       [true|false] Show current ply eval notation
komi           [half-integer] Bonus points awarded to Player 2
opening        [swap|no-swap] Opening variations
showRoads      [true|false] Show road connections
unplayedPieces [true|false] Show unplayed pieces
padding        [true|false] Pad the image
highlighter    [JSON] Square coordinates mapped to color, overrides highlight

name           Filename of exported PNG, defaults to 'takboard.png'
player1        Name of Player 1
player2        Name of Player 2
hl             PTN of a ply whose affected squares will be highlighted
ply            PTN of a ply to be executed
plies          Space- or comma-separated string of plies to be executed
caps           Override number of cap stones for both players
flats          Override number of flat stones for both players
caps1          Override number of cap stones for Player 1
flats1         Override number of flat stones for Player 1
caps2          Override number of cap stones for Player 2
flats2         Override number of flat stones for Player 2

TPS to GIF

Tak Positional System to Graphics Interchange Format

JS Usage:

const stream = TPStoGIF(args, (streamTo = null));

The args argument is a map of options, of which size or tps are required.

If streamTo is defined, the image will be piped to the specified write stream. Otherwise, in a node environment, it will be output to ./takboard.gif. The read stream is returned either way.

CLI Usage:

TPStoGIF <TPS|board size> [OPTION=VALUE ...]

Examples:

TPStoGIF({
  size: 3,
  plies: ["a1", "b1", "b2", "b3", "c2", "b3-", "b3", "2b2-", "c1", "c3", "b2"],
  theme: "discord",
  imageSize: "sm",
  name: "example3",
});

OR

$ TPStoGIF 3 plies="a1 b1 b2 b3 c2 b3- b3 2b2- c1 c3 b2" theme=discord imageSize=sm name=example3

Example 1

Output: example3.gif

Options:

delay          [integer] Milliseconds between frames (default 1000)
theme          [ID|JSON] Theme
imageSize      [xs|sm|md|lg|xl] Image size
textSize       [xs|sm|md|lg|xl] Text size
transparent    [true|false] Transparent background
hlSquares      [true|false] Highlight last ply's squares
axisLabels     [true|false] Show board coordinate labels
turnIndicator  [true|false] Show turn indicator and player names
flatCounts     [true|false] Show flat counts
stackCounts    [true|false] Show stack counts
moveNumber     [true|false|<number>] Show current move number
evalText       [true|false] Show current ply eval notation
komi           [half-integer] Bonus points awarded to Player 2
opening        [swap|no-swap] Opening variations
showRoads      [true|false] Show road connections
unplayedPieces [true|false] Show unplayed pieces
padding        [true|false] Pad the image
highlighter    [JSON] Square coordinates mapped to color, overrides highlight

name           Filename of exported GIF, defaults to 'takboard.gif'
player1        Name of Player 1
player2        Name of Player 2
hl             PTN of a ply whose affected squares will be highlighted
ply            PTN of a ply to be executed
plies          Space- or comma-separated string of plies to be executed
caps           Override number of cap stones for both players
flats          Override number of flat stones for both players
caps1          Override number of cap stones for Player 1
flats1         Override number of flat stones for Player 1
caps2          Override number of cap stones for Player 2
flats2         Override number of flat stones for Player 2