JavaScript API
@mdgascar/words
Malagasy number words. Part of mdg-utils by Mdgascar.
Classes
Section titled “Classes”MdgError
Section titled “MdgError”Error thrown by mdg-utils functions. Check code, which is the same in every language.
Example
Section titled “Example”try { numberToWords(-1);} catch (error) { if (error instanceof MdgError && error.code === 'OUT_OF_RANGE') { // handle it }}Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MdgError(
code,message):MdgError
Creates an error with a shared spec code.
Parameters
Section titled “Parameters”Shared spec error code.
message
Section titled “message”string
Human-readable explanation, in English.
Returns
Section titled “Returns”Overrides
Section titled “Overrides”Error.constructor
Properties
Section titled “Properties”
readonlycode:ErrorCode
Why the call failed; the same code in every language.
readonlyname:"MdgError"='MdgError'
Always 'MdgError'.
Overrides
Section titled “Overrides”Error.name
Methods
Section titled “Methods”[hasInstance]()
Section titled “[hasInstance]()”
static[hasInstance](value):boolean
Makes instanceof MdgError true for errors from any mdg-utils package or build.
Parameters
Section titled “Parameters”unknown
Any value, usually a caught error.
Returns
Section titled “Returns”boolean
true when value is an mdg-utils error.
Remarks
Section titled “Remarks”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.
Type Aliases
Section titled “Type Aliases”ErrorCode
Section titled “ErrorCode”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.
Variables
Section titled “Variables”SPEC_VERSION
Section titled “SPEC_VERSION”
constSPEC_VERSION:"0.6.0"='0.6.0'
Version of the shared spec this code was generated from.
Functions
Section titled “Functions”numberToWords()
Section titled “numberToWords()”numberToWords(
value):string
Writes a number in Malagasy words, smallest part first, with faingo before the decimals.
Parameters
Section titled “Parameters”number
A number from 0 to Number.MAX_SAFE_INTEGER, whole or decimal.
Returns
Section titled “Returns”string
The number in Malagasy words.
Throws
Section titled “Throws”MdgError INVALID_TYPE if value is not a finite number,
OUT_OF_RANGE if it is negative or above Number.MAX_SAFE_INTEGER.
Example
Section titled “Example”numberToWords(21); // 'iraika amby roapolo'numberToWords(2026); // 'enina amby roapolo sy roa arivo'numberToWords(3.14); // "telo faingo efatra ambin'ny folo"