Skip to content

Instantly share code, notes, and snippets.

@xavriley
Last active May 24, 2023 21:16
Show Gist options
  • Save xavriley/8f907811d71abea8aa3f31db8b1535bc to your computer and use it in GitHub Desktop.
Save xavriley/8f907811d71abea8aa3f31db8b1535bc to your computer and use it in GitHub Desktop.
Chord Parsing CLI example
#!/usr/bin/env node
const yargs = require("yargs");
const chordSymbolLib = require("chord-symbol");
const parseChord = chordSymbolLib.chordParserFactory();
const renderChord = chordSymbolLib.chordRendererFactory({ useShortNamings: true });
const options = yargs
.usage("Usage: -c <inputChord>")
.option("c", { alias: "inputChord", describe: "Chord symbol as a string", type: "string", demandOption: true })
.argv;
const chord = parseChord(options.inputChord);
console.log(chord);
$ ./chord-parser -c Cmaj7
{
input: {
symbol: 'Cmaj7',
rootNote: 'C',
descriptor: 'maj7',
parsableDescriptor: 'maj7',
modifiers: [ 'add7' ],
notationSystem: 'english'
},
normalized: {
intervals: [ '1', '3', '5', '7' ],
semitones: [ 0, 4, 7, 11 ],
intents: { major: true, eleventh: false, alt: false },
rootNote: 'C',
quality: 'major7',
isSuspended: false,
extensions: [],
alterations: [],
adds: [],
omits: [],
notes: [ 'C', 'E', 'G', 'B' ]
},
formatted: {
rootNote: 'C',
bassNote: undefined,
descriptor: 'ma7',
chordChanges: [],
symbol: 'Cma7'
},
parserConfiguration: {}
}
```
$ npm install -g pkg # https://github.com/vercel/pkg
$ npm install -g chord-symbol # https://github.com/no-chris/chord-symbol
$ pkg chord-parser.js
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment