New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tonal-key

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tonal-key - npm Package Compare versions

Comparing version 0.50.1 to 0.50.2

114

build/tonal-key.js

@@ -5,9 +5,4 @@ 'use strict';

var tonalNotation = require('tonal-notation');
var tonalTranspose = require('tonal-transpose');
var tonalRange = require('tonal-range');
var tonalNote = require('tonal-note');
var tonal = require('tonal');
// Modes
// =====
// Order matter: use an array

@@ -18,4 +13,62 @@ var MODES = ['ionian', 'dorian', 'phrygian', 'lydian', 'mixolydian',

var FIFTHS = [0, 2, 4, -1, 1, 3, 5, 0, 3]
var SCALES = [0, 1, 2, 3, 4, 5, 6, 0, 5].map(function (n) {
return tonal.harmonics(tonal.rotate(n, ['C', 'D', 'E', 'F', 'G', 'A', 'B']))
})
/**
* Get scale of a key
* @param {String|Object} key
* @return {Array} the key scale
* @example
* var key = require('tonal-key')
* key.scale('A major') // => [ 'A', 'B', 'C#', 'D', 'E', 'F#', 'G#' ]
* key.scale('Bb minor') // => [ 'Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab' ]
* key.scale('C dorian') // => [ 'C', 'D', 'Eb', 'F', 'G', 'A', 'Bb' ]
* key.scale('E mixolydian') // => [ 'E', 'F#', 'G#', 'A', 'B', 'C#', 'D' ]
*/
function scale (key) {
var k = asKey(key)
if (!k || !hasTonic(k)) return null
return tonal.harmonize(SCALES[MODES.indexOf(k[0])], k[1])
}
/**
* Get relative of a key. It can be partially applied.
* @param {String} mode - the relative destination
* @param {String} key - the key source
* @example
* var key = require('tonal-keys')
* key.relative('dorian', 'C major') // => ['dorian', 'D']
* // partially application
* var minor = key.relative('minor')
* minor('C major') // => ['minor', 'A']
*/
function relative (rel, key) {
if (arguments.length === 1) return function (k) { return relative(rel, k) }
var r = asKey(rel)
if (!r || hasTonic(r)) return null
var k = asKey(key)
if (!k || !hasTonic(k)) return null
var i = tonalPitch.pitch(modeNum(r) - modeNum(k), 0, 1)
var tonic = tonal.transpose(k[1], i)
return build(tonic, rel)
}
/**
* Get a list of the altered notes of a given key. The notes will be in
* the same order than in the key signature.
* @param {String|Nunber} key
* @return {Array}
* @example
* var key = require('tonal-keys')
* key.alteredNotes('Eb major') // => [ 'Bb', 'Eb', 'Ab' ]
*/
function alteredNotes (key) {
var alt = alteration(key)
return alt === null ? null
: alt < 0 ? tonal.range([-1, alt]).map(tonal.trFifths('F'))
: tonal.range([1, alt]).map(tonal.trFifths('B'))
}
/**
* Get a list of valid mode names. The list of modes will be always in

@@ -57,3 +110,3 @@ * increasing order (ionian to locrian)

if (tonic === false || tonic === null) return [m, false]
var t = tonalNote.pc(tonic)
var t = tonal.pc(tonic)
return t ? [m, t] : null

@@ -65,3 +118,3 @@ }

function majorKey (n) { return build(tonalTranspose.trFifths('C', n), 'major') }
function majorKey (n) { return build(tonal.trFifths('C', n), 'major') }

@@ -129,24 +182,2 @@ /**

/**
* Get relative of a key. It can be partially applied.
* @param {String} mode - the relative destination
* @param {String} key - the key source
* @example
* var key = require('tonal-keys')
* key.relative('dorian', 'C major') // => ['dorian', 'D']
* // partially application
* var minor = key.relative('minor')
* minor('C major') // => ['minor', 'A']
*/
function relative (rel, key) {
if (arguments.length === 1) return function (k) { return relative(rel, k) }
var r = asKey(rel)
if (!r || hasTonic(r)) return null
var k = asKey(key)
if (!k || !hasTonic(k)) return null
var i = tonalPitch.pitch(modeNum(r) - modeNum(k), 0, 1)
var tonic = tonalTranspose.transpose(k[1], i)
return build(tonic, rel)
}
/**
* Get key alteration. The alteration is a number indicating the number of

@@ -184,18 +215,5 @@ * sharpen notes (positive) or flaten notes (negative)

/**
* Get a list of the altered notes of a given key. The notes will be in
* the same order than in the key signature.
* @param {String|Nunber} key
* @return {Array}
* @example
* var key = require('tonal-keys')
* key.alteredNotes('Eb major') // => [ 'Bb', 'Eb', 'Ab' ]
*/
function alteredNotes (key) {
var alt = alteration(key)
return alt === null ? null
: alt < 0 ? tonalRange.range(-1, alt).map(tonalTranspose.trFifths('F'))
: tonalRange.range(1, alt).map(tonalTranspose.trFifths('B'))
}
exports.scale = scale;
exports.relative = relative;
exports.alteredNotes = alteredNotes;
exports.names = names;

@@ -208,6 +226,4 @@ exports.isKeyMode = isKeyMode;

exports.asKey = asKey;
exports.relative = relative;
exports.alteration = alteration;
exports.signature = signature;
exports.accidentals = accidentals;
exports.alteredNotes = alteredNotes;
exports.accidentals = accidentals;
import { parseNote, pitch, fifths } from 'tonal-pitch'
import { isArr, isStr, isNum, areFlats, areSharps, toAcc } from 'tonal-notation'
import { transpose, trFifths } from 'tonal-transpose'
import { range } from 'tonal-range'
import { pc } from 'tonal-note'
import { transpose, trFifths, range, pc, rotate, harmonics, harmonize } from 'tonal'
// Modes
// =====
// Order matter: use an array

@@ -15,4 +10,62 @@ var MODES = ['ionian', 'dorian', 'phrygian', 'lydian', 'mixolydian',

var FIFTHS = [0, 2, 4, -1, 1, 3, 5, 0, 3]
var SCALES = [0, 1, 2, 3, 4, 5, 6, 0, 5].map(function (n) {
return harmonics(rotate(n, ['C', 'D', 'E', 'F', 'G', 'A', 'B']))
})
/**
* Get scale of a key
* @param {String|Object} key
* @return {Array} the key scale
* @example
* var key = require('tonal-key')
* key.scale('A major') // => [ 'A', 'B', 'C#', 'D', 'E', 'F#', 'G#' ]
* key.scale('Bb minor') // => [ 'Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab' ]
* key.scale('C dorian') // => [ 'C', 'D', 'Eb', 'F', 'G', 'A', 'Bb' ]
* key.scale('E mixolydian') // => [ 'E', 'F#', 'G#', 'A', 'B', 'C#', 'D' ]
*/
export function scale (key) {
var k = asKey(key)
if (!k || !hasTonic(k)) return null
return harmonize(SCALES[MODES.indexOf(k[0])], k[1])
}
/**
* Get relative of a key. It can be partially applied.
* @param {String} mode - the relative destination
* @param {String} key - the key source
* @example
* var key = require('tonal-keys')
* key.relative('dorian', 'C major') // => ['dorian', 'D']
* // partially application
* var minor = key.relative('minor')
* minor('C major') // => ['minor', 'A']
*/
export function relative (rel, key) {
if (arguments.length === 1) return function (k) { return relative(rel, k) }
var r = asKey(rel)
if (!r || hasTonic(r)) return null
var k = asKey(key)
if (!k || !hasTonic(k)) return null
var i = pitch(modeNum(r) - modeNum(k), 0, 1)
var tonic = transpose(k[1], i)
return build(tonic, rel)
}
/**
* Get a list of the altered notes of a given key. The notes will be in
* the same order than in the key signature.
* @param {String|Nunber} key
* @return {Array}
* @example
* var key = require('tonal-keys')
* key.alteredNotes('Eb major') // => [ 'Bb', 'Eb', 'Ab' ]
*/
export function alteredNotes (key) {
var alt = alteration(key)
return alt === null ? null
: alt < 0 ? range([-1, alt]).map(trFifths('F'))
: range([1, alt]).map(trFifths('B'))
}
/**
* Get a list of valid mode names. The list of modes will be always in

@@ -124,24 +177,2 @@ * increasing order (ionian to locrian)

/**
* Get relative of a key. It can be partially applied.
* @param {String} mode - the relative destination
* @param {String} key - the key source
* @example
* var key = require('tonal-keys')
* key.relative('dorian', 'C major') // => ['dorian', 'D']
* // partially application
* var minor = key.relative('minor')
* minor('C major') // => ['minor', 'A']
*/
export function relative (rel, key) {
if (arguments.length === 1) return function (k) { return relative(rel, k) }
var r = asKey(rel)
if (!r || hasTonic(r)) return null
var k = asKey(key)
if (!k || !hasTonic(k)) return null
var i = pitch(modeNum(r) - modeNum(k), 0, 1)
var tonic = transpose(k[1], i)
return build(tonic, rel)
}
/**
* Get key alteration. The alteration is a number indicating the number of

@@ -178,17 +209,1 @@ * sharpen notes (positive) or flaten notes (negative)

export var accidentals = signature
/**
* Get a list of the altered notes of a given key. The notes will be in
* the same order than in the key signature.
* @param {String|Nunber} key
* @return {Array}
* @example
* var key = require('tonal-keys')
* key.alteredNotes('Eb major') // => [ 'Bb', 'Eb', 'Ab' ]
*/
export function alteredNotes (key) {
var alt = alteration(key)
return alt === null ? null
: alt < 0 ? range(-1, alt).map(trFifths('F'))
: range(1, alt).map(trFifths('B'))
}
{
"name": "tonal-key",
"version": "0.50.1",
"version": "0.50.2",
"description": "Conversion between key numbers and note names",

@@ -24,7 +24,6 @@ "keywords": [

"dependencies": {
"tonal": "^0.50.2",
"tonal-notation": "^0.50.0",
"tonal-note": "^0.50.2",
"tonal-range": "^0.50.2",
"tonal-transpose": "^0.50.3"
"tonal-pitch": "^0.50.3"
}
}

@@ -12,3 +12,14 @@ # tonal-key [![npm version](https://img.shields.io/npm/v/tonal-key.svg)](https://www.npmjs.com/package/tonal-key)

## API Reference
<dl>
<dt><a href="#scale">scale(key)</a> ⇒ <code>Array</code></dt>
<dd><p>Get scale of a key</p>
</dd>
<dt><a href="#relative">relative(mode, key)</a></dt>
<dd><p>Get relative of a key. It can be partially applied.</p>
</dd>
<dt><a href="#alteredNotes">alteredNotes(key)</a> ⇒ <code>Array</code></dt>
<dd><p>Get a list of the altered notes of a given key. The notes will be in
the same order than in the key signature.</p>
</dd>
<dt><a href="#names">names(alias)</a> ⇒ <code>Array</code></dt>

@@ -39,5 +50,2 @@ <dd><p>Get a list of valid mode names. The list of modes will be always in

</dd>
<dt><a href="#relative">relative(mode, key)</a></dt>
<dd><p>Get relative of a key. It can be partially applied.</p>
</dd>
<dt><a href="#alteration">alteration(key)</a> ⇒ <code>Integer</code></dt>

@@ -53,8 +61,61 @@ <dd><p>Get key alteration. The alteration is a number indicating the number of

</dd>
<dt><a href="#alteredNotes">alteredNotes(key)</a> ⇒ <code>Array</code></dt>
<dd><p>Get a list of the altered notes of a given key. The notes will be in
the same order than in the key signature.</p>
</dd>
</dl>
<a name="scale"></a>
## scale(key) ⇒ <code>Array</code>
Get scale of a key
**Kind**: global function
**Returns**: <code>Array</code> - the key scale
| Param | Type |
| --- | --- |
| key | <code>String</code> &#124; <code>Object</code> |
**Example**
```js
var key = require('tonal-key')
key.scale('A major') // => [ 'A', 'B', 'C#', 'D', 'E', 'F#', 'G#' ]
key.scale('Bb minor') // => [ 'Bb', 'C', 'Db', 'Eb', 'F', 'Gb', 'Ab' ]
key.scale('C dorian') // => [ 'C', 'D', 'Eb', 'F', 'G', 'A', 'Bb' ]
key.scale('E mixolydian') // => [ 'E', 'F#', 'G#', 'A', 'B', 'C#', 'D' ]
```
<a name="relative"></a>
## relative(mode, key)
Get relative of a key. It can be partially applied.
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| mode | <code>String</code> | the relative destination |
| key | <code>String</code> | the key source |
**Example**
```js
var key = require('tonal-keys')
key.relative('dorian', 'C major') // => ['dorian', 'D']
// partially application
var minor = key.relative('minor')
minor('C major') // => ['minor', 'A']
```
<a name="alteredNotes"></a>
## alteredNotes(key) ⇒ <code>Array</code>
Get a list of the altered notes of a given key. The notes will be in
the same order than in the key signature.
**Kind**: global function
| Param | Type |
| --- | --- |
| key | <code>String</code> &#124; <code>Nunber</code> |
**Example**
```js
var key = require('tonal-keys')
key.alteredNotes('Eb major') // => [ 'Bb', 'Eb', 'Ab' ]
```
<a name="names"></a>

@@ -171,22 +232,2 @@

<a name="relative"></a>
## relative(mode, key)
Get relative of a key. It can be partially applied.
**Kind**: global function
| Param | Type | Description |
| --- | --- | --- |
| mode | <code>String</code> | the relative destination |
| key | <code>String</code> | the key source |
**Example**
```js
var key = require('tonal-keys')
key.relative('dorian', 'C major') // => ['dorian', 'D']
// partially application
var minor = key.relative('minor')
minor('C major') // => ['minor', 'A']
```
<a name="alteration"></a>

@@ -226,18 +267,1 @@

**Kind**: global function
<a name="alteredNotes"></a>
## alteredNotes(key) ⇒ <code>Array</code>
Get a list of the altered notes of a given key. The notes will be in
the same order than in the key signature.
**Kind**: global function
| Param | Type |
| --- | --- |
| key | <code>String</code> &#124; <code>Nunber</code> |
**Example**
```js
var key = require('tonal-keys')
key.alteredNotes('Eb major') // => [ 'Bb', 'Eb', 'Ab' ]
```

@@ -5,2 +5,9 @@

test('scale', function (t) {
t.deepEqual(key.scale('C major'), [ 'C', 'D', 'E', 'F', 'G', 'A', 'B' ])
t.deepEqual(key.scale('C dorian'), [ 'C', 'D', 'Eb', 'F', 'G', 'A', 'Bb' ])
t.deepEqual(key.scale('E mixolydian'), [ 'E', 'F#', 'G#', 'A', 'B', 'C#', 'D' ])
t.end()
})
test('isKeyMode', function (t) {

@@ -7,0 +14,0 @@ key.names(true).forEach(function (m) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc