Registry / data / daccord

daccord

JSON →
library2.0.1jsnpmunverified

d'accord is a focused JavaScript module designed for parsing complex music chord symbols, encompassing both Jazz and Classical notation standards. It accurately interprets a wide range of chords, from basic power chords like 'D#5' to sophisticated real book entries such as 'G7#5' and 'Dm7b5', or even intricate structures like 'Fsus4maj#11' or 'Cm13b5#9'. Crucially, d'accord only parses the chord suffix (the part without the root note) and returns an array of relative intervals (e.g., ['P1', 'm3', 'd5', 'm7']) rather than absolute notes. This design makes it a versatile tool for music theory applications, often used in conjunction with libraries like Teoria to construct full chords from a specified root note. The current stable version is 2.0.1. Release cadence is not explicitly stated but implies a steady maintenance, with major version updates indicating significant changes. Its key differentiator is its robust and forgiving parsing logic for a vast array of chord suffixes, specifically designed to output relative intervals for maximal flexibility in musical analysis and composition.

npm install daccord
INSTALL
IMPORT
SIG · DACCORD
D
daccord
datajavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

daccord
import daccord from 'daccord'
import { daccord } from 'daccord'
The primary export of the 'daccord' package is a default function for parsing chord symbols. While `require` is shown in older examples, ESM is also supported.
daccord
const daccord = require('daccord')
Standard CommonJS `require` syntax, as illustrated in the package's README and for compatibility in Node.js environments.

Demonstrates parsing a chord symbol into relative intervals, combining it with Teoria to form absolute notes from a root, and includes robust error handling for invalid inputs.

import daccord from 'daccord'; import teoria from 'teoria'; // Create a root note, for example C4, using the Teoria library const root = teoria.note('C4'); // Parse a complex chord symbol (e.g., minor major seventh) into relative intervals const intervals = daccord('m(maj7)'); // Map the relative intervals to absolute notes using the chosen root note // This will return an array of Teoria Note objects const notes = intervals.map(intervalStr => root.interval(intervalStr)); // To get the string representation of the resulting notes: const noteStrings = notes.map(note => note.toString()); console.log(`Chord 'm(maj7)' from C4: ${noteStrings.join(', ')}`); // Example with error handling for unparsable chord strings try { // This will throw an error as 'invalidchord' is not a recognized symbol daccord('invalidchord'); } catch (error) { // The error object thrown for invalid input has a 'name' property of 'ParseError' if (error.name === 'ParseError') { console.error(`Parsing error: ${error.message} at token '${error.token}' (index ${error.index})`); } else { console.error(`An unexpected error occurred: ${error.message}`); } }
Debug
Known issues
gotchad'accord exclusively parses the chord suffix (e.g., 'm7b5') and outputs relative intervals (e.g., ['P1', 'm3', 'd5', 'm7']), not absolute notes. It explicitly ignores any root note provided in the input string (e.g., 'C' in 'Cm7').
fix
To construct full chords with specific root notes, integrate d'accord with a music theory library like Teoria, using `teoria.note('C4').interval(intervalString)` to apply the parsed intervals to a chosen root.
affects: >=1.0.0
gotchaWhen an input `chordstring` is unparsable, d'accord throws a `ParseError` object with specific details (message, title, token, index). It does not return `null` or an empty array.
fix
Implement explicit `try...catch` blocks around all calls to `daccord(chordstring)`. Check `error.name === 'ParseError'` within the catch block to handle parsing failures gracefully and extract relevant error information.
affects: >=1.0.0
breakingUpgrading from d'accord 1.x to 2.x involves a major version bump, which typically indicates breaking changes in the API surface, internal implementation, or parsing behavior. Direct drop-in replacement may lead to errors.
fix
Always review the official changelog or release notes for d'accord when migrating between major versions (e.g., 1.x to 2.x) to understand specific breaking changes and necessary code adjustments.
affects: >=2.0.0
Errors
Common errors & fixes
ParseError: Invalid chord string: 'unknownchord' at token 'unknownchord' (index 0)
The input string provided to `daccord()` does not conform to any recognized chord symbol pattern, leading to a parsing failure.
fix
Ensure that the `chordstring` argument is a valid musical chord suffix (e.g., 'maj7', 'm7b5', 'sus4'). Always wrap `daccord()` calls in a `try...catch` block to handle these expected parsing errors gracefully.
TypeError: root.interval is not a function (when combining with Teoria)
This error typically occurs when the `teoria` library is not correctly installed, imported, or when the `root` variable is not a valid `teoria.note` object.
fix
Verify that `teoria` is installed (`npm install teoria`), correctly imported (`import teoria from 'teoria';` or `const teoria = require('teoria');`), and that `root` is initialized using `teeria.note('C4')` (or another valid note string) before attempting to call `.interval()` on it.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
teoriaoptionalCommonly used in conjunction to construct full notes from parsed intervals and a root note.
Agent activity
9 hits · last 30 days
node
6
OpenAI (training)
1
Resources
daccord — npm install daccord · libregistry