npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

momo-chords

v0.4.3

Published

Chord parser and printer

Downloads

234

Readme

Momo Chords · GitHub license npm version Build Status TypeScript

Chord parser and printer.

Try it on the demo page!

Overview

There are many existing libraries that tackle handling chords. However, they either don't support a large enough set of chords, or they lack functionality, or they are not properly configurable, or they don't come with types.

The goal of this library is to support all of the above.

Currently it supports:

  • [x] A very large set of chords
  • [x] Parsing strings as chord symbols
  • [x] Parsing strings as chord notes
  • [x] Printing chord names when given a chord
  • [x] An even larger set of chords (added in 0.3.0)
  • [x] Configurable naming strategies (added in 0.4.0)
  • [ ] Autocomplete/search by name

Installation

npm install --save momo-chords

or

yarn add momo-chords

Usage

import { Chords } from "momo-chords";

const chords = new Chords();

// Check if a string is a valid chord anme
chords.isChord("A#maj7/G");  // true
chords.isChord("T");  // false

// Parse a string into a chord object
const chord = chords.parse("A#M7/G");  // chord object

// Print the name of a chord
chords.print(chord.symbol);  // "A#maj7/G"

Custom namings

The library comes with a comprehensive set of default chord names. However, you might wish to customize what should be considered a chord and/or how a chord should be printed. This is possible to do why namings.

In order to apply a custom naming, simply provide a naming description to the constructor:

import { Chords, INaming } from "momo-chords";

const myNaming: Partial<INaming> = { ... };
const chords = new Chords(myNaming);

You can see the default naming called DEFAULT_NAMING in naming.ts.

The naming you provide is a Partial<INaming> because you can provide a subset of the naming description. What you provide will be used to override the defaults.

If you want to update just how chords should be printed, then it is enough to override only the printing key of the naming. printing contains a preferred name for each chord part.

If you also want to customise what should be considered a chord, you can override the parsing key of the naming. parsing contains a list of all possible names for each chord part.

How it works

Parsing

  1. First, we split the chord string into components using a regular expression generated from the list of all possible chord component names. If the regular expression fails, the string is not a chord.
  2. Next, we check for certain rules regarding the chord components: for example, altered fifths cannot be specified via both dim and b5, and power chords cannot contain further components. If any of the tests fail, the string is not a chord.
  3. Next, we generate the intervals (notes) in the chord, given the constraints specified by the chord components. If there is no chord satisfying all of the chord components, the string is not a chord.
  4. Finally, we now know that the string is indeed a chord, and we combine the results into a single chord object.

Printing

  1. The naming contains a preferred name for each chord component.
  2. For each chord component, we pick the preferred name, and we concatenate the results.