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

@pcmnac/chord-transposer

v2.0.1

Published

Transposes musical chords in arbitrary text.

Downloads

6

Readme

Chord Transposer

Javascript/TypeScript library for transposing musical chords within arbitrary text.

Usage

Install via npm:

npm install chord-transposer

Import the package using your preferred import syntax:

const Transposer = require('chord-transposer');

import * as Transposer from 'chord-transposer';

import { transpose } from 'chord-transposer';

Transposing

To a certain key signature:

> Transposer.transpose('F  C7 Bb   \nHello world').fromKey('F').toKey('D').toString()
'D  A7 G   \nHello world'

> Transposer.transpose('Fm  C Ab   \nHello world').fromKey('Fm').toKey('Dm').toString()
'Dm  A F   \nHello world'

up or down any number of semitones:

// Up 7 semitones.
> Transposer.transpose('F  Am Bb   \nHello world').fromKey('F').up(7).toString()
'C  Em F   \nHello world'

// Down 4 semitones.
> Transposer.transpose('F  Am Bb   \nHello world').fromKey('F').down(4).toString()
'Db  Fm Gb   \nHello world'

Auto Key Signature

If the key signature is not specified, the key will be inferred from the first chord.

> Transposer.transpose('F  C7 Bb   \nHello world').toKey('D').toString()
'D  A7 G   \nHello world'

> Transposer.transpose('Fm  C Ab   \nHello world').toKey('Dm').toString()
'Dm  A F   \nHello world'

> Transposer.transpose('F  Am Bb   \nHello world').up(7)
'C  Em F   \nHello world'

Supported Chords

> Transposer.transpose('C Cmaj CM Cm/F C7/F Csus4').toKey('F').toString()
'F Fmaj FM Fm/Bb F7/Bb Fsus4'

> Transposer.transpose('Cm Cmin C- Cdim Caug C+ C+5').toKey('Dm').toString()
'Dm Dmin D- Ddim Daug D+ D+5'

Parsing

When text is passed into transpose, it is parsed into an Array<Array<string|Chord>>. You can access these through tokens to parse however you like:

> Transposer
    .transpose('C  G  Am  G7/B  C    F  C   F   G7\nO Canada  Our home and native land')
    .tokens
[ [ Chord { root: 'C', suffix: '', bass: undefined },
    '  ',
    Chord { root: 'G', suffix: '', bass: undefined },
    '  ',
    Chord { root: 'A', suffix: 'm', bass: undefined },
    '  ',
    Chord { root: 'G', suffix: '7', bass: 'B' },
    '  ',
    Chord { root: 'C', suffix: '', bass: undefined },
    '    ',
    Chord { root: 'F', suffix: '', bass: undefined },
    '  ',
    Chord { root: 'C', suffix: '', bass: undefined },
    '   ',
    Chord { root: 'F', suffix: '', bass: undefined },
    '   ',
    Chord { root: 'G', suffix: '7', bass: undefined } ],
  [ 'O Canada  Our home and native land' ] ]

Key Signatures

You can see the current key signature of the text through currentKey.

> Transposer.transpose('C  G').currentKey
KeySignature {
  _description: 'C',
  _ordinal: 0,
  majorKey: 'C',
  relativeMinor: 'Am',
  keyType: 1,
  rank: 0,
  _propName: 'C' }

> Transposer.transpose('C  G').up(4).currentKey
KeySignature {
  _description: 'E',
  _ordinal: 4,
  majorKey: 'E',
  relativeMinor: 'C#m',
  keyType: 1,
  rank: 4,
  _propName: 'E' }