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

tablab

v1.0.0

Published

A javascript library to write tablatures

Downloads

279

Readme

Tablab

NPM npm Commitizen friendly npm Coverage Status CI

Tablab is a javascript library to write tablatures. It provides two different ways for writing them:

  • Step by step: With this strategy, you must create a tablature instance and specify each operation to write the desired tablature;
  • From a text input of instructions: In this case, you must create a parser instance to read these instructions. Once read, the resulting parsed instructions can be used with an instruction writer factory to determine and perform the corresponding writing operations to a tablature instance.

Table of Content

Install

With node installed, run

npm install tablab

Usage

Writing a tablature step by step

The Tab class provides the functionalities to write a tablature step by step. With it, you can write notes, header messages, footer messages, change its spacing and add new blocks to your tablature. Once done writing your tablature, you can format it as intended.

Check out the Tab class usage documentation for more information about:

  • The available options to customize your tablature;
  • The available methods to perform the writing operations.

Below, an example of how the Tab class can be used to write a tablature:

const { Tab, Note } = require('tablab');

const cMajorChord = [
  new Note(1, '0'),
  new Note(2, '1'),
  new Note(3, '0'),
  new Note(4, '2'),
  new Note(5, '3'),
];

const eMajorChord = [
  new Note(1, '0'),
  new Note(2, '0'),
  new Note(3, '1'),
  new Note(4, '2'),
  new Note(5, '2'),
  new Note(6, '0'),
];

const tab = new Tab();

tab
  .writeHeader('Simple Notes Example')
  .writeNote(new Note(1, '0'))
  .setSpacing(2)
  .writeNote(new Note(2, '1'))
  .writeNote(new Note(3, '2'))
  .writeNote(new Note(4, '1/3'))
  .writeNote(new Note(5, '3'))
  .writeNote(new Note(6, '1'))
  .writeNote(new Note(5, '2'))
  .writeNote(new Note(4, '3'))
  .writeNote(new Note(3, '1h3'))
  .writeNote(new Note(2, '3p1'))
  .writeNote(new Note(1, '2'))
  .writeFooter('x2')
  .addBlock()
  .setSpacing(5)
  .writeHeader('Chord Example (C Major)')
  .writeParallelNotes(cMajorChord)
  .writeParallelNotes(cMajorChord)
  .addBlock()
  .writeHeader('Chord Example (E Major)')
  .writeParallelNotes(eMajorChord)
  .writeParallelNotes(eMajorChord);

console.log(tab.format(50));

outputs

[
  [
    '   | Simple Notes Example                     |   ',
    '---|---0-----------------------------------2--|---',
    '---|------1---------------------------3p1-----|---',
    '---|---------2-------------------1h3----------|---',
    '---|------------1/3-----------3---------------|---',
    '---|-----------------3-----2------------------|---',
    '---|--------------------1---------------------|---',
    '   |                                       x2 |   '
  ],
  [
    '     | Chord Example (C Major)                    ',
    '-----|-----0-----0--------------------------------',
    '-----|-----1-----1--------------------------------',
    '-----|-----0-----0--------------------------------',
    '-----|-----2-----2--------------------------------',
    '-----|-----3-----3--------------------------------',
    '-----|--------------------------------------------',
    '     |                                            '
  ],
  [
    '     | Chord Example (E Major)                    ',
    '-----|-----0-----0--------------------------------',
    '-----|-----0-----0--------------------------------',
    '-----|-----1-----1--------------------------------',
    '-----|-----2-----2--------------------------------',
    '-----|-----2-----2--------------------------------',
    '-----|-----0-----0--------------------------------',
    '     |                                            '
  ]
]

Writing a tablature from a text input of instructions

As in the strategy step by step, the Tab class is responsible for managing the tablature. The difference from this strategy is that instead of calling each method direct from a tablature instance, the writing operations will be determined from a text input of instructions.

Tablab provides the Parser class to read the given text input of instructions and determine the writing operation to be performed over the tablature for each parsed instruction.

Check out the Parser class usage documentation for more information about:

Below, an example of how the Parser class can be used with the Tab class to write a tablature:

const { Tab, Parser } = require('tablab');

const instructions =
  'header(Simple Notes Example) 1-0 spacing(2) ' +
  '2-1 3-2 4-1/3 5-3 6-1 5-2 4-3 3-1h3 2-3p1 1-2 footer(x2) break spacing(5) ' +
  'header(Chord Example (C Major)) merge{ 1-0 2-1 3-0 4-2 5-3 } ' +
  'merge{ 1-0 2-1 3-0 4-2 5-3 } break header(Chord Example (E Major)) ' +
  'merge{ 1-0 2-0 3-1 4-2 5-2 6-0 } merge{ 1-0 2-0 3-1 4-2 5-2 6-0 }';

const tab = new Tab();
const parser = new Parser();

parser.parseAll(instructions).forEach((parsedInstruction) => {
  const writeResult = parsedInstruction.writeOnTab(tab);

  if (!writeResult.success) {
    console.log(
      `Failed to write instruction < ${parsedInstruction.value} > at position ` +
        `${parsedInstruction.readFromIndex}. (${writeResult.failureReasonIdentifier}) ` +
        `- ${writeResult.failureMessage} `
    );
  }
});

console.log(tab.format(50));

outputs

[
  [
    '   | Simple Notes Example                     |   ',
    '---|---0-----------------------------------2--|---',
    '---|------1---------------------------3p1-----|---',
    '---|---------2-------------------1h3----------|---',
    '---|------------1/3-----------3---------------|---',
    '---|-----------------3-----2------------------|---',
    '---|--------------------1---------------------|---',
    '   |                                       x2 |   '
  ],
  [
    '     | Chord Example (C Major)                    ',
    '-----|-----0-----0--------------------------------',
    '-----|-----1-----1--------------------------------',
    '-----|-----0-----0--------------------------------',
    '-----|-----2-----2--------------------------------',
    '-----|-----3-----3--------------------------------',
    '-----|--------------------------------------------',
    '     |                                            '
  ],
  [
    '     | Chord Example (E Major)                    ',
    '-----|-----0-----0--------------------------------',
    '-----|-----0-----0--------------------------------',
    '-----|-----1-----1--------------------------------',
    '-----|-----2-----2--------------------------------',
    '-----|-----2-----2--------------------------------',
    '-----|-----0-----0--------------------------------',
    '     |                                            '
  ]
]

Acknowledgments

The Tablab's parser was highly inspired by the Latex project, a text preparation system. It provides a creative solution that decouples the document operations of writing them and designing them. If you have already struggled with writing documents, and adjusting their layout, make sure to check it out.

License

MIT