Skip to content
GitHub

Installation

Every module in one package

@mdgascar/utils re-exports every module — words, phone, ariary and date — with one MdgError class, so you install and import from one place.

Choose this when an app uses several modules. Bundlers keep only the functions you import, so unused modules do not reach your users.

  1. Terminal
    npm install @mdgascar/utils
  2. invoice.ts
    import { ariaryToWords, formatAriary, formatDate, numberToWords } from '@mdgascar/utils';
    formatAriary(1500); // 'Ar 1 500'
    ariaryToWords(1500); // 'dimanjato sy arivo ariary'
    formatDate('2026-11-23', 'full'); // 'Alatsinainy 23 Novambra 2026'
    numberToWords(21); // 'iraika amby roapolo'
  3. Catch errors from every module the same way

    Section titled “Catch errors from every module the same way”

    Every module throws the same MdgError, so one catch covers them all.

    invoice.ts
    import { MdgError, parseAriary } from '@mdgascar/utils';
    try {
    parseAriary('1,500');
    } catch (error) {
    if (error instanceof MdgError) console.log(error.code); // 'INVALID_FORMAT'
    }