@libraz/libcantus - v1.1.0
    Preparing search index...

    Function parseInterval

    • Parse an interval name such as 'P5', 'm3', 'AA4', or '-m3'.

      A leading '-' names the same interval taken downward: the span is negated and descending is set. The flag is not redundant with the sign — a descending unison spans zero semitones, so only the flag records that the letters move down.

      Parameters

      • name: string

        The interval name: an optional '-', a quality label, and a diatonic number. Surrounding whitespace is ignored.

      Returns SpelledInterval

      The spelled interval. descending is always present, false for an ascending name, and the span is the one intervalSemitones reports — negative for the rare second narrowed past a zero span.

      If the name is not a quality label followed by a number, or the two cannot describe the same interval. Use tryParseInterval where failure is ordinary, such as an interval field read on every keystroke.

      import { parseInterval } from '@libraz/libcantus';
      parseInterval('m3'); // { number: 3, quality: 'm', semitones: 3, descending: false }
      parseInterval('-m3'); // { number: 3, quality: 'm', semitones: -3, descending: true }