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

swtparser

v3.1.0

Published

Parser for Swiss-Chess Tournament (SWT) files

Downloads

63

Readme

swtparser

Parse SWT Swiss-Chess Tournament files with JavaScript, either by using node.js or directly in your Browser.

Usage with node.js

Simply install the package via

npm install swtparser

You can either use the provided parse.fromBuffer and parse.fromDataView functions or put what you want directly into the parser:

var parse = require('swtparser');
var tournament = parse(buffer);

Internally the DataView method is used for the parsing process.

If you want to try other/newer SWT structure files simply put them into the /structures folder and run the following npm command to build a new /lib/structure.json file:

npm run-script build-structure

Usage within the Browser

The swtparser also works in the Browser. Simply use the swtparser.browser.js in your HTML files. The Browser version only allows to parse DataView objects. Here is an example snippet:

<script src="swtparser.js"></script>
<script type="text/javascript">
  var reader = new FileReader();
  reader.onload = function(e) {
    var tournament = parseSWT(new DataView(this.result));
    // handle your tournament in `tournament`
  }
  reader.readAsArrayBuffer(file);
</script>

If you want to try other/newer SWT structure files you have to put them into the /structures folder and run the following commands:

# rebuild the /lib/structure.json
npm run-script build-structure

# rebuild swtparser.browser.js
npm run-script build-browser

Returned Object

The swtparser returns a hash with the first class objects general, players and pairings_players. In case of team tournaments teams and pairings_teams are provided too:

{
  // the numeric keys are those of the structure files
  'general': {
    '1': 7,
    '2': 7,
    '3': 7,
    '4': 131,
    '5': 0,
    '6': 0,
    '7': 0,
    '8': false,
    '9': 14,
    '10': true,
    '11': 'Arial',
    '12': 'My Tournament name',
    ...
  },
  'players': [
    {
      '2000': 'Surname, Prename',
      '2001': 'MyCountry',
      '2002': '20',
      '2003': '2479',
      '2004': '2498',
      '2005': '1031',
      '2006': 'GER',
      '2007': '',
      '2008': '1973      ',
      ...
      // automatically added:
      'positionInSWT': 0
    },
    ...
  ],
  'pairings_players': [ // only if pairings already set
    {
      '4000': '4000-2',
      '4001': '4b',
      '4002': '4002-10',
      '4003': '3004-10',
      '4004': 0,
      '4005': '3006-0',
      '4006': 1,
      // automatically added:
      'player': '01',
      'round': 1
    }
    ...
  ],
  'teams': [  // only in team tournaments
    {
      '1000': 'My Team Name',
      '1001': '2007',
      '1002': '2048',
      '1003': '2048',
      '1004': '',
      '1005': '',
      ...
      // automatically added:
      'positionInSWT': 0
    }
    ...
  ],
  'pairings_teams': [ // only in team tournaments and if pairings already set
    {
      '3000': 'ffff',
      '3001': '3001-1',
      '3002': 'f0',
      '3003': '03',
      '3004': '3004-0',
      '3005': 1,
      '3006': '3006-0',
      '3007': '01',
      '3008': 0,
      // automatically added:
      'team': 'e7',
      'round': 1
    },
    ...
  ]
}

Supported SWT versions

Because this module uses the SWT structure files of fnogatz/SWT-structure-files, it supports the file versions provided by those structure information. Currently only tournaments of SWT version 8.xx can be parsed.