Installation
Get started with malagasy-intl
malagasy-intl 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.
Requirements
Section titled “Requirements”| Runtimes | Node.js 22.18+, Bun, Deno, every modern browser |
| Module formats | ESM and CommonJS |
| Types | TypeScript declarations included, no @types package |
| Dependencies | None |
| Frameworks | Any: React, Next.js, Vue, Nuxt, Angular, Svelte, Astro, Express, plain scripts |
Installing a module with npm
Section titled “Installing a module with npm”Each module is its own package: @mdgascar/number-words, @mdgascar/phone-number, @mdgascar/ariary and @mdgascar/date-time. 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-number -
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 { formatPhone, parsePhone } from '@mdgascar/phone-number';const phone = parsePhone('034 12 345 67');phone.operator; // 'yas'formatPhone('0341234567', 'international'); // '+261 34 12 345 67' -
Handle bad input
Section titled “Handle bad input”parse…functions throw anMalagasyIntlError. UsesafeParse…to get the error code without throwing, ortryParse…to getundefined.signup.ts import { safeParsePhone, tryParsePhone } from '@mdgascar/phone-number';const result = safeParsePhone('031 12 345 67');if (!result.success) result.error.code; // 'UNKNOWN_OPERATOR'tryParsePhone('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 { MalagasyIntlError, parsePhone } from '@mdgascar/phone-number';try {parsePhone(userInput);} catch (error) {if (error instanceof MalagasyIntlError) console.log(error.code); // 'INVALID_FORMAT' | 'UNKNOWN_OPERATOR' | …}
TypeScript
Section titled “TypeScript”Every option, format and error code is a type, so the editor completes them and a typo fails to compile.
import { safeParsePhone, type PhoneNumber, type PhoneNumberFormat } from '@mdgascar/phone-number';import { spell, type SpellOptions } from '@mdgascar/number-words';import type { ErrorCode } from '@mdgascar/phone-number';
function phoneOrError(input: string): PhoneNumber | ErrorCode { const result = safeParsePhone(input); return result.success ? result.data : result.error.code; // narrowed by `success`}
const format: PhoneNumberFormat = 'international'; // 'e164' | 'international' | 'national'const options: SpellOptions = { system: 'traditional' }; // 'standard' | 'traditional'spell(30_000_000, options); // 'telo safatsiroa'