songbook-chordpro
v0.3.0
Published
Library for parsing chordpro song format
Readme
Songbook Chordpro
Simple typescript library for parsing songs in chordpro format.
You can view the package on npm.
For a react component that uses the library see: songbook-chordpro-view.
Installation
Using npm:
npm i songbook-chordproUsing yarn:
yarn add songbook-chordpro
Usage
To parse the chordpro string to a common format use:
import parseSong from 'songbook-chordpro';
const content = '...chordpro string';
const song = parseSong(content);Grid sections
ChordPro grid environments are parsed as grid sections with tokenized rows:
import parseSong from 'songbook-chordpro';
const song = parseSong(`
{start_of_grid: Intro}
| C . . . | G . . . |
{end_of_grid}
`.trim());
const grid = song.sections[0];
if (grid.type === 'grid') {
console.log(grid.label);
// Intro
console.log(grid.rows[0].tokens);
// [
// { type: 'bar', symbol: '|' },
// { type: 'chord', chord: 'C' },
// { type: 'space', symbol: '.' },
// { type: 'space', symbol: '.' },
// { type: 'space', symbol: '.' },
// { type: 'bar', symbol: '|' },
// { type: 'chord', chord: 'G' },
// { type: 'space', symbol: '.' },
// { type: 'space', symbol: '.' },
// { type: 'space', symbol: '.' },
// { type: 'bar', symbol: '|' },
// ]
}