NPM package that converts Arabic and Persian numbers to English equivalent to avoid data inconsistency.
MIT License
Convert Numbers is a utility package designed to ensure consistency in data transfer by converting Arabic and Persian numerals to English numerals. This tool is essential when user inputs might originate from different keyboard settings, requiring standardization of all digits to English format before further processing or database storage.
Check out the working demo on CodeSandbox:
Install the package using npm or yarn:
npm i @smakss/convert-numbers
# or
yarn add @smakss/convert-numbers
Import convertNumbers
into your project as a CommonJS or ECMAScript module:
ECMAScript Modules:
import ConvertNumbers from '@smakss/convert-numbers';
Then, use the function like this:
// Converts Persian numbers to '1234567890'
console.log(ConvertNumbers('۱۲۳۴۵۶۷۸۹۰'));
// Converts Arabic numbers to '1234567890'
console.log(ConvertNumbers('١٢٣٤٥٦٧٨٩٠'));
// Returns an empty string for no input
console.log(ConvertNumbers());
for-of
loop iteration.For more detailed examples and information about the function usage, refer to the JSDoc comments in the source code.
We welcome contributions! For guidelines on how to contribute, please check CONTRIBUTING.md.
We are committed to fostering a welcoming and positive community. Please see our Code of Conduct for more information.