Search code examples
typescriptmoney-formatnumeral.js

I need a TypeScript library to, format money and numbers, perform localization operations


I'm developing a mobile application using React-Native and TypeScript super-set. I am looking for a format library in which I can perform numbers, currencies, dates, numbers and localizations.

I've used the Numeral JS library before, but the format range is too narrow, and I tried the autoNumeric library, but I didn't have the possibility to use it because @types was not available.

Apart from this, I did not get the efficiency I wanted from many libraries. I'd love to hear your suggestions.


Solution

  • Even if @types is not available you can still use the autoNumeric library by adding your own type definition.

    1. Add a @types folder inside project folder
    2. Create a file named .d.ts

    Add @types folder here

    1. Inside the file add the following line

      declare module 'autonumeric';

    2. Add the path of the newly created folder in tsconfig.json under compilerOptions like so

      "typeRoots": ["node_modules/@types", "src/@types"]

      Note: "node_modules/@types" will already be present. You only need to add the newly path of the new folder.

    3. Save. Run npm i and then start the application.