I used to convert Arabic numbers to Latin numbers by doing the following
moment.updateLocale('ar', <MomentLanguage>{
preparse: (str) => {
return str.replace(/\u200f/g, '');
},
postformat: (str) => {
return str;
}
});
but now, MomentLanguage is not a module in moment, what should I do?
PS: I'm using version 2.15.2
Your code is written with Typescript, right? I think the interface you're using is called Locale
now.
Closing since we haven't heard back since Lucas' comment. Reopen if you still need help.
@IbraheemAlSaady this should work
const symbolMap = {
'1': '1',
'2': '2',
'3': '3',
'4': '4',
'5': '5',
'6': '6',
'7': '7',
'8': '8',
'9': '9',
'0': '0'
};
const numberMap = {
'Ù¡': '1',
'Ù¢': '2',
'Ù£': '3',
'Ù¤': '4',
'Ù¥': '5',
'Ù¦': '6',
'Ù§': '7',
'Ù¨': '8',
'Ù©': '9',
'Ù ': '0'
}
moment.updateLocale('ar', {
preparse: function (string) {
return string.replace(/\u200f/g, '').replace(/[١٢٣٤٥٦٧٨٩٠]/g, function (match) {
return numberMap[match];
}).replace(/،/g, ',');
},
postformat: function(string) {
return string.replace(/\d/g, function(match) {
return symbolMap[match];
}).replace(/,/g, '،');
},
});
Most helpful comment
@IbraheemAlSaady this should work