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

Repository files navigation

Convert Numbers

npm NPM npm npm bundle size (scoped)

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.

Demo

You can check the working demo on CodeSandbox:

View @smakss/convert-numbers

Installation

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

Usage

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());

Documentation

For more detailed examples and function usage, please refer to the JSDoc comments within the code.

Contributing

Contributions to the project are welcome! Please refer to CONTRIBUTING.md for contribution guidelines.

Code of Conduct

To maintain a welcoming and positive community, please see our Code of Conduct.