Skip to content
GitHub

JavaScript API

@mdgascar/words

Malagasy number words. Part of mdg-utils by Mdgascar.

Error thrown by mdg-utils functions. Check code, which is the same in every language.

try {
numberToWords(-1);
} catch (error) {
if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') {
// handle it
}
}
  • Error

new MdgError(code, message): MdgError

Creates an error with a shared spec code.

ErrorCode

Shared spec error code.

string

Human-readable explanation, in English.

MdgError

Error.constructor

readonly code: ErrorCode

Why the call failed; the same code in every language.

readonly name: "MdgError" = 'MdgError'

Always 'MdgError'.

Error.name

static [hasInstance](value): boolean

Makes instanceof MdgError true for errors from any mdg-utils package or build.

unknown

Any value, usually a caught error.

boolean

true when value is an mdg-utils error.

Each package, and its ESM and CommonJS builds, has its own copy of this class, so the check looks at the error’s shape instead of its prototype chain.

ErrorCode = "INVALID_TYPE" | "OUT_OF_RANGE" | "INVALID_FORMAT" | "UNKNOWN_OPERATOR"

Error code shared by every mdg-utils language port.

  • INVALID_TYPE: The input is not of the accepted type (for example a string or a non-integer where an integer is expected).
  • OUT_OF_RANGE: The input has the right type but lies outside the supported range.
  • INVALID_FORMAT: The input text cannot be read as a value of this module (wrong characters or wrong length).
  • UNKNOWN_OPERATOR: The phone number is well formed but its operator code is not assigned to a mobile operator.

const SPEC_VERSION: "0.6.0" = '0.6.0'

Version of the shared spec this code was generated from.

numberToWords(value): string

Writes a number in Malagasy words, smallest part first, with faingo before the decimals.

number

A number from 0 to Number.MAX_SAFE_INTEGER, whole or decimal.

string

The number in Malagasy words.

MdgError INVALID_TYPE if value is not a finite number, OUT_OF_RANGE if it is negative or above Number.MAX_SAFE_INTEGER.

numberToWords(21); // 'iraika amby roapolo'
numberToWords(2026); // 'enina amby roapolo sy roa arivo'
numberToWords(3.14); // "telo faingo efatra ambin'ny folo"