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

tonal-note

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tonal-note - npm Package Compare versions

Comparing version 1.0.0-pre6 to 1.0.0

120

build/es5.js

@@ -16,13 +16,14 @@ 'use strict';

* ```js
* import * as note from 'tonal-note'
* // or const note = require('tonal-note')
* note.name('bb2') // => 'Bb2'
* note.chroma('bb2') // => 10
* note.midi('a4') // => 69
* note.freq('a4') // => 440
* note.oct('G3') // => 3
* import * as Note from "tonal-note"
* // or const Note = require("tonal-note")
* Note.name("bb2") // => "Bb2"
* Note.chroma("bb2") // => 10
* Note.midi("a4") // => 69
* Note.freq("a4") // => 440
* Note.oct("G3") // => 3
*
* // part of tonal
* const tonal = require('tonal')
* tonal.note.midi('d4') // => 62
* const Tonal = require("tonal")
* // or import Note from "tonal"
* Tonal.Note.midi("d4") // => 62
* ```

@@ -36,3 +37,3 @@ *

*
* @module note
* @module Note
*/

@@ -50,4 +51,4 @@

* @example
* note.names(" b") // => [ 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B' ]
* note.names(" #") // => [ 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B' ]
* Note.names(" b") // => [ "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" ]
* Note.names(" #") // => [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ]
*/

@@ -74,7 +75,7 @@ var names = function (accTypes) { return typeof accTypes !== "string"

* @example
* note.tokenize('C#2') // => ["C", "#", "2", ""]
* note.tokenize('Db3 major') // => ["D", "b", "3", "major"]
* note.tokenize('major') // => ["", "", "", "major"]
* note.tokenize('##') // => ["", "##", "", ""]
* note.tokenize() // => ["", "", "", ""]
* Note.tokenize("C#2") // => ["C", "#", "2", ""]
* Note.tokenize("Db3 major") // => ["D", "b", "3", "major"]
* Note.tokenize("major") // => ["", "", "", "major"]
* Note.tokenize("##") // => ["", "##", "", ""]
* Note.tokenize() // => ["", "", "", ""]
*/

@@ -139,6 +140,6 @@ function tokenize(str) {

*
* This function *always* returns an object with all this properties, but if it's
* This function *always* returns an object with all this properties, but if it"s
* not a valid note all properties will be null.
*
* The returned object can't be mutated.
* The returned object can"t be mutated.
*

@@ -149,6 +150,6 @@ * @param {String} note - the note name in scientific notation

* @example
* note.props('fx-3').name // => 'F##-3'
* note.props('invalid').name // => null
* note.props('C#3').oct // => 3
* note.props().oct // => null
* Note.props("fx-3").name // => "F##-3"
* Note.props("invalid").name // => null
* Note.props("C#3").oct // => 3
* Note.props().oct // => null
*/

@@ -169,5 +170,4 @@ var props = memo(properties);

* @example
* const note = require('tonal-note')
* note.name('cb2') // => 'Cb2'
* ['c', 'db3', '2', 'g+', 'gx4'].map(note.name) // => ['C', 'Db3', null, null, 'G##4']
* Note.name("cb2") // => "Cb2"
* ["c", "db3", "2", "g+", "gx4"].map(Note.name) // => ["C", "Db3", null, null, "G##4"]
*/

@@ -183,4 +183,4 @@ var name = function (str) { return props(str).name; };

* @example
* tonal.pc('Db3') // => 'Db'
* tonal.map(tonal.pc, 'db3 bb6 fx2') // => [ 'Db', 'Bb', 'F##']
* Note.pc("Db3") // => "Db"
* ["db3", "bb6", "fx2"].map(Note.pc) // => [ "Db", "Bb", "F##"]
*/

@@ -197,4 +197,4 @@ var pc = function (str) { return props(str).pc; };

* @example
* note.midi('C4') // => 60
* note.midi(60) // => 60
* Note.midi("C4") // => 60
* Note.midi(60) // => 60
* @see midi.toMidi

@@ -224,4 +224,4 @@ */

* @example
* note.freq('A4') // => 440
* note.freq(69) // => 440
* Note.freq("A4") // => 440
* Note.freq(69) // => 440
*/

@@ -239,5 +239,5 @@ var freq = function (note) { return props(note).freq || midiToFreq(note); };

* @example
* note.freqToMidi(220)); //=> 57;
* note.freqToMidi(261.62)); //=> 60;
* note.freqToMidi(261)); //=> 59.96;
* Note.freqToMidi(220)); //=> 57;
* Note.freqToMidi(261.62)); //=> 60;
* Note.freqToMidi(261)); //=> 59.96;
*/

@@ -256,5 +256,4 @@ var freqToMidi = function (freq) {

* @example
* const note = require('tonal-note')
* note.chroma('Cb') // => 11
* ['C', 'D', 'E', 'F'].map(note.chroma) // => [0, 2, 4, 5]
* Note.chroma("Cb") // => 11
* ["C", "D", "E", "F"].map(Note.chroma) // => [0, 2, 4, 5]
*/

@@ -268,7 +267,7 @@ var chroma = function (str) { return props(str).chroma; };

* @param {string} note - the note
* @return {Integer} the octave or null if doesn't have an octave or not a valid note
* @return {Integer} the octave or null if doesn"t have an octave or not a valid note
* @example
* note.oct('C#4') // => 4
* note.oct('C') // => null
* note.oct('blah') // => undefined
* Note.oct("C#4") // => 4
* Note.oct("C") // => null
* Note.oct("blah") // => undefined
*/

@@ -279,7 +278,7 @@ var oct = function (str) { return props(str).oct; };

/**
* Given a step number return it's letter (0 = C, 1 = D, 2 = E)
* Given a step number return it"s letter (0 = C, 1 = D, 2 = E)
* @param {number} step
* @return {string} the letter
* @example
* note.stepToLetter(3) // => "F"
* Note.stepToLetter(3) // => "F"
*/

@@ -296,3 +295,3 @@ var stepToLetter = function (step) { return LETTERS[step]; };

* @example
* note.altToAcc(-3) // => 'bbb'
* Note.altToAcc(-3) // => "bbb"
*/

@@ -310,6 +309,6 @@ var altToAcc = function (alt) { return numToStr(alt, function (alt) { return (alt < 0 ? fillStr("b", -alt) : fillStr("#", alt)); }); };

* @example
* note.build({ step: 5 }) // => "A"
* note.build({ step: 1, acc: -1 }) // => 'Db'
* note.build({ step: 2, acc: 2, oct: 2 }) // => 'E##2'
* note.build({ step: 7 }) // => null
* Note.build({ step: 5 }) // => "A"
* Note.build({ step: 1, acc: -1 }) // => "Db"
* Note.build({ step: 2, acc: 2, oct: 2 }) // => "E##2"
* Note.build({ step: 7 }) // => null
*/

@@ -337,7 +336,6 @@ var build = function (ref) {

* @example
* const note = require('tonal-note')
* note.fromMidi(61) // => 'Db4'
* note.fromMidi(61, true) // => 'C#4'
* Note.fromMidi(61) // => "Db4"
* Note.fromMidi(61, true) // => "C#4"
* // it rounds to nearest note
* note.fromMidi(61.7) // => 'D4'
* Note.fromMidi(61.7) // => "D4"
*/

@@ -354,2 +352,3 @@ function fromMidi(num, sharps) {

* Simplify the note: find an enhramonic note with less accidentals.
*
* @param {String} note - the note to be simplified

@@ -360,6 +359,6 @@ * @param {boolean} useSameAccType - (optional, true by default) set to true

* @example
* note.simplify("C##") // => "D"
* note.simplify("C###") // => "D#"
* note.simplify("C###", false) // => "Eb"
* note.simplify("B#4") // => "C5"
* Note.simplify("C##") // => "D"
* Note.simplify("C###") // => "D#"
* Note.simplify("C###", false) // => "Eb"
* Note.simplify("B#4") // => "C5"
*/

@@ -379,8 +378,9 @@ var simplify = function (note, sameAcc) {

/**
* Get the simplified and enhramonic note of the given one
* Get the simplified and enhramonic note of the given one.
*
* @param {String} note
* @return {String} the enhramonic note
* @example
* note.enharmonic('Db') // => 'C#'
* note.enhramonic('C') // => 'C'
* Note.enharmonic("Db") // => "C#"
* Note.enhramonic("C") // => "C"
*/

@@ -387,0 +387,0 @@ var enharmonic = function (note) { return simplify(note, false); };

@@ -12,13 +12,14 @@ /**

* ```js
* import * as note from 'tonal-note'
* // or const note = require('tonal-note')
* note.name('bb2') // => 'Bb2'
* note.chroma('bb2') // => 10
* note.midi('a4') // => 69
* note.freq('a4') // => 440
* note.oct('G3') // => 3
* import * as Note from "tonal-note"
* // or const Note = require("tonal-note")
* Note.name("bb2") // => "Bb2"
* Note.chroma("bb2") // => 10
* Note.midi("a4") // => 69
* Note.freq("a4") // => 440
* Note.oct("G3") // => 3
*
* // part of tonal
* const tonal = require('tonal')
* tonal.note.midi('d4') // => 62
* const Tonal = require("tonal")
* // or import Note from "tonal"
* Tonal.Note.midi("d4") // => 62
* ```

@@ -32,3 +33,3 @@ *

*
* @module note
* @module Note
*/

@@ -46,4 +47,4 @@

* @example
* note.names(" b") // => [ 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B' ]
* note.names(" #") // => [ 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B' ]
* Note.names(" b") // => [ "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" ]
* Note.names(" #") // => [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ]
*/

@@ -70,7 +71,7 @@ export var names = function (accTypes) { return typeof accTypes !== "string"

* @example
* note.tokenize('C#2') // => ["C", "#", "2", ""]
* note.tokenize('Db3 major') // => ["D", "b", "3", "major"]
* note.tokenize('major') // => ["", "", "", "major"]
* note.tokenize('##') // => ["", "##", "", ""]
* note.tokenize() // => ["", "", "", ""]
* Note.tokenize("C#2") // => ["C", "#", "2", ""]
* Note.tokenize("Db3 major") // => ["D", "b", "3", "major"]
* Note.tokenize("major") // => ["", "", "", "major"]
* Note.tokenize("##") // => ["", "##", "", ""]
* Note.tokenize() // => ["", "", "", ""]
*/

@@ -135,6 +136,6 @@ export function tokenize(str) {

*
* This function *always* returns an object with all this properties, but if it's
* This function *always* returns an object with all this properties, but if it"s
* not a valid note all properties will be null.
*
* The returned object can't be mutated.
* The returned object can"t be mutated.
*

@@ -145,6 +146,6 @@ * @param {String} note - the note name in scientific notation

* @example
* note.props('fx-3').name // => 'F##-3'
* note.props('invalid').name // => null
* note.props('C#3').oct // => 3
* note.props().oct // => null
* Note.props("fx-3").name // => "F##-3"
* Note.props("invalid").name // => null
* Note.props("C#3").oct // => 3
* Note.props().oct // => null
*/

@@ -165,5 +166,4 @@ export var props = memo(properties);

* @example
* const note = require('tonal-note')
* note.name('cb2') // => 'Cb2'
* ['c', 'db3', '2', 'g+', 'gx4'].map(note.name) // => ['C', 'Db3', null, null, 'G##4']
* Note.name("cb2") // => "Cb2"
* ["c", "db3", "2", "g+", "gx4"].map(Note.name) // => ["C", "Db3", null, null, "G##4"]
*/

@@ -179,4 +179,4 @@ export var name = function (str) { return props(str).name; };

* @example
* tonal.pc('Db3') // => 'Db'
* tonal.map(tonal.pc, 'db3 bb6 fx2') // => [ 'Db', 'Bb', 'F##']
* Note.pc("Db3") // => "Db"
* ["db3", "bb6", "fx2"].map(Note.pc) // => [ "Db", "Bb", "F##"]
*/

@@ -193,4 +193,4 @@ export var pc = function (str) { return props(str).pc; };

* @example
* note.midi('C4') // => 60
* note.midi(60) // => 60
* Note.midi("C4") // => 60
* Note.midi(60) // => 60
* @see midi.toMidi

@@ -220,4 +220,4 @@ */

* @example
* note.freq('A4') // => 440
* note.freq(69) // => 440
* Note.freq("A4") // => 440
* Note.freq(69) // => 440
*/

@@ -235,5 +235,5 @@ export var freq = function (note) { return props(note).freq || midiToFreq(note); };

* @example
* note.freqToMidi(220)); //=> 57;
* note.freqToMidi(261.62)); //=> 60;
* note.freqToMidi(261)); //=> 59.96;
* Note.freqToMidi(220)); //=> 57;
* Note.freqToMidi(261.62)); //=> 60;
* Note.freqToMidi(261)); //=> 59.96;
*/

@@ -252,5 +252,4 @@ export var freqToMidi = function (freq) {

* @example
* const note = require('tonal-note')
* note.chroma('Cb') // => 11
* ['C', 'D', 'E', 'F'].map(note.chroma) // => [0, 2, 4, 5]
* Note.chroma("Cb") // => 11
* ["C", "D", "E", "F"].map(Note.chroma) // => [0, 2, 4, 5]
*/

@@ -264,7 +263,7 @@ export var chroma = function (str) { return props(str).chroma; };

* @param {string} note - the note
* @return {Integer} the octave or null if doesn't have an octave or not a valid note
* @return {Integer} the octave or null if doesn"t have an octave or not a valid note
* @example
* note.oct('C#4') // => 4
* note.oct('C') // => null
* note.oct('blah') // => undefined
* Note.oct("C#4") // => 4
* Note.oct("C") // => null
* Note.oct("blah") // => undefined
*/

@@ -275,7 +274,7 @@ export var oct = function (str) { return props(str).oct; };

/**
* Given a step number return it's letter (0 = C, 1 = D, 2 = E)
* Given a step number return it"s letter (0 = C, 1 = D, 2 = E)
* @param {number} step
* @return {string} the letter
* @example
* note.stepToLetter(3) // => "F"
* Note.stepToLetter(3) // => "F"
*/

@@ -292,3 +291,3 @@ export var stepToLetter = function (step) { return LETTERS[step]; };

* @example
* note.altToAcc(-3) // => 'bbb'
* Note.altToAcc(-3) // => "bbb"
*/

@@ -306,6 +305,6 @@ export var altToAcc = function (alt) { return numToStr(alt, function (alt) { return (alt < 0 ? fillStr("b", -alt) : fillStr("#", alt)); }); };

* @example
* note.build({ step: 5 }) // => "A"
* note.build({ step: 1, acc: -1 }) // => 'Db'
* note.build({ step: 2, acc: 2, oct: 2 }) // => 'E##2'
* note.build({ step: 7 }) // => null
* Note.build({ step: 5 }) // => "A"
* Note.build({ step: 1, acc: -1 }) // => "Db"
* Note.build({ step: 2, acc: 2, oct: 2 }) // => "E##2"
* Note.build({ step: 7 }) // => null
*/

@@ -333,7 +332,6 @@ export var build = function (ref) {

* @example
* const note = require('tonal-note')
* note.fromMidi(61) // => 'Db4'
* note.fromMidi(61, true) // => 'C#4'
* Note.fromMidi(61) // => "Db4"
* Note.fromMidi(61, true) // => "C#4"
* // it rounds to nearest note
* note.fromMidi(61.7) // => 'D4'
* Note.fromMidi(61.7) // => "D4"
*/

@@ -350,2 +348,3 @@ export function fromMidi(num, sharps) {

* Simplify the note: find an enhramonic note with less accidentals.
*
* @param {String} note - the note to be simplified

@@ -356,6 +355,6 @@ * @param {boolean} useSameAccType - (optional, true by default) set to true

* @example
* note.simplify("C##") // => "D"
* note.simplify("C###") // => "D#"
* note.simplify("C###", false) // => "Eb"
* note.simplify("B#4") // => "C5"
* Note.simplify("C##") // => "D"
* Note.simplify("C###") // => "D#"
* Note.simplify("C###", false) // => "Eb"
* Note.simplify("B#4") // => "C5"
*/

@@ -375,9 +374,10 @@ export var simplify = function (note, sameAcc) {

/**
* Get the simplified and enhramonic note of the given one
* Get the simplified and enhramonic note of the given one.
*
* @param {String} note
* @return {String} the enhramonic note
* @example
* note.enharmonic('Db') // => 'C#'
* note.enhramonic('C') // => 'C'
* Note.enharmonic("Db") // => "C#"
* Note.enhramonic("C") // => "C"
*/
export var enharmonic = function (note) { return simplify(note, false); };

@@ -12,13 +12,14 @@ /**

* ```js
* import * as note from 'tonal-note'
* // or const note = require('tonal-note')
* note.name('bb2') // => 'Bb2'
* note.chroma('bb2') // => 10
* note.midi('a4') // => 69
* note.freq('a4') // => 440
* note.oct('G3') // => 3
* import * as Note from "tonal-note"
* // or const Note = require("tonal-note")
* Note.name("bb2") // => "Bb2"
* Note.chroma("bb2") // => 10
* Note.midi("a4") // => 69
* Note.freq("a4") // => 440
* Note.oct("G3") // => 3
*
* // part of tonal
* const tonal = require('tonal')
* tonal.note.midi('d4') // => 62
* const Tonal = require("tonal")
* // or import Note from "tonal"
* Tonal.Note.midi("d4") // => 62
* ```

@@ -32,3 +33,3 @@ *

*
* @module note
* @module Note
*/

@@ -46,4 +47,4 @@

* @example
* note.names(" b") // => [ 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B' ]
* note.names(" #") // => [ 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B' ]
* Note.names(" b") // => [ "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" ]
* Note.names(" #") // => [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ]
*/

@@ -71,7 +72,7 @@ export const names = accTypes =>

* @example
* note.tokenize('C#2') // => ["C", "#", "2", ""]
* note.tokenize('Db3 major') // => ["D", "b", "3", "major"]
* note.tokenize('major') // => ["", "", "", "major"]
* note.tokenize('##') // => ["", "##", "", ""]
* note.tokenize() // => ["", "", "", ""]
* Note.tokenize("C#2") // => ["C", "#", "2", ""]
* Note.tokenize("Db3 major") // => ["D", "b", "3", "major"]
* Note.tokenize("major") // => ["", "", "", "major"]
* Note.tokenize("##") // => ["", "##", "", ""]
* Note.tokenize() // => ["", "", "", ""]
*/

@@ -130,6 +131,6 @@ export function tokenize(str) {

*
* This function *always* returns an object with all this properties, but if it's
* This function *always* returns an object with all this properties, but if it"s
* not a valid note all properties will be null.
*
* The returned object can't be mutated.
* The returned object can"t be mutated.
*

@@ -140,6 +141,6 @@ * @param {String} note - the note name in scientific notation

* @example
* note.props('fx-3').name // => 'F##-3'
* note.props('invalid').name // => null
* note.props('C#3').oct // => 3
* note.props().oct // => null
* Note.props("fx-3").name // => "F##-3"
* Note.props("invalid").name // => null
* Note.props("C#3").oct // => 3
* Note.props().oct // => null
*/

@@ -160,5 +161,4 @@ export const props = memo(properties);

* @example
* const note = require('tonal-note')
* note.name('cb2') // => 'Cb2'
* ['c', 'db3', '2', 'g+', 'gx4'].map(note.name) // => ['C', 'Db3', null, null, 'G##4']
* Note.name("cb2") // => "Cb2"
* ["c", "db3", "2", "g+", "gx4"].map(Note.name) // => ["C", "Db3", null, null, "G##4"]
*/

@@ -174,4 +174,4 @@ export const name = str => props(str).name;

* @example
* tonal.pc('Db3') // => 'Db'
* tonal.map(tonal.pc, 'db3 bb6 fx2') // => [ 'Db', 'Bb', 'F##']
* Note.pc("Db3") // => "Db"
* ["db3", "bb6", "fx2"].map(Note.pc) // => [ "Db", "Bb", "F##"]
*/

@@ -188,4 +188,4 @@ export const pc = str => props(str).pc;

* @example
* note.midi('C4') // => 60
* note.midi(60) // => 60
* Note.midi("C4") // => 60
* Note.midi(60) // => 60
* @see midi.toMidi

@@ -212,4 +212,4 @@ */

* @example
* note.freq('A4') // => 440
* note.freq(69) // => 440
* Note.freq("A4") // => 440
* Note.freq(69) // => 440
*/

@@ -227,5 +227,5 @@ export const freq = note => props(note).freq || midiToFreq(note);

* @example
* note.freqToMidi(220)); //=> 57;
* note.freqToMidi(261.62)); //=> 60;
* note.freqToMidi(261)); //=> 59.96;
* Note.freqToMidi(220)); //=> 57;
* Note.freqToMidi(261.62)); //=> 60;
* Note.freqToMidi(261)); //=> 59.96;
*/

@@ -244,5 +244,4 @@ export const freqToMidi = freq => {

* @example
* const note = require('tonal-note')
* note.chroma('Cb') // => 11
* ['C', 'D', 'E', 'F'].map(note.chroma) // => [0, 2, 4, 5]
* Note.chroma("Cb") // => 11
* ["C", "D", "E", "F"].map(Note.chroma) // => [0, 2, 4, 5]
*/

@@ -256,7 +255,7 @@ export const chroma = str => props(str).chroma;

* @param {string} note - the note
* @return {Integer} the octave or null if doesn't have an octave or not a valid note
* @return {Integer} the octave or null if doesn"t have an octave or not a valid note
* @example
* note.oct('C#4') // => 4
* note.oct('C') // => null
* note.oct('blah') // => undefined
* Note.oct("C#4") // => 4
* Note.oct("C") // => null
* Note.oct("blah") // => undefined
*/

@@ -267,7 +266,7 @@ export const oct = str => props(str).oct;

/**
* Given a step number return it's letter (0 = C, 1 = D, 2 = E)
* Given a step number return it"s letter (0 = C, 1 = D, 2 = E)
* @param {number} step
* @return {string} the letter
* @example
* note.stepToLetter(3) // => "F"
* Note.stepToLetter(3) // => "F"
*/

@@ -284,3 +283,3 @@ export const stepToLetter = step => LETTERS[step];

* @example
* note.altToAcc(-3) // => 'bbb'
* Note.altToAcc(-3) // => "bbb"
*/

@@ -299,6 +298,6 @@ export const altToAcc = alt =>

* @example
* note.build({ step: 5 }) // => "A"
* note.build({ step: 1, acc: -1 }) // => 'Db'
* note.build({ step: 2, acc: 2, oct: 2 }) // => 'E##2'
* note.build({ step: 7 }) // => null
* Note.build({ step: 5 }) // => "A"
* Note.build({ step: 1, acc: -1 }) // => "Db"
* Note.build({ step: 2, acc: 2, oct: 2 }) // => "E##2"
* Note.build({ step: 7 }) // => null
*/

@@ -321,7 +320,6 @@ export const build = ({ step, alt, oct } = {}) => {

* @example
* const note = require('tonal-note')
* note.fromMidi(61) // => 'Db4'
* note.fromMidi(61, true) // => 'C#4'
* Note.fromMidi(61) // => "Db4"
* Note.fromMidi(61, true) // => "C#4"
* // it rounds to nearest note
* note.fromMidi(61.7) // => 'D4'
* Note.fromMidi(61.7) // => "D4"
*/

@@ -338,2 +336,3 @@ export function fromMidi(num, sharps) {

* Simplify the note: find an enhramonic note with less accidentals.
*
* @param {String} note - the note to be simplified

@@ -344,6 +343,6 @@ * @param {boolean} useSameAccType - (optional, true by default) set to true

* @example
* note.simplify("C##") // => "D"
* note.simplify("C###") // => "D#"
* note.simplify("C###", false) // => "Eb"
* note.simplify("B#4") // => "C5"
* Note.simplify("C##") // => "D"
* Note.simplify("C###") // => "D#"
* Note.simplify("C###", false) // => "Eb"
* Note.simplify("B#4") // => "C5"
*/

@@ -360,9 +359,10 @@ export const simplify = (note, sameAcc) => {

/**
* Get the simplified and enhramonic note of the given one
* Get the simplified and enhramonic note of the given one.
*
* @param {String} note
* @return {String} the enhramonic note
* @example
* note.enharmonic('Db') // => 'C#'
* note.enhramonic('C') // => 'C'
* Note.enharmonic("Db") // => "C#"
* Note.enhramonic("C") // => "C"
*/
export const enharmonic = note => simplify(note, false);
{
"name": "tonal-note",
"version": "1.0.0-pre6",
"version": "1.0.0",
"repository": "https://github.com/danigb/tonal/packages/note",

@@ -5,0 +5,0 @@ "description": "Parse and manipulate music notes in scientific notation",

@@ -1,4 +0,4 @@

<a name="module_note"></a>
<a name="module_Note"></a>
# note
# Note
[![npm version](https://img.shields.io/npm/v/tonal-note.svg)](https://www.npmjs.com/package/tonal-note)

@@ -14,13 +14,14 @@ [![tonal](https://img.shields.io/badge/tonal-note-yellow.svg)](https://www.npmjs.com/browse/keyword/tonal)

```js
import * as note from 'tonal-note'
// or const note = require('tonal-note')
note.name('bb2') // => 'Bb2'
note.chroma('bb2') // => 10
note.midi('a4') // => 69
note.freq('a4') // => 440
note.oct('G3') // => 3
import * as Note from "tonal-note"
// or const Note = require("tonal-note")
Note.name("bb2") // => "Bb2"
Note.chroma("bb2") // => 10
Note.midi("a4") // => 69
Note.freq("a4") // => 440
Note.oct("G3") // => 3
// part of tonal
const tonal = require('tonal')
tonal.note.midi('d4') // => 62
const Tonal = require("tonal")
// or import Note from "tonal"
Tonal.Note.midi("d4") // => 62
```

@@ -35,27 +36,27 @@

* [note](#module_note)
* [`.names`](#module_note.names) ⇒ <code>Array</code>
* [`.props`](#module_note.props) ⇒ <code>Object</code>
* [`.midiToFreq`](#module_note.midiToFreq) ⇒ <code>Number</code>
* [`.freqToMidi`](#module_note.freqToMidi) ⇒ <code>Number</code>
* [`.chroma`](#module_note.chroma) ⇒ <code>Integer</code>
* [`.stepToLetter`](#module_note.stepToLetter) ⇒ <code>string</code>
* [`.altToAcc`](#module_note.altToAcc) ⇒ <code>String</code>
* [`.build`](#module_note.build) ⇒ <code>String</code>
* [`.simplify`](#module_note.simplify) ⇒ <code>String</code>
* [`.enharmonic`](#module_note.enharmonic) ⇒ <code>String</code>
* [`.tokenize(str)`](#module_note.tokenize) ⇒ <code>Array</code>
* [`.name()`](#module_note.name) ⇒ <code>string</code>
* [`.pc()`](#module_note.pc) ⇒ <code>string</code>
* [`.midi(note)`](#module_note.midi) ⇒ <code>Integer</code>
* [`.freq(note)`](#module_note.freq) ⇒ <code>Number</code>
* [`.oct(note)`](#module_note.oct) ⇒ <code>Integer</code>
* [`.fromMidi(midi, useSharps)`](#module_note.fromMidi) ⇒ <code>string</code>
* [Note](#module_Note)
* [`.names`](#module_Note.names) ⇒ <code>Array</code>
* [`.props`](#module_Note.props) ⇒ <code>Object</code>
* [`.midiToFreq`](#module_Note.midiToFreq) ⇒ <code>Number</code>
* [`.freqToMidi`](#module_Note.freqToMidi) ⇒ <code>Number</code>
* [`.chroma`](#module_Note.chroma) ⇒ <code>Integer</code>
* [`.stepToLetter`](#module_Note.stepToLetter) ⇒ <code>string</code>
* [`.altToAcc`](#module_Note.altToAcc) ⇒ <code>String</code>
* [`.build`](#module_Note.build) ⇒ <code>String</code>
* [`.simplify`](#module_Note.simplify) ⇒ <code>String</code>
* [`.enharmonic`](#module_Note.enharmonic) ⇒ <code>String</code>
* [`.tokenize(str)`](#module_Note.tokenize) ⇒ <code>Array</code>
* [`.name()`](#module_Note.name) ⇒ <code>string</code>
* [`.pc()`](#module_Note.pc) ⇒ <code>string</code>
* [`.midi(note)`](#module_Note.midi) ⇒ <code>Integer</code>
* [`.freq(note)`](#module_Note.freq) ⇒ <code>Number</code>
* [`.oct(note)`](#module_Note.oct) ⇒ <code>Integer</code>
* [`.fromMidi(midi, useSharps)`](#module_Note.fromMidi) ⇒ <code>string</code>
<a name="module_note.names"></a>
<a name="module_Note.names"></a>
## `note.names` ⇒ <code>Array</code>
## `Note.names` ⇒ <code>Array</code>
Get a list of note names (pitch classes) within a octave
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)

@@ -68,8 +69,8 @@ | Param | Type | Description |

```js
note.names(" b") // => [ 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B' ]
note.names(" #") // => [ 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B' ]
Note.names(" b") // => [ "C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B" ]
Note.names(" #") // => [ "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" ]
```
<a name="module_note.props"></a>
<a name="module_Note.props"></a>
## `note.props` ⇒ <code>Object</code>
## `Note.props` ⇒ <code>Object</code>
Get note properties. It returns an object with the following information:

@@ -88,8 +89,8 @@

This function *always* returns an object with all this properties, but if it's
This function *always* returns an object with all this properties, but if it"s
not a valid note all properties will be null.
The returned object can't be mutated.
The returned object can"t be mutated.
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)
**Returns**: <code>Object</code> - an object with the properties (or an object will all properties

@@ -104,13 +105,13 @@ set to null if not valid note)

```js
note.props('fx-3').name // => 'F##-3'
note.props('invalid').name // => null
note.props('C#3').oct // => 3
note.props().oct // => null
Note.props("fx-3").name // => "F##-3"
Note.props("invalid").name // => null
Note.props("C#3").oct // => 3
Note.props().oct // => null
```
<a name="module_note.midiToFreq"></a>
<a name="module_Note.midiToFreq"></a>
## `note.midiToFreq` ⇒ <code>Number</code>
## `Note.midiToFreq` ⇒ <code>Number</code>
Get the frequency from midi number
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)
**Returns**: <code>Number</code> - the frequency or null if not valid note midi

@@ -123,9 +124,9 @@

<a name="module_note.freqToMidi"></a>
<a name="module_Note.freqToMidi"></a>
## `note.freqToMidi` ⇒ <code>Number</code>
## `Note.freqToMidi` ⇒ <code>Number</code>
Get the midi number from a frequency in hertz. The midi number can
contain decimals (with two digits precission)
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)

@@ -138,13 +139,13 @@ | Param | Type |

```js
note.freqToMidi(220)); //=> 57;
note.freqToMidi(261.62)); //=> 60;
note.freqToMidi(261)); //=> 59.96;
Note.freqToMidi(220)); //=> 57;
Note.freqToMidi(261.62)); //=> 60;
Note.freqToMidi(261)); //=> 59.96;
```
<a name="module_note.chroma"></a>
<a name="module_Note.chroma"></a>
## `note.chroma` ⇒ <code>Integer</code>
## `Note.chroma` ⇒ <code>Integer</code>
Return the chroma of a note. The chroma is the numeric equivalent to the
pitch class, where 0 is C, 1 is C# or Db, 2 is D... 11 is B
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)
**Returns**: <code>Integer</code> - the chroma number

@@ -158,12 +159,11 @@

```js
const note = require('tonal-note')
note.chroma('Cb') // => 11
['C', 'D', 'E', 'F'].map(note.chroma) // => [0, 2, 4, 5]
Note.chroma("Cb") // => 11
["C", "D", "E", "F"].map(Note.chroma) // => [0, 2, 4, 5]
```
<a name="module_note.stepToLetter"></a>
<a name="module_Note.stepToLetter"></a>
## `note.stepToLetter` ⇒ <code>string</code>
Given a step number return it's letter (0 = C, 1 = D, 2 = E)
## `Note.stepToLetter` ⇒ <code>string</code>
Given a step number return it"s letter (0 = C, 1 = D, 2 = E)
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)
**Returns**: <code>string</code> - the letter

@@ -177,10 +177,10 @@

```js
note.stepToLetter(3) // => "F"
Note.stepToLetter(3) // => "F"
```
<a name="module_note.altToAcc"></a>
<a name="module_Note.altToAcc"></a>
## `note.altToAcc` ⇒ <code>String</code>
## `Note.altToAcc` ⇒ <code>String</code>
Given an alteration number, return the accidentals
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)

@@ -193,7 +193,7 @@ | Param | Type |

```js
note.altToAcc(-3) // => 'bbb'
Note.altToAcc(-3) // => "bbb"
```
<a name="module_note.build"></a>
<a name="module_Note.build"></a>
## `note.build` ⇒ <code>String</code>
## `Note.build` ⇒ <code>String</code>
Build a note name in scientific notation from note properties.

@@ -205,3 +205,3 @@ It receives an object with:

**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)
**Returns**: <code>String</code> - the note name in scientific notation or null if not valid properties

@@ -215,13 +215,13 @@

```js
note.build({ step: 5 }) // => "A"
note.build({ step: 1, acc: -1 }) // => 'Db'
note.build({ step: 2, acc: 2, oct: 2 }) // => 'E##2'
note.build({ step: 7 }) // => null
Note.build({ step: 5 }) // => "A"
Note.build({ step: 1, acc: -1 }) // => "Db"
Note.build({ step: 2, acc: 2, oct: 2 }) // => "E##2"
Note.build({ step: 7 }) // => null
```
<a name="module_note.simplify"></a>
<a name="module_Note.simplify"></a>
## `note.simplify` ⇒ <code>String</code>
## `Note.simplify` ⇒ <code>String</code>
Simplify the note: find an enhramonic note with less accidentals.
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)
**Returns**: <code>String</code> - the simplfiied note or null if not valid note

@@ -236,13 +236,13 @@

```js
note.simplify("C##") // => "D"
note.simplify("C###") // => "D#"
note.simplify("C###", false) // => "Eb"
note.simplify("B#4") // => "C5"
Note.simplify("C##") // => "D"
Note.simplify("C###") // => "D#"
Note.simplify("C###", false) // => "Eb"
Note.simplify("B#4") // => "C5"
```
<a name="module_note.enharmonic"></a>
<a name="module_Note.enharmonic"></a>
## `note.enharmonic` ⇒ <code>String</code>
Get the simplified and enhramonic note of the given one
## `Note.enharmonic` ⇒ <code>String</code>
Get the simplified and enhramonic note of the given one.
**Kind**: static constant of [<code>note</code>](#module_note)
**Kind**: static constant of [<code>Note</code>](#module_Note)
**Returns**: <code>String</code> - the enhramonic note

@@ -256,8 +256,8 @@

```js
note.enharmonic('Db') // => 'C#'
note.enhramonic('C') // => 'C'
Note.enharmonic("Db") // => "C#"
Note.enhramonic("C") // => "C"
```
<a name="module_note.tokenize"></a>
<a name="module_Note.tokenize"></a>
## `note.tokenize(str)` ⇒ <code>Array</code>
## `Note.tokenize(str)` ⇒ <code>Array</code>
Split a string into tokens related to note parts.

@@ -268,3 +268,3 @@ It returns an array of strings `[letter, accidental, octave, modifier]`

**Kind**: static method of [<code>note</code>](#module_note)
**Kind**: static method of [<code>Note</code>](#module_Note)
**Returns**: <code>Array</code> - an array of note tokens

@@ -278,11 +278,11 @@

```js
note.tokenize('C#2') // => ["C", "#", "2", ""]
note.tokenize('Db3 major') // => ["D", "b", "3", "major"]
note.tokenize('major') // => ["", "", "", "major"]
note.tokenize('##') // => ["", "##", "", ""]
note.tokenize() // => ["", "", "", ""]
Note.tokenize("C#2") // => ["C", "#", "2", ""]
Note.tokenize("Db3 major") // => ["D", "b", "3", "major"]
Note.tokenize("major") // => ["", "", "", "major"]
Note.tokenize("##") // => ["", "##", "", ""]
Note.tokenize() // => ["", "", "", ""]
```
<a name="module_note.name"></a>
<a name="module_Note.name"></a>
## `note.name()` ⇒ <code>string</code>
## `Note.name()` ⇒ <code>string</code>
Given a note name, return the note name or null if not valid note.

@@ -294,3 +294,3 @@ The note name will ALWAYS have the letter in upercase and accidentals

**Kind**: static method of [<code>note</code>](#module_note)
**Kind**: static method of [<code>Note</code>](#module_Note)

@@ -303,12 +303,11 @@ | Type |

```js
const note = require('tonal-note')
note.name('cb2') // => 'Cb2'
['c', 'db3', '2', 'g+', 'gx4'].map(note.name) // => ['C', 'Db3', null, null, 'G##4']
Note.name("cb2") // => "Cb2"
["c", "db3", "2", "g+", "gx4"].map(Note.name) // => ["C", "Db3", null, null, "G##4"]
```
<a name="module_note.pc"></a>
<a name="module_Note.pc"></a>
## `note.pc()` ⇒ <code>string</code>
## `Note.pc()` ⇒ <code>string</code>
Get pitch class of a note. The note can be a string or a pitch array.
**Kind**: static method of [<code>note</code>](#module_note)
**Kind**: static method of [<code>Note</code>](#module_Note)
**Returns**: <code>string</code> - the pitch class

@@ -322,12 +321,12 @@

```js
tonal.pc('Db3') // => 'Db'
tonal.map(tonal.pc, 'db3 bb6 fx2') // => [ 'Db', 'Bb', 'F##']
Note.pc("Db3") // => "Db"
["db3", "bb6", "fx2"].map(Note.pc) // => [ "Db", "Bb", "F##"]
```
<a name="module_note.midi"></a>
<a name="module_Note.midi"></a>
## `note.midi(note)` ⇒ <code>Integer</code>
## `Note.midi(note)` ⇒ <code>Integer</code>
Get the note midi number
(an alias of tonal-midi `toMidi` function)
**Kind**: static method of [<code>note</code>](#module_note)
**Kind**: static method of [<code>Note</code>](#module_Note)
**Returns**: <code>Integer</code> - the midi number or null if not valid pitch

@@ -342,11 +341,11 @@ **See**: midi.toMidi

```js
note.midi('C4') // => 60
note.midi(60) // => 60
Note.midi("C4") // => 60
Note.midi(60) // => 60
```
<a name="module_note.freq"></a>
<a name="module_Note.freq"></a>
## `note.freq(note)` ⇒ <code>Number</code>
## `Note.freq(note)` ⇒ <code>Number</code>
Get the frequency of a note
**Kind**: static method of [<code>note</code>](#module_note)
**Kind**: static method of [<code>Note</code>](#module_Note)
**Returns**: <code>Number</code> - the frequency

@@ -360,12 +359,12 @@

```js
note.freq('A4') // => 440
note.freq(69) // => 440
Note.freq("A4") // => 440
Note.freq(69) // => 440
```
<a name="module_note.oct"></a>
<a name="module_Note.oct"></a>
## `note.oct(note)` ⇒ <code>Integer</code>
## `Note.oct(note)` ⇒ <code>Integer</code>
Get the octave of the given pitch
**Kind**: static method of [<code>note</code>](#module_note)
**Returns**: <code>Integer</code> - the octave or null if doesn't have an octave or not a valid note
**Kind**: static method of [<code>Note</code>](#module_Note)
**Returns**: <code>Integer</code> - the octave or null if doesn"t have an octave or not a valid note

@@ -378,13 +377,13 @@ | Param | Type | Description |

```js
note.oct('C#4') // => 4
note.oct('C') // => null
note.oct('blah') // => undefined
Note.oct("C#4") // => 4
Note.oct("C") // => null
Note.oct("blah") // => undefined
```
<a name="module_note.fromMidi"></a>
<a name="module_Note.fromMidi"></a>
## `note.fromMidi(midi, useSharps)` ⇒ <code>string</code>
## `Note.fromMidi(midi, useSharps)` ⇒ <code>string</code>
Given a midi number, returns a note name. The altered notes will have
flats unless explicitly set with the optional `useSharps` parameter.
**Kind**: static method of [<code>note</code>](#module_note)
**Kind**: static method of [<code>Note</code>](#module_Note)
**Returns**: <code>string</code> - the note name

@@ -399,7 +398,6 @@

```js
const note = require('tonal-note')
note.fromMidi(61) // => 'Db4'
note.fromMidi(61, true) // => 'C#4'
Note.fromMidi(61) // => "Db4"
Note.fromMidi(61, true) // => "C#4"
// it rounds to nearest note
note.fromMidi(61.7) // => 'D4'
Note.fromMidi(61.7) // => "D4"
```
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