karyal-ps-digits
Version:
40 lines (29 loc) • 857 B
JavaScript
const enDigits = '0123456789'.split('');
const psDigits = '۰۱۲۳۴۵۶۷۸۹'.split('');
function en2ps(value) {
let result = '';
for (let digit of new String(value)) {
if (enDigits.indexOf(digit) >= 0) {
result += psDigits[enDigits.indexOf(digit)];
continue;
}
result += digit;
}
return result;
}
function ps2en(value) {
let result = '';
for (let digit of new String(value)) {
if (psDigits.indexOf(digit) >= 0) {
result += enDigits[psDigits.indexOf(digit)];
continue;
}
result += digit;
}
return result;
}
// console.log( en2ps('48573') );
// console.log( en2ps('A5 B12') );
// console.log( ps2en('۴۸۵۸۹') );
// exports = {en2ps, ps2en};
module.exports = {en2ps, ps2en};