Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

simfile-parser

noahm177MIT0.8.1TypeScript support: included

Read stepmania charts with javascript!

stepmania, itg, stepfile, ddr

readme

simfile-parser

npm npm bundle size

Original parsing code from city41/stepcharts. Props to Matt for building a really sweet site.

Works both in node (server-side or CLI) and in browser. Bun and Deno support is untested, but an interesting future to explore!

Usage

Install with npm install --save simfile-parser or yarn add simfile-parser

// in node.js >= 16.9.0

import {
  parseAllPacks,
  parsePack,
  parseSong,
  calculateStats,
} from "simfile-parser";

// Use one of the three parsing functions depending on your needs:
const allMyStuff = parseAllPacks("/pathToStepmania/Songs");
const aGreatPack = parsePack("/pathToStepmania/Songs/DDRMAX2");
const aGreatSong = parseSong(".../Songs/Easy as Pie 2/Abracadabra");

// you can get some top level info about a song's contents too:
calculateStats(aGreatSong.charts["single-challenge"]);
/* returns:
{
  "freezes": 111,
  "gallops": 0,
  "jacks": 22,
  "jumps": 8,
}
*/

Browser support

Support dragging packs directly into a web app by parsing in-browser!

// requires typescript 5.0 in "Bundler" module resolution mode for typings
import { parsePack } from "simfile-parser/browser";

// necessary to enable data drops
document.body.addEventListener("dragover", function (e) {
  e.preventDefault();
});

document.body.addEventListener("drop", async function (e) {
  // also necessary to prevent browser navigating to dropped folder
  evt.preventDefault();
  if (!evt.dataTransfer) {
    return;
  }
  if (evt.dataTransfer.items.length !== 1) {
    console.error("too many items dropped, try just one folder");
    return;
  }

  try {
    const pack = await parsePack(evt.dataTransfer.items[0]);
    console.log(`parsed pack "${pack.name}" with ${pack.songCount} songs`);
  } catch (e) {
    console.error(e);
  }
});

changelog

Changelog

v0.8.1

  • Added support for parsing individual simfiles via HTMLInputElement selection in Firefox.

v0.8.0

  • Added parseSongFolderOrData to browser exports for parsing a single song folder or data file.

v0.7.2

  • Gracefully drop empty placeholder charts instead of bailing on the whole song
  • Avoid spamming warnings when guessing jacket names in browser

v0.7.1

  • Changed behavior when a song with both older dwi charts and newer ssc or sm files present. Before the first song to appear alphabetically would be used, but this might use the older dwi file as the source of info, which is unlikely to be desired. Now ssc files are used first, if present, then sm, and finally dwi.
  • Changed behavior when multiple files with the same extension exist as sometimes occurs when a text editor saves a hidden backup file with a leading period. (e.g. song.sm and .song.sm in a folder together) Files without a leading period are now always used over ones with a leading period.

v0.7.0

  • Added support for in-browser parsing of entire simfile packs! Individual songs can be easily supported later. See the readme for usage example.

v0.6.1

  • Avoid publishing yarn cache in published tarball

v0.6.0

  • BREAKING switched package output to pure ESM
  • Removed dependency on 'fraction.js'
  • Fix parsing BPMs when broken across multiple lines
  • Parse display bpms to a better display format

v0.5.0

  • BREAKING drop support for Node 14
  • Fixed non-song folders in packs causing fatal errors

v0.4.1

  • No changes (just working out auto-publishing)

v0.4.0

  • BREAKING renamed some exported types and/or fields
    • FreezeBody => FreezeLocation
    • Bpm => BpmChange
    • Arrow['beat'] => Arrow['quantization']
  • Quantization now reports 32nd and 64th steps, anything out of bounds is now reported as a 64th instead of a 12th
  • More correctly return displayBpm values as written in the stepfile instead of always calculating a range
  • Added considerable amounts of doc comments on types and functions
  • Fixed potentially incorrect handling of simfiles using the less-standard BACKGROUND tag (compared to the more common BG)

v0.3.0

  • BREAKING drop support for Node 12, begin testing in node 18
  • Fix issues parsing SSC: no longer crashes on files with only a single chart, no longer missing the final chart when multiple exist

v0.2.1

  • Fixed some problems detecting images

v0.2.0

  • Added SSC parser
  • Fixed issues parsing charts with rolls

v0.1.0

Initial public release. Parses DWI and SM files (most of the time) and picks up associated images (sometimes).