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 🙏

© 2026 – Pkg Stats / Ryan Hefner

interval-parser

v1.0.0

Published

Parse musical intervals in shorthand notation

Readme

interval-parser npm

js-standard-style license

Parses music intervals in shorthand notation:

var parser = require('interval-parser')
parser.parse('P4')
// => { num: 4, q: 'P', dir: 1, simple: 4, type: 'P', alt: 0, oct: 0, semitones: 5 }

// accepts reverse shorthand notation
parser.parse('6m')
// => { num: 6, q: 'm', dir: 1, simple: 6, type: 'M', alt: -1, oct: 0, semitones: 8 }

If you only need a property, you can use a function with the property name:

parser.semitones('6m') // => 8
parser.simple('9M') // => 2

#### Interval string format

It accepts two different interval string formats:

  • In standard shorthand notation: quality+[dir]+num. Examples: 'P8', 'M-3'
  • In reverse shorthand notation: [dur]+num+quality. Examples: '8P', '-3M'

API

parse(str)

Parse a string with an interval in shorthand notation and returns an object with interval properties

Parameters

  • str String the string with the interval

Examples

var parser = require('interval-parser')
parser.parse('P4')
// => { num: 4, q: 'P', dir: 1, simple: 4, type: 'P', alt: 0, oct: 0, semitones: 5 }
// accepts reverse shorthand notation
parser.parse('6m')
// => { num: 6, q: 'm', dir: 1, simple: 6, type: 'M', alt: -1, oct: 0, semitones: 8 }

Returns an object with interval properties or null if not valid interval string:

  • num: the interval number
  • q: the interval quality string (M is major, m is minor, P is perfect...)
  • simple: the simplified number (from 1 to 7)
  • dir: the interval direction (1 ascending, -1 descending)
  • type: the interval type (P is perfectable, M is majorable)
  • alt: the alteration, a numeric representation of the quality
  • oct: the number of octaves the interval spans. 0 for simple intervals.
  • semitones: the size of the interval in semitones

Helper functions

For each property of the interval there's a function with the same name that returns only that property:

parser.num('9m') // => 9
parser.q('9m') // => 'm'
parser.simple('9m') // => 2
parser.dir('9m') // => 1
parser.type('9m') // => 'M'
parser.alt('9m') // => -1
parser.oct('9m') // => 1
parser.semitones('9m') // => 13

License

MIT License