Skip to content
GitHub

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.

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

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.

  1. Add the module you need. This example uses phone numbers.

    Terminal
    npm install @mdgascar/phone-number
  2. 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'
  3. parse… functions throw an MalagasyIntlError. Use safeParse… to get the error code without throwing, or tryParse… to get undefined.

    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
  4. 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' | …
    }

Every option, format and error code is a type, so the editor completes them and a typo fails to compile.

signup.ts
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'