5.0.2 • Published 11 months ago

@encode42/nbs.js v5.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

NBS.js

A versatile API for reading, manipulating, and writing OpenNBS files, inspired by NBSEditor and NBS4j.

It's cleanroom, too! No required dependencies!

Demo Badge Docs Badge NPM Badge

šŸ”§ Including

!TIP When using jsdelivr links, it's recommended to use versioned links! (e.g. @encode42/nbs.js@3.0.0)

!WARNING
3.0.0 is not the latest version of NBS.js! The above is just an example.

🌐 Browser

<script src="https://cdn.jsdelivr.net/npm/@encode42/nbs.js"></script>

Minified: https://cdn.jsdelivr.net/npm/@encode42/nbs.js/dist/umd.min.js

šŸ¦• Module & Deno

import { Song } from "https://cdn.jsdelivr.net/npm/@encode42/nbs.js/dist/esm.js";

Minified: https://cdn.jsdelivr.net/npm/@encode42/nbs.js/dist/esm.min.js

🟢 Node.js

Add the @encode42/nbs.js package from NPM using the package manager of your choice.

import { Song } from "@encode42/nbs.js"; // ESM (TypeScript, Vite, etc.)

const { Song } = require("@encode42/nbs.js"); // CJS (vanilla Node.js)

ā” FAQ

Install NBS.js for your platform, then refer to the documentation and examples below.

<input type="file" id="file-input">

<script src="https://cdn.jsdelivr.net/npm/@encode42/nbs.js"></script> <!-- Import NBS.js -->
<script>
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 = NBSjs.fromArrayBuffer(buffer); // Parse the buffer

			console.dir(song);
		});
	});
});
</script>
<input type="file" id="file-input">

<script src="index.js" type="module">
import { fromArrayBuffer } from "https://cdn.jsdelivr.net/npm/@encode42/nbs.js/dist/esm.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);
		});
	});
});
// ESM (TypeScript, Vite, etc.)
import { readFileSync } from "node:fs";
import { fromArrayBuffer } from "@encode42/nbs.js";

// CJS (vanilla Node.js)
const { readFileSync } = require("fs");
const { fromArrayBuffer } = require("@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);
import { fromArrayBuffer } from "https://cdn.jsdelivr.net/npm/@encode42/nbs.js/dist/esm.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);

Yes! A demo site is located here. It serves as an example of how to read NBS files, allows you to edit the song structure, and plays the result through the browser.

This repository also contains tests that could be used as examples.

I don't create GitHub releases, but I do keep a changelog here!

šŸ”Ø Building

Ensure PNPM and Node.js are installed.

  1. Enter the directory containing the NBS.js source code in your terminal.
  2. Install the build dependencies via pnpm install.
  3. Run pnpm run build to generate the Node.js and browser modules.

Generated files:

  • dist/cjs.js: CommonJS bundle, used by Node.js.
  • dist/esm.js: ES module for browser script modules.
  • dist/umd.js: UMD bundle for browser scripts.
  • dist/*.min.js: Minified bundle.
  • build/: Built ES2021 files.
5.0.2

11 months ago

5.0.1

11 months ago

6.0.0-alpha4

1 year ago

6.0.0-beta2

1 year ago

6.0.0-beta

1 year ago

6.0.0-alpha1

2 years ago

6.0.0-alpha2

2 years ago

6.0.0-alpha3

2 years ago

6.0.0-alpha

2 years ago

5.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.0.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

0.0.1

4 years ago

1.0.0

4 years ago