GithubHelp home page GithubHelp logo

ayunami2000 / nbs.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from encode42/nbs.js

1.0 1.0 1.0 1.33 MB

A versatile API for reading and writing OpenNBS files.

License: MIT License

JavaScript 4.68% TypeScript 95.32%

nbs.js's Introduction

NBS.js

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

Docs Badge Changelog Badge NPM Badge

With the added bonus of no required dependencies!

๐Ÿ”ง Including

๐ŸŒ Browser

It's recommended to use a versioned link, e.g. @encode42/[email protected]

Script

<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

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

โš™๏ธ Deno

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

โš™๏ธ Node.js

NPM

npm i @encode42/nbs.js

Yarn

yarn add @encode42/nbs.js

โ” FAQ

How do I use this?

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

Docs Badge

Browser (Script)
<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");

  // Clear the file input (QOL)
  input.value = null;

  // Initialize file input
  input.addEventListener("change", () => {
    const songFile = input.files[0]; // Read a NBS file
    songFile.arrayBuffer().then(buffer => { // Create an ArrayBuffer
      const song = NBSjs.fromArrayBuffer(buffer); // Parse song from ArrayBuffer

      console.log(song);
    });
  });
});
</script>
Browser (Module)

index.html

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

<script src="index.js" type="module">

index.js

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

window.addEventListener("load", () => {
  const input = document.getElementById("file-input");

  // Clear the file input (QOL)
  input.value = null;
    
  // Initialize file input
  input.addEventListener("change", () => {
    const songFile = input.files[0]; // Read a NBS file
    songFile.arrayBuffer().then(buffer => { // Create an ArrayBuffer
      const song = fromArrayBuffer(buffer); // Parse song from ArrayBuffer

      console.log(song);
    });
  });
});
Deno
import { fromArrayBuffer } from "https://cdn.jsdelivr.net/npm/@encode42/nbs.js/dist/esm.js";

const songFile = await Deno.readFile("song.nbs"); // Read a NBS file
const buffer = new Uint8Array(songFile).buffer; // Create an ArrayBuffer
const song = fromArrayBuffer(buffer); // Parse song from ArrayBuffer

console.log(song);
Node.js
const fs = require("fs");
const { fromArrayBuffer } = require("@encode42/nbs.js"); // Import NBS.js

const songFile = fs.readFileSync("song.nbs"); // Read a NBS file
const buffer = new Uint8Array(songFile).buffer; // Create an ArrayBuffer
const song = fromArrayBuffer(buffer); // Parse song from ArrayBuffer

console.log(song);

NPM Badge

Is there a demo?

Yes! A GitHub pages site is located here. It contains a demonstration of how to read and process NBS files, displays the song structure, and plays the song through the browser.

The demo is currently under development. Check NBSPlayer for a working example!

Where's the changelog?

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

Changelog Badge

๐Ÿ”จ Building

Ensure Yarn and Node.js are installed.

  1. Enter the directory containing the NBS.js source code in your terminal.
  2. Install the build dependencies via yarn install.
  3. Run yarn 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 ES2015 files.

nbs.js's People

Contributors

encode42 avatar actions-user avatar ayunami2000 avatar dependabot[bot] avatar

Stargazers

Evan avatar

Watchers

James Cloos avatar

Forkers

barneycompiler

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.