note-duration

1.3.0 • Public • Published

note-duration

Code Climate js-standard-style

Parse note durations. It can convert from name to value and viceversa.

Usage

Install the node module: npm install --save node-duration and require it from you file:

var duration = require('note-duration');

You can convert from names to values:

duration('long');          // => 4
duration('double');         // => 2
duration('whole');          // => 1
duration('half');           // => 1/2
duration('quarter');        // => 1/4
duration('eighth');         // => 1/8
duration('sixteenth');      // => 1/16
duration('thirty-second');  // => 1/32

From letter and dots to values:

duration("h");   // => 1/2
duration("h.");  // => dot: 1/2 + 1/4
duration("h.."); // => double dot: 1/2 + 1/4 + 1/8
duration("ht");  // => triplet: (1/2 + 1/ 2) / 3
duration("q");   // => 1/4
duration("q.");  // => dot: 1/4 + 1/8
duration("q.."); // => double dot: 1/4 + 1/8 + 1/16
duration("qt");  // => triplet: (1/4 + 1/4) / 3

From number string to value:

duration("2");   // => 1/2
duration("2.");  // => dot: 1/2 + 1/4
duration("2t");  // => triplet: (1/2 + 1/ 2) / 3
duration("2.."); // => double dot: 1/2 + 1/4 + 1/8
duration("4");   // => 1/4
duration("4.");  // => dot: 1/4 + 1/8
duration("4.."); // => double dot: 1/4 + 1/8 + 1/16
duration("4t");  // => triplet: (1/4 + 1/4) / 3

The duration.toString method does the opposite: convert from value to letter and dots:

duration.toString(1/2 + 1/4);        // => "h."
duration.toString(1/4 + 1/2 + 1/8);  // => "q.."

License

MIT License

Package Sidebar

Install

npm i note-duration

Weekly Downloads

0

Version

1.3.0

License

MIT

Last publish

Collaborators

  • danigb