@tonaljs/duration-value
TypeScript icon, indicating that this package has built-in type declarations

4.8.1 • Public • Published

@tonaljs/duration-value tonal npm version

Functions to parse and manipulate time duration values

Usage

ES6:

import { DurationValue } from "tonal";

node:

const { DurationValue } = require("tonal");

single module:

import DurationValue from "@tonaljs/duration-value";

API

DurationValue.names() => string[]

Return all duration names

DurationValue.names(); // => ["large", "duplex longa", ...]

DurationValue.shorthands() => string[]

Return all duration value shorthands

DurationValue.shorthands(); // => ["dl", "l", "d", "w", "h", "q", "e", "s", "t", "sf", "h", "th"]

DurationValue.get(name: string) // => object

Get a duration value object from name:

DurationValue.get("quarter"); // =>
// {
//   empty: false,
//   name: 'q',
//   value: 0.25,
//   fraction: [ 1, 4 ],
//   shorthand: 'q',
//   dots: '',
//   names: [ 'quarter', 'crotchet' ]
// }

The name accepts an arbitrary number of dots:

DurationValue.get("quarter.."); // =>
// {
//   empty: false,
//   name: 'q..',
//   value: 0.4375,
//   fraction: [ 7, 16 ],
//   shorthand: 'q',
//   dots: '..',
//   names: [ 'quarter', 'crotchet' ]
// }

Short names are accepted:

DurationValue.get("q") == DurationValue.get("quarter");
DurationValue.get("q.") == DurationValue.get("quarter.");
DurationValue.get("q..") == DurationValue.get("quarter..");

Some aliases (value and fraction) are provided:

DurationValue.value("q.."); // => 0.4375
DurationValue.fraction("q.."); // => [ 7, 16 ]

References

Package Sidebar

Install

npm i @tonaljs/duration-value

Weekly Downloads

529

Version

4.8.1

License

MIT

Unpacked Size

21.7 kB

Total Files

9

Last publish

Collaborators

  • danigb