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

    Function tryParseInterval

    • Parse an interval name, reporting failure instead of throwing it.

      The same reading as parseInterval — that function is this one with its error thrown — for the callers where a name that does not parse yet is the normal state of the input rather than a fault.

      Parameters

      • name: string

        The interval name.

      Returns ParseResult<SpelledInterval>

      The interval, or the error explaining why the text is not one.

      import { tryParseInterval } from '@libraz/libcantus';
      const result = tryParseInterval('M5');
      result.ok ? result.value.semitones : result.error.message; // a fifth cannot be major