New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

chord-parser-render

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chord-parser-render

Parse and render guitar chords contained within a string of tablature

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

chord-parser-render

Utility for parsing and rendering guitar chords contained within an any string. Note, that chord must be in square brackets and starts with capital letter, e.g. [Am7]. Brackets will be removed after processing a chord. The most common use case is to wrap all chords found within a song in an anchor tag so that their finger chart can be presented in a tooltip.

Rendering

In progress.

Install

npm install chord-parser-render

or if using on the web, clone repo, run grunt copy and grab the dist/chord-parser-render.min.js file.

Usage

var input = '\
[Em]                 [D]    [Dsus4] [Cadd9] \
So close no matter how far.                 \
[Em]                    [D]          [Cadd9]\
Couldn’t be much more from the heart.       \
[Em]               [D]       [Dsus4] [Cadd9]\
Forever trusting who we are                 \
[G]   [B7]           [Em]                   \
And nothing else matters.';

// Import
var ChordParser = require('chord-parser-render');

// Create a new ChordParser object with the input string
var tabs = new ChordParser(input);

// Wrap chords found in the string (Em, D, etc.) with an anchor tag
var wrappedTab = tabs.wrap(function(chord) {
  return '<a href="">' + chord + '</a>';
});

// Return an array of unique chords found in the string
var uniques = tabs.unique(); // => ["B7", "Cadd9", "D", "Dsus4", "Em", "G"];

API

constructor

Create a new chord parsing object passing in a string of guitar tabs/chords to parse:

var parser = new ChordParser(inputString);

wrap(replacerFn);

This method calls the function replacerFn for each chord it finds in the input string, passing in the chord in as its only argument. Your wrapper function should return a string to replace the chord with. A modified version of the input string with the transposed replacements is returned.

new ChordParser('[Ab] [C#]').wrap(function(chord) {
  return '<a>' + chord + '</a>';
});

// Return value: '<a>Ab</a> <a>C#</a>'

all()

Return a sorted array of all chords found in the input string.

new ChordParser('[Ab] [C#] [B] [C#]').all();

// Return value: ['Ab', 'B', 'C#', 'C#']

unique()

Return a sorted array of unique chords found in the input string.

new ChordParser('[Ab] [C#] [B] [C#]').unique();

// Return value: ['Ab', 'B', 'C#']

Tests

Run npm test.

License

MIT.

Keywords

guitar

FAQs

Package last updated on 21 Sep 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts