martijnversluis / ChordJS

A simple JavaScript chord parsing and manipulation tool
GNU General Public License v2.0
30 stars 5 forks source link
chords manipulation parsing

⚠️ NOTE: ChordJS has been merged into ChordSheetJS

ChordJS will not receive any more updates, although it will remain on NPM. To benefit from new features, please use ChordSheetJS instead.

npm install chordsheetjs

or:

yarn add chordsheetjs
import Chord from 'chordsheetjs';
const chord = Chord.parse('Em');

ChordJS Build Status npm version Code Climate

A simple JavaScript chord parsing and manipulation tool

Installation

ChordJS is on npm, to install run:

npm install chordjs

or:

yarn add chordjs

Load with import (es2015):

var Chord = require('chordjs').default;
import Chord, { parse } from 'chordjs';

Functionalities

Parse

const chord = parse('Ebsus4/Bb');

Parse numeric chords (Nashville system):

const chord = parse('b1sus4/#3');

Display with #toString

Use #toString() to convert the chord to a chord string (eg Dsus/F#)

const chord = parse('Ebsus4/Bb');
chord.toString(); // --> "Ebsus4/Bb"

Clone

var chord2 = chord.clone();

Normalize

Normalizes keys B#, E#, Cb and Fb to C, F, B and E

const chord = parse('E#/B#'),
    normalizedChord = chord.normalize();
normalizedChord.toString(); // --> "F/C"

Switch modifier

Convert # to b and vice versa

const chord = parse('Eb/Bb');
const chord2 = chord.switchModifier();
chord2.toString(); // --> "D#/A#"

Use specific modifier

Set the chord to a specific modifier (# or b)

const chord = parse('Eb/Bb');
const chord2 = chord.useModifier('#');
chord2.toString(); // --> "D#/A#"
const chord = parse('Eb/Bb');
const chord2 = chord.useModifier('b');
chord2.toString(); // --> "Eb/Bb"

Transpose up

const chord = parse('Eb/Bb');
const chord2 = chord.transposeUp();
chord2.toString(); // -> "E/B"

Transpose down

const chord = parse('Eb/Bb');
const chord2 = chord.transposeDown();
chord2.toString(); // -> "D/A"

Transpose

const chord = parse('C/E');
const chord2 = chord.transpose(4);
chord2.toString(); // -> "E/G#"
const chord = parse('C/E');
const chord2 = chord.transpose(-4);
chord2.toString(); // -> "Ab/C"

Convert numeric chord to chord symbol

const numericChord = parse('2/4');
const chordSymbol = toChordSymbol(numericChord, 'E');
chordSymbol.toString(); // -> "F#m/A"