Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/homaily/fix-arabic-numbers
Replace arabic numbers with engilsh ones.
https://github.com/homaily/fix-arabic-numbers
Last synced: 25 days ago
JSON representation
Replace arabic numbers with engilsh ones.
- Host: GitHub
- URL: https://github.com/homaily/fix-arabic-numbers
- Owner: homaily
- License: mit
- Created: 2015-12-20T10:02:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-03T09:43:34.000Z (almost 9 years ago)
- Last Synced: 2024-08-03T19:07:42.834Z (4 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 15
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-arabic - Fix Arabic Numbers - Simple Moment.js style library that changes Arabic numbers (١٢٣...) into (123...) (Programming Languages)
README
# fix-arabic-numbers
Replace arabic numbers with engilsh ones.### How to use
Simply pass a String, Object or an Array.
```js
var fixArabicNumbers = require('fix-arabic-numbers');fixArabicNumbers('١٢٣٤٥٦٧٨٩٠ـ٪'); // return '1234567890_%'
fixArabicNumbers(['١', '٢', 'test ٣', 'تجربة ٤']); // return ['1', '2', 'test 3', 'تجربة 4']
fixArabicNumbers({test: '١٢٣٤'}); // return {test: '1234'}
```#### How to use with Expressjs
You can use this module as a connect middleware to fix `req.body` and `req.query` by using `fixArabicNumbers.connect` middleware
```js
var express = require('express');
var fixArabicNumbers = require('fix-arabic-numbers');var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());// use connect middleware after using body-parser.
app.use(fixArabicNumbers.connect);app.get('/', function (req, res) {
// req.body & req.query now checked and fixed.
})```
#### How to fix Expressjs `req.params`
`req.params` are processed by express router on requrst. to fix `req.params` you could use `fixArabicNumbers.params` middleware
```js
var express = require('express');
var fixArabicNumbers = require('fix-arabic-numbers');var app = express();
app.get('/', fixArabicNumbers.params, function (req, res) {
// req.params now checked and fixed.
})```
## License
[MIT](LICENSE)