tonal-notation
Advanced tools
Comparing version 0.50.0 to 0.60.0
50
index.js
@@ -0,10 +1,10 @@ | ||
/** | ||
* @module notation | ||
*/ | ||
export var isArr = Array.isArray | ||
export function isNum (x) { return typeof x === 'number' } | ||
export function isStr (x) { return typeof x === 'string' } | ||
// NOTE LETTERS | ||
// ============ | ||
// Given a letter, return step | ||
/** | ||
* Given a letter, return step | ||
* @param {String} letter - the letter | ||
* @return {Integer} the step number (from 0 to 6) | ||
*/ | ||
export function toStep (l) { | ||
@@ -16,3 +16,5 @@ var s = 'CDEFGAB'.indexOf(l.toUpperCase()) | ||
/** | ||
* Is a valid step number | ||
* Test if a number is a valid step number (a number from 0 to 6) | ||
* @param {Integer} step - the step number | ||
* @return {Boolean} true if it's a valid step number, false otherwise | ||
*/ | ||
@@ -23,2 +25,4 @@ export function isStep (d) { return !(d < 0 || d > 6) } | ||
* Given a step, return a letter | ||
* @param {Integer} step - the step number | ||
* @return {String} the note letter or null if not valid step number | ||
*/ | ||
@@ -32,5 +36,24 @@ export function toLetter (s) { | ||
/** | ||
* Test if a string are all flats (`b`) chars | ||
* @param {String} str - the string to test | ||
* @return {Boolean} true if all charaters are `b`, false otherwise | ||
*/ | ||
export function areFlats (s) { return /^b+$/.test(s) } | ||
/** | ||
* Test if a string are all sharps (`#`) chars | ||
* @param {String} str - the string to test | ||
* @return {Boolean} true if all charaters are `#`, false otherwise | ||
*/ | ||
export function areSharps (s) { return /^#+$/.test(s) } | ||
/** | ||
* Given an accidentals string return its alteration, the number | ||
* of semitones (positive for sharps, negative for flats, 0 for none) | ||
* @param {String} accidentals - the string to parse | ||
* @return {Integer} the alteration number of null if not a valid accidental strings | ||
* @example | ||
* toAlt('###') // => 3 | ||
* toAlt('bbb') // => -3 | ||
*/ | ||
export function toAlt (s) { | ||
@@ -45,2 +68,11 @@ return s === '' ? 0 | ||
/** | ||
* Given an alteration number, returns the accidentals string | ||
* @param {Integer} alteration - the number of semitones (positive and negative | ||
* values are accepted for sharps and flats) | ||
* @return {String} the accidental string | ||
* @example | ||
* toAcc(3) // => '###' | ||
* toAcc(-3) // => 'bbb' | ||
*/ | ||
export function toAcc (n) { | ||
@@ -47,0 +79,0 @@ return n === 0 ? '' |
{ | ||
"name": "tonal-notation", | ||
"version": "0.50.0", | ||
"version": "0.60.0", | ||
"description": "Music notation utilities", | ||
"keywords": ["music", "notation", "tonal"], | ||
"scripts": { | ||
"pretest": "rm -rf build && mkdir build && rollup -f umd -n notation -o build/tonal-notation.js -- index.js", | ||
"test": "tape 'test/*.js'" | ||
}, | ||
"main": "build/tonal-notation.js", | ||
"keywords": [ | ||
"music", | ||
"notation", | ||
"tonal" | ||
], | ||
"scripts": {}, | ||
"main": "build/index.js", | ||
"jsnext:main": "index", | ||
"author": "danigb", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"rollup": "0.25", | ||
"tape": "4", | ||
"uglify-js": "2" | ||
} | ||
"devDependencies": {} | ||
} |
121
README.md
@@ -12,1 +12,122 @@ # tonal-notation [![npm version](https://img.shields.io/npm/v/tonal-notation.svg)](https://www.npmjs.com/package/tonal-notation) | ||
## API Reference | ||
<dl> | ||
<dt><a href="#toStep">toStep(letter)</a> ⇒ <code>Integer</code></dt> | ||
<dd><p>Given a letter, return step</p> | ||
</dd> | ||
<dt><a href="#isStep">isStep(step)</a> ⇒ <code>Boolean</code></dt> | ||
<dd><p>Test if a number is a valid step number (a number from 0 to 6)</p> | ||
</dd> | ||
<dt><a href="#toLetter">toLetter(step)</a> ⇒ <code>String</code></dt> | ||
<dd><p>Given a step, return a letter</p> | ||
</dd> | ||
<dt><a href="#areFlats">areFlats(str)</a> ⇒ <code>Boolean</code></dt> | ||
<dd><p>Test if a string are all flats (<code>b</code>) chars</p> | ||
</dd> | ||
<dt><a href="#areSharps">areSharps(str)</a> ⇒ <code>Boolean</code></dt> | ||
<dd><p>Test if a string are all sharps (<code>#</code>) chars</p> | ||
</dd> | ||
<dt><a href="#toAlt">toAlt(accidentals)</a> ⇒ <code>Integer</code></dt> | ||
<dd><p>Given an accidentals string return its alteration, the number | ||
of semitones (positive for sharps, negative for flats, 0 for none)</p> | ||
</dd> | ||
<dt><a href="#toAcc">toAcc(alteration)</a> ⇒ <code>String</code></dt> | ||
<dd><p>Given an alteration number, returns the accidentals string</p> | ||
</dd> | ||
</dl> | ||
<a name="toStep"></a> | ||
## toStep(letter) ⇒ <code>Integer</code> | ||
Given a letter, return step | ||
**Returns**: <code>Integer</code> - the step number (from 0 to 6) | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| letter | <code>String</code> | the letter | | ||
<a name="isStep"></a> | ||
## isStep(step) ⇒ <code>Boolean</code> | ||
Test if a number is a valid step number (a number from 0 to 6) | ||
**Returns**: <code>Boolean</code> - true if it's a valid step number, false otherwise | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| step | <code>Integer</code> | the step number | | ||
<a name="toLetter"></a> | ||
## toLetter(step) ⇒ <code>String</code> | ||
Given a step, return a letter | ||
**Returns**: <code>String</code> - the note letter or null if not valid step number | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| step | <code>Integer</code> | the step number | | ||
<a name="areFlats"></a> | ||
## areFlats(str) ⇒ <code>Boolean</code> | ||
Test if a string are all flats (`b`) chars | ||
**Returns**: <code>Boolean</code> - true if all charaters are `b`, false otherwise | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| str | <code>String</code> | the string to test | | ||
<a name="areSharps"></a> | ||
## areSharps(str) ⇒ <code>Boolean</code> | ||
Test if a string are all sharps (`#`) chars | ||
**Returns**: <code>Boolean</code> - true if all charaters are `#`, false otherwise | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| str | <code>String</code> | the string to test | | ||
<a name="toAlt"></a> | ||
## toAlt(accidentals) ⇒ <code>Integer</code> | ||
Given an accidentals string return its alteration, the number | ||
of semitones (positive for sharps, negative for flats, 0 for none) | ||
**Returns**: <code>Integer</code> - the alteration number of null if not a valid accidental strings | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| accidentals | <code>String</code> | the string to parse | | ||
**Example** | ||
```js | ||
toAlt('###') // => 3 | ||
toAlt('bbb') // => -3 | ||
``` | ||
<a name="toAcc"></a> | ||
## toAcc(alteration) ⇒ <code>String</code> | ||
Given an alteration number, returns the accidentals string | ||
**Returns**: <code>String</code> - the accidental string | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| alteration | <code>Integer</code> | the number of semitones (positive and negative values are accepted for sharps and flats) | | ||
**Example** | ||
```js | ||
toAcc(3) // => '###' | ||
toAcc(-3) // => 'bbb' | ||
``` |
9804
0
174
133
5