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

ojsama

v2.2.0

Published

pp and difficulty calculator for osu! in pure javascript

Downloads

110

Readme

this is free and unencumbered software released into the public domain. refer to the attached UNLICENSE or http://unlicense.org/

Build Status

pure javascript implementation of https://github.com/Francesco149/oppai-ng intended to be easier to use and set up for js developers as well as more portable than straight up bindings at the cost of some performance

installation:

since this is a single-file library, you can just drop the file into your project:

cd my/project
curl https://waa.ai/ojsama > ojsama.js

or include it directly in a html page:

<script type="text/javascript" src="ojsama.min.js"></script>

it's also available as a npm package:

npm install ojsama

you can find full documentation of the code at http://hnng.moe/stuff/ojsama.html or simply read ojsama.js

usage (nodejs):

(change ./ojsama to ojsama if you installed through npm)

var readline = require("readline");
var osu = require("./ojsama");

var parser = new osu.parser();
readline.createInterface({
  input: process.stdin, terminal: falsei
})
.on("line", parser.feed_line.bind(parser))
.on("close", function() {
  console.log(osu.ppv2({map: parser.map}).toString());
});
$ curl https://osu.ppy.sh/osu/67079 | node minexample.js
133.24 pp (36.23 aim, 40.61 speed, 54.42 acc)

advanced usage (nodejs with acc, mods, combo...):

var readline = require("readline");
var osu = require("./ojsama");

var mods = osu.modbits.none;
var acc_percent;
var combo;
var nmiss;

// get mods, acc, combo, misses from command line arguments
// format: +HDDT 95% 300x 1m
var argv = process.argv;

for (var i = 2; i < argv.length; ++i)
{
  if (argv[i].startsWith("+")) {
    mods = osu.modbits.from_string(argv[i].slice(1) || "");
  }

  else if (argv[i].endsWith("%")) {
    acc_percent = parseFloat(argv[i]);
  }

  else if (argv[i].endsWith("x")) {
    combo = parseInt(argv[i]);
  }

  else if (argv[i].endsWith("m")) {
    nmiss = parseInt(argv[i]);
  }
}

var parser = new osu.parser();
readline.createInterface({
  input: process.stdin, terminal: false
})
.on("line", parser.feed_line.bind(parser))
.on("close", function() {
  var map = parser.map;
  console.log(map.toString());

  if (mods) {
    console.log("+" + osu.modbits.string(mods));
  }

  var stars = new osu.diff().calc({map: map, mods: mods});
  console.log(stars.toString());

  var pp = osu.ppv2({
    stars: stars,
    combo: combo,
    nmiss: nmiss,
    acc_percent: acc_percent,
  });

  var max_combo = map.max_combo();
  combo = combo || max_combo;

  console.log(pp.computed_accuracy.toString());
  console.log(combo + "/" + max_combo + "x");

  console.log(pp.toString());
});
$ curl https://osu.ppy.sh/osu/67079 | node example.js
TERRA - Tenjou no Hoshi ~Reimeiki~ [BMax] mapped by ouranhshc

AR5 OD8 CS4 HP8
262 circles, 69 sliders, 5 spinners
469 max combo

4.33 stars (2.09 aim, 2.19 speed)
100.00% 0x100 0x50 0xmiss
469/469x
133.24 pp (36.23 aim, 40.61 speed, 54.42 acc)

$ curl https://osu.ppy.sh/osu/67079 \
| node example.js +HDDT 98% 400x 1m
...
+HDDT
6.13 stars (2.92 aim, 3.11 speed)
97.92% 9x100 0x50 1xmiss
400/469x
266.01 pp (99.70 aim, 101.68 speed, 60.41 acc)

usage (in the browser)

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <script type="text/javascript" src="ojsama.min.js"></script>
  <script type="text/javascript">
  function load_file()
  {
    var frame = document.getElementById("osufile");
    var contents = frame.contentWindow
      .document.body.childNodes[0].innerHTML;

    var parser = new osu.parser().feed(contents);
    console.log(parser.toString());

    var str = parser.map.toString();
    str += osu.ppv2({map: parser.map}).toString();

    document.getElementById("result").innerHTML = str;
  }
  </script>
</head>
<body>
  <iframe id="osufile" src="test.osu" onload="load_file();"
  style="display: none;">
  </iframe>
  <blockquote><pre id="result">calculating...</pre></blockquote>
</body>
</html>

(this example assumes you have a test.osu beatmap in the same directory)

performance

this is around 50-60% slower than the C implementation and uses ~10 times more memory.

$ busybox time -v node --use_strict test.js
...
User time (seconds): 16.58
System time (seconds): 0.43
Percent of CPU this job got: 101%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0m 16.70s
...
Maximum resident set size (kbytes): 314080
Minor (reclaiming a frame) page faults: 20928
Voluntary context switches: 72138
Involuntary context switches: 16689