Convert Numbers is a utility package that helps ensure consistency in data transfer by converting Arabic and Persian numerals to English numerals. This is particularly useful when user inputs can come from different keyboard settings, and there's a need to standardize all digits to English format before sending data to a database or processing it further.
You can check the working demo on CodeSandbox:
To install the package, you can use npm or yarn with the following commands:
npm i @smakss/convert-numbers
# or
yarn add @smakss/convert-numbers
Import the convertNumbers
function into your project using CommonJS or ECMAScript modules:
CommonJS:
const ConvertNumbers = require('@smakss/convert-numbers');
ECMAScript Modules:
import ConvertNumbers from '@smakss/convert-numbers';
Then, use the function as follows:
// Returns '1234567890' for Persian numbers
console.log(ConvertNumbers('۱۲۳۴۵۶۷۸۹۰'));
// Returns '1234567890' for Arabic numbers
console.log(ConvertNumbers('١٢٣٤٥٦٧٨٩٠'));
// Returns "" for no input
console.log(ConvertNumbers());
For more detailed examples and function usage, please refer to the JSDoc comments within the code.
Contributions to the project are welcome! Please refer to CONTRIBUTING.md for contribution guidelines.
To maintain a welcoming and positive community, please see our Code of Conduct.