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

tonal

v6.3.0

Published

tonaljs music theory library

Downloads

10,870

Readme

tonal

npm version build status minified size gzipped size

tonal is a music theory library. Contains functions to manipulate tonal elements of music (note, intervals, chords, scales, modes, keys). It deals with abstractions (not actual music or sound).

tonal is implemented in Typescript and published as a collection of Javascript npm packages.

It uses a functional programing style: all functions are pure, there is no data mutation, and entities are represented by data structures instead of objects.

Example

import { Interval, Note, Scale } from "tonal";

Note.midi("A4"); // => 60
Note.freq("a4").freq; // => 440
Note.accidentals("c#2"); // => '#'
Note.transpose("C4", "5P"); // => "G4"
Interval.semitones("5P"); // => 7
Interval.distance("C4", "G4"); // => "5P"
Scale.get("C major").notes; // =>["C", "D", "E", "F", "G", "A", "B"];

Install

Install all packages at once:

npm install --save tonal

Usage

Tonal is compatible with both ES5 and ES6 modules, and browser.

ES6 import:

import { Note, Scale } from "tonal";

ES5 require:

const { Note, Scale } = require("tonal");

Browser

You can use the browser version from jsdelivr CDN directly in your html:

<script src="https://cdn.jsdelivr.net/npm/tonal/browser/tonal.min.js"></script>
<script>
  console.log(Tonal.Key.minorKey("Ab"));
</script>

Or if you prefer, grab the minified browser ready version from the repository.

Bundle size

tonal includes all published modules.

Although the final bundle it is small, you can reduce bundle sizes even more by installing the modules individually, and importing only the functions you need.

Note that individual modules are prefixed with @tonaljs/. For example:

npm i @tonaljs/note
import { transpose } from "@tonaljs/note";
transpose("A4", "P5");

Documentation

Generally, you just need to install tonal package (before it was called @tonaljs/tonal).

The API documentation is inside README.md of each module 👇

Notes and intervals

Scales and chords

Keys, chord progressions

Time, rhythm

Utilities

Contributing

Read contributing document. To contribute open a PR and ensure:

  • If is a music theory change (like the name of a scale) link to reliable references.
  • If is a new feature, add documentation: changes to README of the affected module(s) are expected.
  • Ad tests: changes to the test.ts file of the affected module(s) are expected.
  • All tests are green

Inspiration

This library takes inspiration from other music theory libraries:

  • Teoria: https://github.com/saebekassebil/teoria
  • Impro-Visor: https://www.cs.hmc.edu/~keller/jazz/improvisor/
  • MusicKit: https://github.com/benzguo/MusicKit
  • Music21: http://web.mit.edu/music21/doc/index.html
  • Sharp11: https://github.com/jsrmath/sharp11
  • python-mingus: https://github.com/bspaans/python-mingus

Projects using tonal

Showcase of projects that are using Tonal:

Thank you all!

Add your project here by editing this file

License

MIT License