Skip to content
GitHub

Guides

Choose your settings once

One object with every writer of the library and your choices built in, in TypeScript and PHP.

Every writer has options: the number system, the money layout, the phone format, the date style. Passing them on every call is noise. Choose them once and call plain functions everywhere.

import { createMalagasy } from '@mdgascar/malagasy-intl';
const mg = createMalagasy({ phoneFormat: 'international' });
mg.words(21); // 'iraika amby roapolo'
mg.ordinal(3); // 'fahatelo'
mg.money(1500); // '1 500 Ar'
mg.phone('0341234567'); // '+261 34 12 345 67'
mg.date('2026-11-23'); // '23 Novambra 2026'
mg.time('14:30'); // "amin'ny roa ora sy telopolo minitra tolakandro"
mg.error('INVALID_FORMAT', 'fr'); // a message for the end user, in French
use Mdgascar\MalagasyIntl\Malagasy;
use Mdgascar\MalagasyIntl\PhoneNumber\PhoneNumberFormat;
$mg = new Malagasy(phoneFormat: PhoneNumberFormat::International);
$mg->words(21); // 'iraika amby roapolo'
$mg->phone('0341234567'); // '+261 34 12 345 67'
$mg->date('2026-11-23'); // '23 Novambra 2026'
Setting Values Default
system standard or traditional words standard
ariary the layout options of formatAriary 1 500 Ar
phoneFormat national, international or e164 national
dateStyle long, full, medium, short or numeric the library default (long)

In TypeScript a setting that does not exist is INVALID_TYPE. In PHP the constructor is typed, so it cannot be mistyped.

date, time and dateTime also take Unix milliseconds, such as Date.now(), and a PHP date object. A number is read as milliseconds only between 2001 and 2200; anything else is INVALID_TYPE, because it is probably seconds.