ChordSheetJS
A JavaScript library for parsing and formatting chord sheets
Contents
Installation
Package managers
ChordSheetJS
is on npm, to install run:
npm install chordsheetjs
Load with import
:
import ChordSheetJS from 'chordsheetjs';
or require()
:
var ChordSheetJS = require('chordsheetjs').default;
Standalone bundle file
If you're not using a build tool, you can download and use the bundle.js
from the
latest release:
<script src="bundle.js"></script>
<script>
// ChordSheetJS is available in global namespace now
const parser = new ChordSheetJS.ChordProParser();
</script>
How to ...?
Parse chord sheet
Regular chord sheets
const chordSheet = `
Am C/G F C
Let it be, let it be, let it be, let it be
C G F C/E Dm C
Whisper words of wisdom, let it be`.substring(1);
const parser = new ChordSheetJS.ChordSheetParser();
const song = parser.parse(chordSheet);
Ultimate Guitar chord sheets
const chordSheet = `
[Chorus]
Am C/G F C
Let it be, let it be, let it be, let it be
C G F C/E Dm C
Whisper words of wisdom, let it be`.substring(1);
const parser = new ChordSheetJS.UltimateGuitarParser();
const song = parser.parse(chordSheet);
Chord pro format
const chordSheet = `
{title: Let it be}
{subtitle: ChordSheetJS example version}
{start_of_chorus: Chorus}
Let it [Am]be, let it [C/G]be, let it [F]be, let it [C]be
[C]Whisper words of [G]wisdom, let it [F]be [C/E] [Dm] [C]
{end_of_chorus}`.substring(1);
const parser = new ChordSheetJS.ChordProParser();
const song = parser.parse(chordSheet);
Display a parsed sheet
Plain text format
const formatter = new ChordSheetJS.TextFormatter();
const disp = formatter.format(song);
HTML format
Table-based layout
const formatter = new ChordSheetJS.HtmlTableFormatter();
const disp = formatter.format(song);
Div-based layout
const formatter = new ChordSheetJS.HtmlDivFormatter();
const disp = formatter.format(song);
Chord pro format
const formatter = new ChordSheetJS.ChordProFormatter();
const disp = formatter.format(song);
Serialize/deserialize
Chord sheets (Song
s) can be serialized to plain JavaScript objects, which can be converted to JSON, XML etc by
third-party libraries. The serialized object can also be deserialized back into a Song
.
const serializedSong = new ChordSheetSerializer().serialize(song);
const deserialized = new ChordSheetSerializer().deserialize(serializedSong);
Add styling
The HTML formatters (HtmlTableFormatter and HtmlDivFormatter) can provide basic CSS to help with styling the output:
HtmlTableFormatter.cssString();
// .paragraph {
// margin-bottom: 1em;
// }
HtmlTableFormatter.cssString('.chordSheetViewer');
// .chordSheetViewer .paragraph {
// margin-bottom: 1em;
// }
HtmlTableFormatter.cssObject();
// '.paragraph': {
// marginBottom: '1em'
// }
Parsing and modifying chords
import { parseChord } from 'chordsheetjs';
Parse
const chord = parseChord('Ebsus4/Bb');
Parse numeric chords (Nashville system):
const chord = parseChord('b1sus4/#3');
Display with #toString
Use #toString() to convert the chord to a chord string (eg Dsus/F#)
const chord = parseChord('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 = parseChord('E#/B#'),
normalizedChord = chord.normalize();
normalizedChord.toString(); // --> "F/C"
Switch modifier
Convert # to b and vice versa
const chord = parseChord('Eb/Bb');
const chord2 = chord.switchModifier();
chord2.toString(); // --> "D#/A#"
Use specific modifier
Set the chord to a specific modifier (# or b)
const chord = parseChord('Eb/Bb');
const chord2 = chord.useModifier('#');
chord2.toString(); // --> "D#/A#"
const chord = parseChord('Eb/Bb');
const chord2 = chord.useModifier('b');
chord2.toString(); // --> "Eb/Bb"
Transpose up
const chord = parseChord('Eb/Bb');
const chord2 = chord.transposeUp();
chord2.toString(); // -> "E/B"
Transpose down
const chord = parseChord('Eb/Bb');
const chord2 = chord.transposeDown();
chord2.toString(); // -> "D/A"
Transpose
const chord = parseChord('C/E');
const chord2 = chord.transpose(4);
chord2.toString(); // -> "E/G#"
const chord = parseChord('C/E');
const chord2 = chord.transpose(-4);
chord2.toString(); // -> "Ab/C"
Convert numeric chord to chord symbol
const numericChord = parseChord('2/4');
const chordSymbol = toChordSymbol(numericChord, 'E');
chordSymbol.toString(); // -> "F#m/A"
Supported ChordPro directives
All directives are parsed and are added to Song.metadata
. The list below indicates whether formatters actually
use those to change the generated output.
✔️ = supported
Meta-data directives
Directive | Support |
---|---|
title (short: t) | |
subtitle | |
artist | |
composer | |
lyricist | |
copyright | |
album | |
year | |
key | |
time | |
tempo | |
duration | |
capo | |
meta |
Formatting directives
Directive | Support |
---|---|
comment (short: c) | |
comment_italic (short: ci) | |
comment_box (short: cb) | |
chorus | ✖️ |
image |
Environment directives
Directive | Support |
---|---|
start_of_chorus (short: soc) | |
end_of_chorus (short: eoc) | ✔️ |
start_of_verse | |
end_of_verse | ✔️ |
start_of_tab (short: sot) | |
end_of_tab (short: eot) | |
start_of_grid | |
end_of_grid | ✖️ |
Chord diagrams
Directive | Support |
---|---|
define | |
chord |
Fonts, sizes and colours
Directive | Support |
---|---|
textfont | |
textsize | |
textcolour | |
chordfont | |
chordsize | |
chordcolour | ✔️ |
tabfont | ✖️ |
tabsize | |
tabcolour |
Output related directives
Directive | Support |
---|---|
new_page (short: np) | |
new_physical_page (short: npp) | |
column_break (short: cb) | ✖️ |
grid (short: g) | |
no_grid (short: ng) | |
titles | ✖️ |
columns (short: col) |
Custom extensions
Directive | Support |
---|---|
x_ |
API docs
Note: all classes, methods and constants that are documented here can be considered public API and will only be subject to breaking changes between major versions.
Classes
- ChordLyricsPair
Represents a chord with the corresponding (partial) lyrics
- Comment
Represents a comment. See https://www.chordpro.org/chordpro/chordpro-file-format-specification/#overview
- Line :
Font
Represents a line in a chord sheet, consisting of items of type ChordLyricsPair or Tag
- Metadata
Stores song metadata. Properties can be accessed using the get() method:
const metadata = new Metadata({ author: 'John' }); metadata.get('author') // => 'John'
See [get](#Metadata+get)
- Paragraph
Represents a paragraph of lines in a chord sheet
- Song
Represents a song in a chord sheet. Currently a chord sheet can only have one song.
- Tag
Represents a tag/directive. See https://www.chordpro.org/chordpro/chordpro-directives/
- ChordProFormatter
Formats a song into a ChordPro chord sheet
- ChordsOverWordsFormatter
Formats a song into a plain text chord sheet
- Formatter
Base class for all formatters, taking care of receiving a configuration wrapping that inside a Configuration object
- HtmlDivFormatter
Formats a song into HTML. It uses DIVs to align lyrics with chords, which makes it useful for responsive web pages.
- HtmlFormatter
Acts as a base class for HTML formatters
- HtmlTableFormatter
Formats a song into HTML. It uses TABLEs to align lyrics with chords, which makes the HTML for things like PDF conversion.
- TextFormatter
Formats a song into a plain text chord sheet
- ChordProParser
Parses a ChordPro chord sheet
ChordSheetParserParses a normal chord sheet
ChordSheetParser is deprecated, please use ChordsOverWordsParser.
ChordsOverWordsParser aims to support any kind of chord, whereas ChordSheetParser lacks support for many variations. Besides that, some chordpro feature have been ported back to ChordsOverWordsParser, which adds some interesting functionality.
- ChordsOverWordsParser
Parses a chords over words sheet into a song
It support "regular" chord sheets:
Am C/G F C Let it be, let it be, let it be, let it be C G F C/E Dm C Whisper words of wisdom, let it be
Additionally, some chordpro features have been "ported back". For example, you can use chordpro directives:
{title: Let it be} {key: C} Chorus 1: Am Let it be
For convenience, you can leave out the brackets:
title: Let it be Chorus 1: Am Let it be
You can even use a markdown style frontmatter separator to separate the header from the song:
title: Let it be key: C --- Chorus 1: Am C/G F C Let it be, let it be, let it be, let it be C G F C/E Dm C Whisper words of wisdom, let it be
ChordsOverWordsParser
is the better version ofChordSheetParser
, which is deprecated.- ParserWarning
Represents a parser warning, currently only used by ChordProParser.
- PegBasedParser
Parses a chords over words sheet
- UltimateGuitarParser
Parses an Ultimate Guitar chord sheet with metadata Inherits from [ChordSheetParser](#ChordSheetParser)
- Chord
Represents a Chord, consisting of a root, suffix (quality) and bass
- ChordSheetSerializer
Serializes a song into een plain object, and deserializes the serialized object back into a [Song](#Song)
- Key
Represents a key, such as Eb (symbol), #3 (numeric) or VII (numeral).
The only function considered public API is
Key.distance
Members
- Font :
string
|null
The font color
- FontSize :
number
The font size
- ALBUM :
string
Artist meta directive. See https://www.chordpro.org/chordpro/directives-artist/
- ARTIST :
string
Capo meta directive. See https://www.chordpro.org/chordpro/directives-capo/
- CAPO :
string
Comment directive. See https://www.chordpro.org/chordpro/directives-comment/
- COMMENT :
string
Composer meta directive. See https://www.chordpro.org/chordpro/directives-composer/
- COMPOSER :
string
Copyright meta directive. See https://www.chordpro.org/chordpro/directives-copyright/
- COPYRIGHT :
string
Duration meta directive. See https://www.chordpro.org/chordpro/directives-duration/
- DURATION :
string
End of bridge directive. See https://chordpro.org/chordpro/directives-env_bridge/
- END_OF_BRIDGE :
string
End of chorus directive. See https://www.chordpro.org/chordpro/directives-env_chorus/
- END_OF_CHORUS :
string
End of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
- END_OF_TAB :
string
End of verse directive. See https://www.chordpro.org/chordpro/directives-env_verse/
- END_OF_VERSE :
string
Key meta directive. See https://www.chordpro.org/chordpro/directives-key/
- KEY :
string
_Key meta directive. Reflects the key as transposed by the capo value See https://www.chordpro.org/chordpro/directives-key/
- _KEY :
string
Lyricist meta directive. See https://www.chordpro.org/chordpro/directives-lyricist/
- LYRICIST :
string
Start of bridge directive. See https://chordpro.org/chordpro/directives-env_bridge/
- START_OF_BRIDGE :
string
Start of chorus directive. See https://www.chordpro.org/chordpro/directives-env_chorus/
- START_OF_CHORUS :
string
Start of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
- START_OF_TAB :
string
Start of verse directive. See https://www.chordpro.org/chordpro/directives-env_verse/
- START_OF_VERSE :
string
Subtitle meta directive. See https://www.chordpro.org/chordpro/directives-subtitle/
- SUBTITLE :
string
Tempo meta directive. See https://www.chordpro.org/chordpro/directives-tempo/
- TEMPO :
string
Time meta directive. See https://www.chordpro.org/chordpro/directives-time/
- TIME :
string
Title meta directive. See https://www.chordpro.org/chordpro/directives-title/
- TITLE :
string
Transpose meta directive. See: https://www.chordpro.org/chordpro/directives-transpose/
- TRANSPOSE :
string
New Key meta directive. See: bettermusic#53
- NEW_KEY :
string
Year meta directive. See https://www.chordpro.org/chordpro/directives-year/
- YEAR :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_chord_legacy/
- CHORDFONT :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_chord_legacy/
- CHORDSIZE :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_chord_legacy/
- CHORDCOLOUR :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_text_legacy/
- TEXTFONT :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_text_legacy/
- TEXTSIZE :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_text_legacy/
- TEXTCOLOUR :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_title_legacy/
- TITLEFONT :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_title_legacy/
- TITLESIZE :
string
Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_title_legacy/
- TITLECOLOUR :
string
Chorus directive. Support repeating an earlier defined section. See https://www.chordpro.org/chordpro/directives-env_chorus/
- defaultCss ⇒
string
Generates basic CSS, scoped within the provided selector, to use with output generated by [HtmlTableFormatter](#HtmlTableFormatter)
- defaultCss ⇒
string
Generates basic CSS, scoped within the provided selector, to use with output generated by [HtmlTableFormatter](#HtmlTableFormatter)
Constants
- ALBUM :
string
Album meta directive. See https://www.chordpro.org/chordpro/directives-album/
- defaultCss :
Object.<string, Object.<string, string>>
Basic CSS, in object style à la useStyles, to use with output generated by {@link }HtmlTableFormatter} For a CSS string see [scopedCss](scopedCss)
- VERSE :
string
Used to mark a paragraph as verse
- VERSE :
string
Used to mark a paragraph as chorus
- CHORUS :
string
Used to mark a paragraph as not containing a line marked with a type
- NONE :
string
Used to mark a paragraph as containing lines with both verse and chorus type
- INDETERMINATE :
string
Used to mark a paragraph as tab
Functions
parseChord(chordString) ⇒Chord
|null
Tries to parse a chord string into a chord
- getCapos(key) ⇒
Object.<string, string>
Returns applicable capos for the provided key
- getKeys(key) ⇒
Array.<string>
Returns applicable keys to transpose to from the provided key
ChordLyricsPair
Represents a chord with the corresponding (partial) lyrics
Kind: global class
- ChordLyricsPair
- new ChordLyricsPair(chords, lyrics)
- .chords :
string
- .lyrics :
string
- .isRenderable() ⇒
boolean
- .clone() ⇒
ChordLyricsPair
new ChordLyricsPair(chords, lyrics)
Initialises a ChordLyricsPair
Param | Type | Default | Description |
---|---|---|---|
chords | string |
The chords |
|
lyrics | string |
null |
The lyrics |
string
chordLyricsPair.chords : The chords
Kind: instance property of ChordLyricsPair
string
chordLyricsPair.lyrics : The lyrics
Kind: instance property of ChordLyricsPair
boolean
chordLyricsPair.isRenderable() ⇒ Indicates whether a ChordLyricsPair should be visible in a formatted chord sheet (except for ChordPro sheets)
Kind: instance method of ChordLyricsPair
ChordLyricsPair
chordLyricsPair.clone() ⇒ Returns a deep copy of the ChordLyricsPair, useful when programmatically transforming a song
Kind: instance method of ChordLyricsPair
Comment
Represents a comment. See https://www.chordpro.org/chordpro/chordpro-file-format-specification/#overview
Kind: global class
- Comment
- .isRenderable() ⇒
boolean
- .clone() ⇒
Comment
- .isRenderable() ⇒
boolean
comment.isRenderable() ⇒ Indicates whether a Comment should be visible in a formatted chord sheet (except for ChordPro sheets)
Kind: instance method of Comment
Comment
comment.clone() ⇒ Returns a deep copy of the Comment, useful when programmatically transforming a song
Kind: instance method of Comment
Font
Line : Represents a line in a chord sheet, consisting of items of type ChordLyricsPair or Tag
Kind: global class
- Line :
Font
- new Line()
- .isEmpty() ⇒
boolean
- .addItem(item)
- .hasRenderableItems() ⇒
boolean
- .clone() ⇒
Line
- .isVerse() ⇒
boolean
- .isChorus() ⇒
boolean
.hasContent() ⇒boolean
new Line()
The chord font that applies to this line. Is derived from the directives:
chordfont
, chordsize
and chordcolour
See: https://www.chordpro.org/chordpro/directives-props_chord_legacy/
boolean
line.isEmpty() ⇒ Indicates whether the line contains any items
Kind: instance method of Line
line.addItem(item)
Adds an item ([ChordLyricsPair](#ChordLyricsPair) or [Tag](#Tag)) to the line
Kind: instance method of Line
Param | Type | Description |
---|---|---|
item | ChordLyricsPair | Tag |
The item to be added |
boolean
line.hasRenderableItems() ⇒ Indicates whether the line contains items that are renderable
Kind: instance method of Line
Line
line.clone() ⇒ Returns a deep copy of the line and all of its items
Kind: instance method of Line
boolean
line.isVerse() ⇒ Indicates whether the line type is [VERSE](#VERSE)
Kind: instance method of Line
boolean
line.isChorus() ⇒ Indicates whether the line type is [CHORUS](#CHORUS)
Kind: instance method of Line
line.hasContent() ⇒ boolean
boolean
Deprecated
Indicates whether the line contains items that are renderable. Please use [hasRenderableItems](hasRenderableItems)
Kind: instance method of Line
Metadata
Stores song metadata. Properties can be accessed using the get() method:
const metadata = new Metadata({ author: 'John' }); metadata.get('author') // => 'John'
See [get](#Metadata+get)
Kind: global class
- Metadata
- .get(prop) ⇒
Array.<String>
|String
- .clone() ⇒
Metadata
- .get(prop) ⇒
Array.<String>
| String
metadata.get(prop) ⇒ Reads a metadata value by key. This method supports simple value lookup, as well as fetching single array values.
This method deprecates direct property access, eg: metadata['author']
Examples:
const metadata = new Metadata({ lyricist: 'Pete', author: ['John', 'Mary'] }); metadata.get('lyricist') // => 'Pete' metadata.get('author') // => ['John', 'Mary'] metadata.get('author.1') // => 'John' metadata.get('author.2') // => 'Mary'
Using a negative index will start counting at the end of the list:
const metadata = new Metadata({ lyricist: 'Pete', author: ['John', 'Mary'] }); metadata.get('author.-1') // => 'Mary' metadata.get('author.-2') // => 'John'
Kind: instance method of Metadata
Returns: Array.<String>
| String
-
the metadata value(s). If there is only one value, it will return a String, else it returns an array of strings.
Param | Description |
---|---|
prop | the property name |
Metadata
metadata.clone() ⇒ Returns a deep clone of this Metadata object
Kind: instance method of Metadata
Returns: Metadata
-
the cloned Metadata object
Paragraph
Represents a paragraph of lines in a chord sheet
Kind: global class
- Paragraph
- .addLine :
Array.<Line>
- .type ⇒
string
- .hasRenderableItems() ⇒
boolean
- .addLine :
Array.<Line>
paragraph.addLine : The [Line](#Line) items of which the paragraph consists
Kind: instance property of Paragraph
string
paragraph.type ⇒ Tries to determine the common type for all lines. If the types for all lines are equal, it returns that type. If not, it returns [INDETERMINATE](#INDETERMINATE)
Kind: instance property of Paragraph
boolean
paragraph.hasRenderableItems() ⇒ Indicates whether the paragraph contains lines with renderable items.
Kind: instance method of Paragraph
See: Line.hasRenderableItems
Song
Represents a song in a chord sheet. Currently a chord sheet can only have one song.
Kind: global class
- Song
- new Song(metadata)
- .bodyLines ⇒
Array.<Line>
- .bodyParagraphs ⇒
Array.<Paragraph>
- .paragraphs :
Array.<Paragraph>
- .expandedBodyParagraphs :
Array.<Paragraph>
.metaData ⇒- .clone() ⇒
Song
- .setKey(key) ⇒
Song
- .setCapo(capo) ⇒
Song
- .transpose(delta, [options]) ⇒
Song
- .transposeUp([options]) ⇒
Song
- .transposeDown([options]) ⇒
Song
- .changeKey(newKey) ⇒
Song
- .changeMetadata(name, value)
- .mapItems(func) ⇒
Song
- .mapLines(func) ⇒
Song
new Song(metadata)
Creates a new {Song} instance
Param | Type | Description |
---|---|---|
metadata | Object | Metadata |
predefined metadata |
Array.<Line>
song.bodyLines ⇒ Returns the song lines, skipping the leading empty lines (empty as in not rendering any content). This is useful if you want to skip the "header lines": the lines that only contain meta data.
Kind: instance property of Song
Returns: Array.<Line>
-
The song body lines
Array.<Paragraph>
song.bodyParagraphs ⇒ Returns the song paragraphs, skipping the paragraphs that only contain empty lines (empty as in not rendering any content)
Kind: instance property of Song
See: bodyLines
Array.<Paragraph>
song.paragraphs : The [Paragraph](#Paragraph) items of which the song consists
Kind: instance property of Song
Array.<Paragraph>
song.expandedBodyParagraphs : The body paragraphs of the song, with any {chorus}
tag expanded into the targetted chorus
Kind: instance property of Song
song.metaData ⇒
Deprecated
The song's metadata. Please use [metadata](metadata) instead.
Kind: instance property of Song
Returns:
Metadata The metadata
Song
song.clone() ⇒ Returns a deep clone of the song
Kind: instance method of Song
Returns: Song
-
The cloned song
Song
song.setKey(key) ⇒ Returns a copy of the song with the key value set to the specified key. It changes:
- the value for
key
in the [metadata](metadata) set - any existing
key
directive
Kind: instance method of Song
Returns: Song
-
The changed song
Param | Type | Description |
---|---|---|
key | number | null |
the key. Passing
|
Song
song.setCapo(capo) ⇒ Returns a copy of the song with the key value set to the specified capo. It changes:
- the value for
capo
in the [metadata](metadata) set - any existing
capo
directive
Kind: instance method of Song
Returns: Song
-
The changed song
Param | Type | Description |
---|---|---|
capo | number | null |
the capo. Passing
|
Song
song.transpose(delta, [options]) ⇒ Transposes the song by the specified delta. It will:
- transpose all chords, see: [transpose](#Chord+transpose)
- transpose the song key in [metadata](metadata)
- update any existing
key
directive
Kind: instance method of Song
Returns: Song
-
The transposed song
Param | Type | Default | Description |
---|---|---|---|
delta | number |
The number of semitones (positive or negative) to transpose with |
|
[options] | Object |
{} |
options |
[options.normalizeChordSuffix] | boolean |
false |
whether to normalize the chord suffixes after transposing |
Song
song.transposeUp([options]) ⇒ Transposes the song up by one semitone. It will:
- transpose all chords, see: [transpose](#Chord+transpose)
- transpose the song key in [metadata](metadata)
- update any existing
key
directive
Kind: instance method of Song
Returns: Song
-
The transposed song
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
{} |
options |
[options.normalizeChordSuffix] | boolean |
false |
whether to normalize the chord suffixes after transposing |
Song
song.transposeDown([options]) ⇒ Transposes the song down by one semitone. It will:
- transpose all chords, see: [transpose](#Chord+transpose)
- transpose the song key in [metadata](metadata)
- update any existing
key
directive
Kind: instance method of Song
Returns: Song
-
The transposed song
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
{} |
options |
[options.normalizeChordSuffix] | boolean |
false |
whether to normalize the chord suffixes after transposing |
Song
song.changeKey(newKey) ⇒ Returns a copy of the song with the key set to the specified key. It changes:
- the value for
key
in the [metadata](metadata) set - any existing
key
directive - all chords, those are transposed according to the distance between the current and the new key
Kind: instance method of Song
Returns: Song
-
The changed song
Param | Type | Description |
---|---|---|
newKey | string |
The new key. |
song.changeMetadata(name, value)
Returns a copy of the song with the directive value set to the specified value.
- when there is a matching directive in the song, it will update the directive
- when there is no matching directive, it will be inserted
If
value
isnull
it will act as a delete, any directive matchingname
will be removed.
Kind: instance method of Song
Param | Type | Description |
---|---|---|
name | string |
The directive name |
value | string | null |
The value to set, or |
Song
song.mapItems(func) ⇒ Change the song contents inline. Return a new [Item](Item) to replace it. Return null
to remove it.
Kind: instance method of Song
Returns: Song
-
the changed song
Param | Type | Description |
---|---|---|
func | MapItemsCallback |
the callback function |
Example
// transpose all chords:
song.mapItems((item) => {
if (item instanceof ChordLyricsPair) {
return item.transpose(2, 'D');
}
return item;
});
Song
song.mapLines(func) ⇒ Change the song contents inline. Return a new [Line](#Line) to replace it. Return null
to remove it.
Kind: instance method of Song
Returns: Song
-
the changed song
Param | Type | Description |
---|---|---|
func | MapLinesCallback |
the callback function |
Example
// remove lines with only Tags:
song.mapLines((line) => {
if (line.items.every(item => item instanceof Tag)) {
return null;
}
return line;
});
Tag
Represents a tag/directive. See https://www.chordpro.org/chordpro/chordpro-directives/
Kind: global class
- Tag
- .name :
string
- .originalName :
string
- .value :
string
- .hasValue() ⇒
boolean
- .isRenderable() ⇒
boolean
- .hasRenderableLabel()
- .isMetaTag() ⇒
boolean
- .clone() ⇒
Tag
- .name :
string
tag.name : The tag full name. When the original tag used the short name, name
will return the full name.
Kind: instance property of Tag
string
tag.originalName : The original tag name that was used to construct the tag.
Kind: instance property of Tag
string
tag.value : The tag value
Kind: instance property of Tag
boolean
tag.hasValue() ⇒ Checks whether the tag value is a non-empty string.
Kind: instance method of Tag
boolean
tag.isRenderable() ⇒ Checks whether the tag is usually rendered inline. It currently only applies to comment tags.
Kind: instance method of Tag
tag.hasRenderableLabel()
Check whether this tag's label (if any) should be rendered, as applicable to tags like
start_of_verse
and start_of_chorus
.
See https://chordpro.org/chordpro/directives-env_chorus/, https://chordpro.org/chordpro/directives-env_verse/,
https://chordpro.org/chordpro/directives-env_bridge/, https://chordpro.org/chordpro/directives-env_tab/
Kind: instance method of Tag
boolean
tag.isMetaTag() ⇒ Checks whether the tag is either a standard meta tag or a custom meta directive ({x_some_name}
)
Kind: instance method of Tag
Tag
tag.clone() ⇒ Returns a clone of the tag.
Kind: instance method of Tag
Returns: Tag
-
The cloned tag
ChordProFormatter
Formats a song into a ChordPro chord sheet
string
chordProFormatter.format(song) ⇒ Formats a song into a ChordPro chord sheet.
Kind: instance method of ChordProFormatter
Returns: string
-
The ChordPro string
Param | Type | Description |
---|---|---|
song | Song |
The song to be formatted |
ChordsOverWordsFormatter
Formats a song into a plain text chord sheet
string
chordsOverWordsFormatter.format(song) ⇒ Formats a song into a plain text chord sheet
Kind: instance method of ChordsOverWordsFormatter
Returns: string
-
the chord sheet
Param | Type | Description |
---|---|---|
song | Song |
The song to be formatted |
Formatter
Base class for all formatters, taking care of receiving a configuration wrapping that inside a Configuration object
new Formatter([configuration])
Instantiate
Param | Type | Default | Description |
---|---|---|---|
[configuration] | Object |
{} |
options |
[configuration.evaluate] | boolean |
false |
Whether or not to evaluate meta expressions. For more info about meta expressions, see: https://bit.ly/2SC9c2u |
[configuration.metadata] | object |
{} |
|
[configuration.metadata.separator] | string |
"", "" |
The separator to be used when rendering a metadata value that has multiple values. See: https://bit.ly/2SC9c2u |
[configuration.key] | Key | string |
|
The key to use for rendering. The chord sheet will be transposed from the song's original key (as indicated by the |
[configuration.expandChorusDirective] | boolean |
false |
Whether or not to expand |
[configuration.useUnicodeModifiers] | boolean |
false |
Whether or not to use unicode flat and sharp symbols. |
[configuration.normalizeChords] | boolean |
true |
Whether or not to automatically normalize chords |
HtmlDivFormatter
Formats a song into HTML. It uses DIVs to align lyrics with chords, which makes it useful for responsive web pages.
HtmlFormatter
Acts as a base class for HTML formatters
Kind: global class
- HtmlFormatter
- instance
- .cssObject ⇒
Object.<string, Object.<string, string>>
- .format(song) ⇒
string
- .cssString(scope) ⇒
string
- .cssObject ⇒
- static
- instance
Object.<string, Object.<string, string>>
htmlFormatter.cssObject ⇒ Basic CSS, in object style à la useStyles, to use with the HTML output For a CSS string see [cssString](cssString)
Example:
'.paragraph': {
marginBottom: '1em'
}
Kind: instance property of HtmlFormatter
Returns: Object.<string, Object.<string, string>>
-
the CSS object
string
htmlFormatter.format(song) ⇒ Formats a song into HTML.
Kind: instance method of HtmlFormatter
Returns: string
-
The HTML string
Param | Type | Description |
---|---|---|
song | Song |
The song to be formatted |
string
htmlFormatter.cssString(scope) ⇒ Generates basic CSS, optionally scoped within the provided selector, to use with the HTML output
For example, execute cssString('.chordSheetViewer') will result in CSS like:
.chordSheetViewer .paragraph {
margin-bottom: 1em;
}
Kind: instance method of HtmlFormatter
Returns: string
-
the CSS string
Param | Description |
---|---|
scope | the CSS scope to use, for example |
HtmlFormatter.cssString()
Deprecated
Generates basic CSS, optionally scoped within the provided selector, to use with the HTML output
Kind: static method of HtmlFormatter
HtmlFormatter.cssObject()
Deprecated
Basic CSS, in object style à la useStyles, to use with the HTML output
Kind: static method of HtmlFormatter
HtmlTableFormatter
Formats a song into HTML. It uses TABLEs to align lyrics with chords, which makes the HTML for things like PDF conversion.
TextFormatter
Formats a song into a plain text chord sheet
string
textFormatter.format(song) ⇒ Formats a song into a plain text chord sheet
Kind: instance method of TextFormatter
Returns: string
-
the chord sheet
Param | Type | Description |
---|---|---|
song | Song |
The song to be formatted |
ChordProParser
Parses a ChordPro chord sheet
Song
chordProParser.parse(chordProChordSheet) ⇒ Parses a ChordPro chord sheet into a song
Kind: instance method of ChordProParser
Returns: Song
-
The parsed song
Param | Type | Description |
---|---|---|
chordProChordSheet | string |
the ChordPro chord sheet |
ChordSheetParser
Deprecated
Parses a normal chord sheet
ChordSheetParser is deprecated, please use ChordsOverWordsParser.
ChordsOverWordsParser aims to support any kind of chord, whereas ChordSheetParser lacks support for many variations. Besides that, some chordpro feature have been ported back to ChordsOverWordsParser, which adds some interesting functionality.
Kind: global class
new ChordSheetParser([options])
Instantiate a chord sheet parser ChordSheetParser is deprecated, please use ChordsOverWordsParser.
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
{} |
options |
[options.preserveWhitespace] | boolean |
true |
whether to preserve trailing whitespace for chords |
Song
chordSheetParser.parse(chordSheet, [options]) ⇒ Parses a chord sheet into a song
Kind: instance method of ChordSheetParser
Returns: Song
-
The parsed song
Param | Type | Default | Description |
---|---|---|---|
chordSheet | string |
The ChordPro chord sheet |
|
[options] | Object |
{} |
Optional parser options |
[options.song] | Song |
|
The Song to store the song data in |
ChordsOverWordsParser
Parses a chords over words sheet into a song
It support "regular" chord sheets:
Am C/G F C
Let it be, let it be, let it be, let it be
C G F C/E Dm C
Whisper words of wisdom, let it be
Additionally, some chordpro features have been "ported back". For example, you can use chordpro directives:
{title: Let it be}
{key: C}
Chorus 1:
Am
Let it be
For convenience, you can leave out the brackets:
title: Let it be
Chorus 1:
Am
Let it be
You can even use a markdown style frontmatter separator to separate the header from the song:
title: Let it be
key: C
---
Chorus 1:
Am C/G F C
Let it be, let it be, let it be, let it be
C G F C/E Dm C
Whisper words of wisdom, let it be
ChordsOverWordsParser
is the better version of ChordSheetParser
, which is deprecated.
Song
chordsOverWordsParser.parse(chordsOverWordsSheet) ⇒ Parses a chords over words sheet into a song
Kind: instance method of ChordsOverWordsParser
Returns: Song
-
The parsed song
Param | Type | Description |
---|---|---|
chordsOverWordsSheet | string |
the chords over words sheet |
ParserWarning
Represents a parser warning, currently only used by ChordProParser.
string
parserWarning.toString() ⇒ Returns a stringified version of the warning
Kind: instance method of ParserWarning
Returns: string
-
The string warning
PegBasedParser
Parses a chords over words sheet
Array.<ParserWarning>
pegBasedParser.warnings : All warnings raised during parsing the chord sheet
Kind: instance property of PegBasedParser
UltimateGuitarParser
Parses an Ultimate Guitar chord sheet with metadata Inherits from [ChordSheetParser](#ChordSheetParser)
Chord
Represents a Chord, consisting of a root, suffix (quality) and bass
Kind: global class
- Chord
- instance
- .clone() ⇒
Chord
- .toChordSymbol([referenceKey]) ⇒
Chord
- .toChordSymbolString([referenceKey]) ⇒
string
- .isChordSymbol() ⇒
boolean
- .toNumeric([referenceKey]) ⇒
Chord
- .toNumeral([referenceKey]) ⇒
Chord
- .toNumeralString([referenceKey]) ⇒
string
- .isNumeric() ⇒
boolean
- .toNumericString([referenceKey]) ⇒
string
- .isNumeral() ⇒
boolean
- .toString([configuration]) ⇒
string
- .normalize([key], [options]) ⇒
Chord
- .useModifier(newModifier) ⇒
Chord
- .transposeUp() ⇒
Chord
- .transposeDown() ⇒
Chord
- .transpose(delta) ⇒
Chord
- .clone() ⇒
- static
- .parse(chordString) ⇒
Chord
|null
- .parse(chordString) ⇒
- instance
Chord
chord.clone() ⇒ Returns a deep copy of the chord
Kind: instance method of Chord
Chord
chord.toChordSymbol([referenceKey]) ⇒ Converts the chord to a chord symbol, using the supplied key as a reference.
For example, a numeric chord #4
with reference key E
will return the chord symbol A#
.
When the chord is already a chord symbol, it will return a clone of the object.
Kind: instance method of Chord
Returns: Chord
-
the chord symbol
Param | Type | Default | Description |
---|---|---|---|
[referenceKey] | Key | string | null |
|
the reference key. The key is required when converting a numeric or numeral. |
string
chord.toChordSymbolString([referenceKey]) ⇒ Converts the chord to a chord symbol string, using the supplied key as a reference.
For example, a numeric chord #4
with reference key E
will return the chord symbol A#
.
When the chord is already a chord symbol, it will return a string version of the chord.
Kind: instance method of Chord
Returns: string
-
the chord symbol string
See: {toChordSymbol}
Param | Type | Default | Description |
---|---|---|---|
[referenceKey] | Key | string | null |
|
the reference key. The key is required when converting a numeric or numeral. |
boolean
chord.isChordSymbol() ⇒ Determines whether the chord is a chord symbol
Kind: instance method of Chord
Chord
chord.toNumeric([referenceKey]) ⇒ Converts the chord to a numeric chord, using the supplied key as a reference. For example, a chord symbol A# with reference key E will return the numeric chord #4.
Kind: instance method of Chord
Returns: Chord
-
the numeric chord
Param | Type | Default | Description |
---|---|---|---|
[referenceKey] | Key | string | null |
|
the reference key. The key is required when converting a chord symbol |
Chord
chord.toNumeral([referenceKey]) ⇒ Converts the chord to a numeral chord, using the supplied key as a reference. For example, a chord symbol A# with reference key E will return the numeral chord #IV.
Kind: instance method of Chord
Returns: Chord
-
the numeral chord
Param | Type | Default | Description |
---|---|---|---|
[referenceKey] | Key | string | null |
|
the reference key. The key is required when converting a chord symbol |
string
chord.toNumeralString([referenceKey]) ⇒ Converts the chord to a numeral chord string, using the supplied kye as a reference. For example, a chord symbol A# with reference key E will return the numeral chord #4.
Kind: instance method of Chord
Returns: string
-
the numeral chord string
See: {toNumeral}
Param | Type | Default | Description |
---|---|---|---|
[referenceKey] | Key | string | null |
|
the reference key. The key is required when converting a chord symbol |
boolean
chord.isNumeric() ⇒ Determines whether the chord is numeric
Kind: instance method of Chord
string
chord.toNumericString([referenceKey]) ⇒ Converts the chord to a numeric chord string, using the supplied kye as a reference. For example, a chord symbol A# with reference key E will return the numeric chord #4.
Kind: instance method of Chord
Returns: string
-
the numeric chord string
See: {toNumeric}
Param | Type | Default | Description |
---|---|---|---|
[referenceKey] | Key | string | null |
|
the reference key. The key is required when converting a chord symbol |
boolean
chord.isNumeral() ⇒ Determines whether the chord is a numeral
Kind: instance method of Chord
string
chord.toString([configuration]) ⇒ Converts the chord to a string, eg Esus4/G#
or 1sus4/#3
Kind: instance method of Chord
Returns: string
-
the chord string
Param | Type | Default | Description |
---|---|---|---|
[configuration] | Object |
{} |
options |
[configuration.useUnicodeModifier] | boolean |
false |
Whether or not to use unicode modifiers. This will make |
Chord
chord.normalize([key], [options]) ⇒ Normalizes the chord root and bass notes:
- Fb becomes E
- Cb becomes B
- B# becomes C
- E# becomes F
- 4b becomes 3
- 1b becomes 7
- 7# becomes 1
- 3# becomes 4
Besides that it normalizes the suffix if normalizeSuffix
is true
.
For example, sus2
becomes 2
, sus4
becomes sus
.
All suffix normalizations can be found in src/normalize_mappings/suffix-mapping.txt
.
When the chord is minor, bass notes are normalized off of the relative major
of the root note. For example, Em/A#
becomes Em/Bb
.
Kind: instance method of Chord
Returns: Chord
-
the normalized chord
Param | Type | Default | Description |
---|---|---|---|
[key] | Key | string |
|
the key to normalize to |
[options] | Object |
{} |
options |
[options.normalizeSuffix] | boolean |
true |
whether to normalize the chord suffix after transposing |
Chord
chord.useModifier(newModifier) ⇒ Switches to the specified modifier
Kind: instance method of Chord
Returns: Chord
-
the new, changed chord
Param | Description |
---|---|
newModifier | the modifier to use: |
Chord
chord.transposeUp() ⇒ Transposes the chord up by 1 semitone. Eg. A becomes A#, Eb becomes E
Kind: instance method of Chord
Returns: Chord
-
the new, transposed chord
Chord
chord.transposeDown() ⇒ Transposes the chord down by 1 semitone. Eg. A# becomes A, E becomes Eb
Kind: instance method of Chord
Returns: Chord
-
the new, transposed chord
Chord
chord.transpose(delta) ⇒ Transposes the chord by the specified number of semitones
Kind: instance method of Chord
Returns: Chord
-
the new, transposed chord
Param | Description |
---|---|
delta | de number of semitones |
Chord
| null
Chord.parse(chordString) ⇒ Tries to parse a chord string into a chord
Any leading or trailing whitespace is removed first, so a chord like \n E/G# \r
is valid.
Kind: static method of Chord
Param | Description |
---|---|
chordString | the chord string, eg |
ChordSheetSerializer
Serializes a song into een plain object, and deserializes the serialized object back into a [Song](#Song)
Kind: global class
chordSheetSerializer.serialize() ⇒
Serializes the chord sheet to a plain object, which can be converted to any format like JSON, XML etc Can be deserialized using [deserialize](deserialize)
Kind: instance method of ChordSheetSerializer
Returns:
object A plain JS object containing all chord sheet data
Song
chordSheetSerializer.deserialize(serializedSong) ⇒ Deserializes a song that has been serialized using [serialize](serialize)
Kind: instance method of ChordSheetSerializer
Returns: Song
-
The deserialized song
Param | Type | Description |
---|---|---|
serializedSong | object |
The serialized song |
Key
Represents a key, such as Eb (symbol), #3 (numeric) or VII (numeral).
The only function considered public API is Key.distance
number
Key.distance(oneKey, otherKey) ⇒ Calculates the distance in semitones between one key and another.
Kind: static method of Key
Returns: number
-
the distance in semitones
Param | Type | Description |
---|---|---|
oneKey | Key | string |
the key |
otherKey | Key | string |
the other key |
string
| null
Font : The font color
string
font.toCssString() ⇒ Converts the font, size and color to a CSS string.
If possible, font and size are combined to the font
shorthand.
If font
contains double quotes ("
) those will be converted to single quotes ('
).
Kind: instance method of Font
Returns: string
-
The CSS string
Example
// Returns "font-family: 'Times New Roman'"
new Font({ font: '"Times New Roman"' }).toCssString()
Example
// Returns "color: red; font-family: Verdana"
new Font({ font: 'Verdana', colour: 'red' }).toCssString()
Example
// Returns "font: 30px Verdana"
new Font({ font: 'Verdana', size: '30' }).toCssString()
Example
// Returns "color: blue; font: 30% Verdana"
new Font({ font: 'Verdana', size: '30%', colour: 'blue' }).toCssString()
number
FontSize : The font size
string
fontSize.toString() ⇒ Stringifies the font size by concatenating size and unit
Kind: instance method of FontSize
Returns: string
-
The font size
Example
// Returns "30px"
new FontSize(30, 'px').toString()
Example
// Returns "120%"
new FontSize(120, '%').toString()
string
ALBUM : Artist meta directive. See https://www.chordpro.org/chordpro/directives-artist/
string
ARTIST : Capo meta directive. See https://www.chordpro.org/chordpro/directives-capo/
string
CAPO : Comment directive. See https://www.chordpro.org/chordpro/directives-comment/
string
COMMENT : Composer meta directive. See https://www.chordpro.org/chordpro/directives-composer/
string
COMPOSER : Copyright meta directive. See https://www.chordpro.org/chordpro/directives-copyright/
string
COPYRIGHT : Duration meta directive. See https://www.chordpro.org/chordpro/directives-duration/
string
DURATION : End of bridge directive. See https://chordpro.org/chordpro/directives-env_bridge/
string
END_OF_BRIDGE : End of chorus directive. See https://www.chordpro.org/chordpro/directives-env_chorus/
string
END_OF_CHORUS : End of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
string
END_OF_TAB : End of verse directive. See https://www.chordpro.org/chordpro/directives-env_verse/
string
END_OF_VERSE : Key meta directive. See https://www.chordpro.org/chordpro/directives-key/
string
KEY : _Key meta directive. Reflects the key as transposed by the capo value See https://www.chordpro.org/chordpro/directives-key/
string
_KEY : Lyricist meta directive. See https://www.chordpro.org/chordpro/directives-lyricist/
string
LYRICIST : Start of bridge directive. See https://chordpro.org/chordpro/directives-env_bridge/
string
START_OF_BRIDGE : Start of chorus directive. See https://www.chordpro.org/chordpro/directives-env_chorus/
string
START_OF_CHORUS : Start of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
string
START_OF_TAB : Start of verse directive. See https://www.chordpro.org/chordpro/directives-env_verse/
string
START_OF_VERSE : Subtitle meta directive. See https://www.chordpro.org/chordpro/directives-subtitle/
string
SUBTITLE : Tempo meta directive. See https://www.chordpro.org/chordpro/directives-tempo/
string
TEMPO : Time meta directive. See https://www.chordpro.org/chordpro/directives-time/
string
TIME : Title meta directive. See https://www.chordpro.org/chordpro/directives-title/
string
TITLE : Transpose meta directive. See: https://www.chordpro.org/chordpro/directives-transpose/
string
TRANSPOSE : New Key meta directive. See: bettermusic#53
string
NEW_KEY : Year meta directive. See https://www.chordpro.org/chordpro/directives-year/
string
YEAR : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_chord_legacy/
string
CHORDFONT : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_chord_legacy/
string
CHORDSIZE : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_chord_legacy/
string
CHORDCOLOUR : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_text_legacy/
string
TEXTFONT : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_text_legacy/
string
TEXTSIZE : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_text_legacy/
string
TEXTCOLOUR : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_title_legacy/
string
TITLEFONT : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_title_legacy/
string
TITLESIZE : Chordfont directive. See https://www.chordpro.org/chordpro/directives-props_title_legacy/
string
TITLECOLOUR : Chorus directive. Support repeating an earlier defined section. See https://www.chordpro.org/chordpro/directives-env_chorus/
string
defaultCss ⇒ Generates basic CSS, scoped within the provided selector, to use with output generated by [HtmlTableFormatter](#HtmlTableFormatter)
Kind: global variable
Returns: string
-
the CSS string
Param | Description |
---|---|
scope | the CSS scope to use, for example |
string
defaultCss ⇒ Generates basic CSS, scoped within the provided selector, to use with output generated by [HtmlTableFormatter](#HtmlTableFormatter)
Kind: global variable
Returns: string
-
the CSS string
Param | Description |
---|---|
scope | the CSS scope to use, for example |
string
ALBUM : Album meta directive. See https://www.chordpro.org/chordpro/directives-album/
Object.<string, Object.<string, string>>
defaultCss : Basic CSS, in object style à la useStyles, to use with output generated by {@link }HtmlTableFormatter} For a CSS string see [scopedCss](scopedCss)
string
VERSE : Used to mark a paragraph as verse
string
VERSE : Used to mark a paragraph as chorus
string
CHORUS : Used to mark a paragraph as not containing a line marked with a type
string
NONE : Used to mark a paragraph as containing lines with both verse and chorus type
string
INDETERMINATE : Used to mark a paragraph as tab
parseChord(chordString) ⇒ Chord
| null
Chord
| null
Deprecated
Tries to parse a chord string into a chord
Kind: global function
Param | Description |
---|---|
chordString | the chord string, eg Esus4/G# or 1sus4/#3 |
Object.<string, string>
getCapos(key) ⇒ Returns applicable capos for the provided key
Kind: global function
Returns: Object.<string, string>
-
The available capos, where the keys are capo numbers and the values are the effective key for that capo.
Param | Type | Description |
---|---|---|
key | Key | string |
The key to get capos for |
Array.<string>
getKeys(key) ⇒ Returns applicable keys to transpose to from the provided key
Kind: global function
Returns: Array.<string>
-
The available keys
Param | Type | Description |
---|---|---|
key | Key | string |
The key to get keys for |