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

kshoot

v0.2.1

Published

JavaScript/TypeScript library for reading KSH and KSON charts for K-Shoot Mania

Downloads

93

Readme

kshoot.js

npm GitHub Workflow Status (with branch)

This is JavaScript/TypeScript library for manipulating KSH and KSON chart files of K-Shoot Mania. This library is focused on having a simple, modular, and intuitive codebase with little dependency.

NOTE: Check out kshoot-tools if you are looking for a program or a tool to do something with chart files. This library can be used to create such tools, but is not a tool by itself.

Progress

This library is currently work-in-progress with only the basic features implemented.

  • KSH/KSON I/O
    • [x] Reading KSH
    • [x] Reading KSON
    • [ ] Writing KSH
    • [ ] Writing KSON
    • [x] Metadata
    • [x] Comments
    • [x] Notes and lasers
    • [ ] Audio effects
    • [X] Camera effects
    • [ ] BG effects
  • Simple API
    • [x] Iterating each note in the chart
    • [x] Calculating median BPM

Chart file specs

Examples

Basic data structure

Chart implements kson.Kson, so be sure to read the KSON spec before using this library. Also, ByPulse<...>[] and similar lists are managed by sorted-btree.

import {parse, Chart, kson} from 'kshoot.js';

// `Chart.parseKSON`, `Chart.parseKSH`, `parse` for parsing a chart
// Note that strings without BOMs are preferred.
let chart: Chart = Chart.parseKSON("... (a valid KSON chart, with or without BOM) ...");
chart = Chart.parseKSH("... (a valid KSH chart, with or without BOM) ...");
chart = parse("... (either KSH or KSON chart, with or without BOM) ...");

// Structure of `Chart` follows that of KSON
const meta: kson.MetaInfo = chart.meta;
const beat: kson.BeatInfo = chart.beat;
const note: kson.NoteInfo = chart.note;

// Some lists such as note.bt/fx/laser and beat.bpm are not arrays,
// but they are nevertheless iterable.
for(const [y, len] of note.bt[0]) {
    /* ... */
}

Counting notes

import fs from 'node:fs';
import {parse} from 'kshoot.js';

function reportChart(chart_filename) {
    const chart_contents = fs.readFileSync(chart_filename, 'utf-8');
    const chart = parse(chart_contents);

    let short_notes = 0;
    let long_notes = 0;

    const count = (notes_arr) => {
        for(const notes of notes_arr) {
            // Note that the backing data structure for `chart.note.bt` and `chart.note.fx` may change in future.
            // The only gaurantee is that they will always remain to be iterable.
            for(const [y, len] of notes) {
                // Note that pulses use `bigint`, not `number`.
                if(len > 0n) ++long_notes;
                else ++short_notes;
            }
        }
    };

    count(chart.note.bt);
    count(chart.note.fx);

    console.log(`${chart_filename}: ${short_notes} short notes, ${long_notes} long notes`);
}

["./foo.ksh", "./bar.kson"].forEach(reportChart);

Dependencies

I want kshoot to have as little dependencies as possible. Some zero-dependency libraries are too cool to not use, though.

$ pnpm ls --prod --depth 2
Legend: production dependency, optional only, dev only

[email protected] D:\Project\GitHub\kshoot.js

dependencies:
sorted-btree 1.8.1
zod 3.23.8