It's cleanroom, too! No required dependencies!
Important
This library does not bundle CommonJS modules. Legacy Node.js applications may not be compatible.
Tip
When linking to esm.run
, it's recommended to use a version! (e.g. @encode42/nbs.js@6.0.0
)
Add the @encode42/nbs.js
package using the package manager of your choice.
import { Song } from "@encode42/nbs.js";
<script type="module">
import { Song } from "https://esm.run/@encode42/nbs.js";
</script>
import { Song } from "https://esm.run/@encode42/nbs.js";
How do I use this?
Install nbs.js for your platform, then refer to the documentation and examples below.
There are more examples designed for use with Node.js in the examples directory!
π’ Node.js
import { readFileSync } from "node:fs";
import { fromArrayBuffer } from "@encode42/nbs.js";
const songFile = readFileSync("song.nbs"); // Read the selected NBS file
const buffer = new Uint8Array(songFile).buffer; // Convert it into an ArrayBuffer
const song = fromArrayBuffer(buffer); // Parse the buffer
console.dir(song);
π Browser
<input type="file" id="file-input">
<script type="module">
import { fromArrayBuffer } from "https://esm.run/@encode42/nbs.js"
window.addEventListener("load", () => {
const input = document.getElementById("file-input");
// Initialize file input
input.addEventListener("change", () => {
const songFile = input.files[0]; // Read the selected NBS file
songFile.arrayBuffer().then(buffer => { // Convert it into an ArrayBuffer
const song = fromArrayBuffer(buffer); // Parse the buffer
console.dir(song);
});
});
});
</script>
π¦ Deno
import { fromArrayBuffer } from "https://esm.run/@encode42/nbs.js";
const songFile = await Deno.readFile("song.nbs"); // Read the selected NBS file
const buffer = new Uint8Array(songFile).buffer; // Convert it into an ArrayBuffer
const song = fromArrayBuffer(buffer); // Parse the buffer
console.dir(song);
Is there a demo?
Currently, a website to demonstrate usage of the library does not exist. However, this repository contains tests that could be used as examples, and actual examples designed for Node.js and similar.
Where's the changelog?
I don't create GitHub releases, but I do keep a changelog here!
Ensure that Bun is installed.
- Enter the directory containing the nbs.js source code in your terminal.
- Install the build dependencies via
bun install
. - Run
bun run build
to bundle the ESM module.
Generated files:
dist/*.js
: Bundled ESM files for Node.js and relateddist/*.d.ts
: Generated TypeScript type bundlepublic/docs/*
: Generated web-based documentation