Comparing version 2.1.1 to 3.0.0
{ | ||
"name": "eurodigit", | ||
"version": "2.1.1", | ||
"version": "3.0.0", | ||
"description": "Convert Hindu-Arabic numerals of different scripts into Western Arabic (European) digits.", | ||
@@ -5,0 +5,0 @@ "modules": "src/index.js", |
{ | ||
"name": "eurodigit", | ||
"version": "2.1.1", | ||
"version": "3.0.0", | ||
"description": "Convert Hindu-Arabic numerals of different scripts into Western Arabic (European) digits.", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"test": "grunt test" | ||
"test": "grunt" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
'use strict'; | ||
/* Magic number: 2406 is the char code for '०' */ | ||
function replacer(c) { return c.charCodeAt(0) - 2406; } | ||
function replacer(c) { | ||
c = c.charCodeAt(0); | ||
if(c < 1642) return c - 1632; // western arabic | ||
if(c < 1786) return c - 1776; // perso-arabic | ||
return c - 2406; // devanagari | ||
} | ||
module.exports = function(original) { | ||
return original && original.toString().replace(/[०-९]/g, replacer); | ||
return original && original.toString().replace(/[٠-٩۰-۹०-९]/g, replacer); | ||
}; |
@@ -22,2 +22,14 @@ var assert = require('chai').assert; | ||
it('should translate Eastern Arabic numerals', function() { | ||
// expect | ||
assertTranslation('0 1 2 3 4 5 6 7 8 9', | ||
'٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩'); | ||
}); | ||
it('should translate Perso-Arabic numerals', function() { | ||
// expect | ||
assertTranslation('0 1 2 3 4 5 6 7 8 9', | ||
'۰ ۱ ۲ ۳ ۴ ۵ ۶ ۷ ۸ ۹'); | ||
}); | ||
it('should ignore irrelevant text', function() { | ||
@@ -24,0 +36,0 @@ // expect |
7753
192