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

smartgame

v0.1.5

Published

Parse SGF (Smart Game Format) files into JavaScript and back again.

Downloads

56

Readme

smartgame Build Status

A node library for parsing SGF format game records into JavaScript and back again. Then use smartgamer to navigate and manipulate those game records.

Installation

For most projects, you'll just want to install smartgame locally and add it to your project's dependencies in package.json:

$ npm install --save smartgame

If you want (for whatever reason) to use smartgame anywhere, you can install it globally.

$ npm install -g smartgame

Usage

var sgf = require('smartgame');
var fs = require('fs');

// Grab an SGF file from somewhere
var example = fs.readFileSync('sgf/example.sgf', { encoding: 'utf8' });

var collection = sgf.parse(example);

// ... use the collection object however you want!

// ... when collection has been modified and you want to save it as an .sgf file
var collectionSGF = sgf.generate(collection);
fs.writeFileSync('new-example.sgf', collectionSGF, { encoding: 'utf8' });

Example JS Game Record

Let's take a very simple SGF file as an example:

(;GM[1]FF[4]CA[UTF-8]SZ[19];B[pd];W[dp];B[pp](;W[dd])(;W[dc];B[ce];W[ed](;B[ch];W[jc])(;B[ci])))

The parse function would turn this into a JS Object that looked like this:

{
	gameTrees: [
		{
			parent: <a reference to the parent object>,
			nodes: [
				{ GM: '1', FF: '4', CA: 'UTF-8', SZ: '19' },
				{ B: 'pd' },
				{ W: 'dp' },
				{ B: 'pp' }
			],
			sequences: [
				{
					parent: <a reference to the parent object>,
					nodes: [
						{ W: 'dd' }
					]
				},
				{
					parent: <a reference to the parent object>,
					nodes: [
						{ W: 'dc' },
						{ B: 'ce' },
						{ W: 'ed' }
					],
					sequences: [
						{
							parent: <a reference to the parent object>,
							nodes: [
								{ B: 'ch' },
								{ W: 'jc' }
							]
						},
						{
							parent: <a reference to the parent object>,
							nodes: [
								{ B: 'ci' }
							]
						}
					]
				}
			]
		}
	]
}

You'll still have to read up a little bit on the way SGFs work, but the structure is a simple and straightforward representation of the SGF in JS form.

Want an easy way to navigate and manipulate that game? Check out smartgamer.

License

MIT

History

This parser began life as part of another project, but I thought it was useful enough to become its own module. Breaking it and the other components of that project out into individual modules has helped me improve the separation of concerns and make the project more approachable. It's the first NPM package I've written that's not a plugin for something else (ie, a Grunt plugin or Yeoman generator) and any criticisms or suggestions are welcome.