Created
May 6, 2023 14:32
-
-
Save ali-master/40def25cf445e675f67c3b107a2e4a08 to your computer and use it in GitHub Desktop.
Convert HTML document numbers to Persian Digits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.toPersianDigit = function (a) { | |
return this.replace(/\d+/g, function (digit) { | |
var enDigitArr = [], peDigitArr = []; | |
for (var i = 0; i < digit.length; i++) { | |
enDigitArr.push(digit.charCodeAt(i)); | |
} | |
for (var j = 0; j < enDigitArr.length; j++) { | |
peDigitArr.push(String.fromCharCode(enDigitArr[j] + ((!!a && a == true) ? 1584 : 1728))); | |
} | |
return peDigitArr.join(''); | |
}); | |
}; | |
function TraceNodes(Node) { | |
if (Node.nodeType == 3){ //TextNode | |
Node.nodeValue = Node.nodeValue.toPersianDigit(); | |
}else{ | |
for (var i = 0; i < Node.childNodes.length; i++){ | |
TraceNodes(Node.childNodes[i]); | |
} | |
} | |
} | |
TraceNodes(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment