Skip to content

NPM package that converts Arabic and Persian numbers to English equivalent to avoid data inconsistency.

License

Notifications You must be signed in to change notification settings

SMAKSS/convert-numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Convert numbers

npm Snyk Vulnerabilities for npm package NPM npm npm bundle size (scoped)

Due to keeping consistency in our data transfer with API's we need to make sure digits or numbers entered by user inputs have always transferred by English. Since users could always fill data with different keyboard settings we need to make sure that we don't send Arabic or Persian numbers to our database. So to avoid such an inconsistency we should always translate our numbers or prevent a user from entering unwanted data. Convert numbers created for this cause to make sure every digit input is in standard format of it.

How it works?

To install it you can simply do the following command:

npm i @smakss/convert-numbers
or
yarn add @smakss/convert-numbers

to include it with common js module you should do this:

var ConvertNumbers = require('@smakss/convert-numbers');

and to include it with ECMAscript module you can simply do this one:

import ConvertNumbers from '@smakss/convert-numbers';

then to use it within your application you can do it just like this:

ConvertNumbers(); 

// Result: undefined 
// If you don't provide any input it will return undefined.
ConvertNumbers('۱۲۳۴۵۶۷۸۹۰');

// Result: '1234567890'
ConvertNumbers('١٢٣٤٥٦٧٨٩٠');

// Result: '1234567890'

Demo

You can check the working demo in runkit.