Installation
Get started with mdg-utils
mdg-utils gives you Malagasy number words, Madagascar phone numbers, Ariary amounts and dates. Install only the modules you need — each one is a small package with zero dependencies, ESM + CommonJS + types.
Installing a module with npm
Section titled “Installing a module with npm”Each module is its own package: @mdgascar/words, @mdgascar/phone, @mdgascar/ariary and @mdgascar/date. They run in Node.js 22.18+, Deno, Bun and every modern browser.
-
Install the package
Section titled “Install the package”Add the module you need. This example uses phone numbers.
Terminal npm install @mdgascar/phone -
Import a function
Section titled “Import a function”Every module exports plain functions. Read a number written in any common way and format it.
signup.ts import { formatPhoneNumber, parsePhoneNumber } from '@mdgascar/phone';const phone = parsePhoneNumber('034 12 345 67');phone.operator; // 'yas'formatPhoneNumber('0341234567', 'international'); // '+261 34 12 345 67' -
Handle bad input
Section titled “Handle bad input”parse…functions throw anMdgError. UsesafeParse…to get the error code without throwing, ortryParse…to getundefined.signup.ts import { safeParsePhoneNumber, tryParsePhoneNumber } from '@mdgascar/phone';const result = safeParsePhoneNumber('031 12 345 67');if (!result.success) result.error.code; // 'UNKNOWN_OPERATOR'tryParsePhoneNumber('not a number'); // undefined -
Check the result
Section titled “Check the result”Error codes are the same in every language, so a form can show the same message whether the check ran in the browser or on a PHP server.
signup.ts import { MdgError, parsePhoneNumber } from '@mdgascar/phone';try {parsePhoneNumber(userInput);} catch (error) {if (error instanceof MdgError) console.log(error.code); // 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | …}