Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.
/ ChordJS Public archive

A simple JavaScript chord parsing and manipulation tool

License

Notifications You must be signed in to change notification settings

martijnversluis/ChordJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

04e7bb1 · Aug 18, 2021
Apr 29, 2021
Aug 18, 2021
Jun 18, 2021
May 1, 2021
May 10, 2018
May 1, 2021
Jun 18, 2021
May 10, 2018
Jun 18, 2021
May 1, 2021
Feb 16, 2015
Jun 18, 2021
Aug 18, 2021
Aug 13, 2021

Repository files navigation

ChordJS Build Status npm version Code Climate

A simple JavaScript chord parsing and manipulation tool

⚠️ NOTE: These are the V2 docs. The V1 docs are here.

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"