Commit 567927ca authored by Smari McCarthy's avatar Smari McCarthy
Browse files

Support more formats

parent a0ac45f9
......@@ -46,14 +46,17 @@ Marka.prototype.match = function() {
var optSpace = "[\\s]*";
var magnitudes = "(([Mm]illion|[Bb]illion|[Hh]undred|[Tt]housand|[Tt]rillion|[Ll]akh|[Cc]rore|[Ss]core)[\\s]*)*";
var currencyCode = "[A-Z]{2,3}";
var optCurrencyCode = "(" + currencyCode + "){0,1}";
var optAsterisk = "[*]{0,1}";
var optBraceOpen = "[\(]{0,1}";
var optBraceClose = "[\)]{0,1}";
var format1 = numbers + optSpace + magnitudes + optSpace + currencyCode;
var format2 = currencySymbols + optSpace + numbers + optSpace + magnitudes + optSpace + "(" + optAsterisk + "|" + optBraceOpen + currencyCode + optBraceClose + ")";
var format3 = numbers + optSpace + magnitudes + optSpace + currencyWords;
var optBraceOpen = "[\\(]{0,1}";
var optBraceClose = "[\\)]{0,1}";
var formats = [];
formats.push(currencySymbols + optSpace + numbers + optSpace + magnitudes + optSpace + optCurrencyCode);
formats.push(numbers + optSpace + magnitudes + optSpace + currencyCode);
formats.push(optCurrencyCode + currencySymbols + optSpace + numbers + optSpace + magnitudes + optSpace + "(" + optAsterisk + "|" + optBraceOpen + currencyCode + optBraceClose + ")");
formats.push(numbers + optSpace + magnitudes + optSpace + currencyWords);
var regex = new RegExp("(" + format1 + "|" + format2 + "|" + format3 + ")", "g")
var regex = new RegExp("(" + formats.join("|") + ")", "g")
findAndReplaceDOMText(this.target, {
find: regex,
wrap: this.wrapNode()
......@@ -119,7 +122,8 @@ Marka.prototype.splitSymbols = function(text) {
Marka.prototype.findSymbol = function(text) {
var result = {certain: false, symbol: null}
text = $.trim(text);
text = text.replace(/[\s]+/g, "");
console.log("TEXT: >" + text + "<" + text.length)
if (text.match(/[A-Z]{3}/)) {
for (code in currency_info) {
if (code == text) {
......@@ -128,7 +132,18 @@ Marka.prototype.findSymbol = function(text) {
return result;
}
}
} else if (text.match(/[$€¥]/)) {
} else if (text.length == 3) {
if (text == "US$" || text == "$US") {
result.symbol = "USD";
result.certain = true;
} else if (text == "CA$" || text == "$CA") {
result.symbol = "CAD";
result.certain = true;
} else if (text == "AU$" || text == "$AU") {
result.symbol = "AUD";
result.certain = true;
}
} else if (text.match(RegExp(this.currencySymbols))) {
for (code in currency_info) {
if (currency_info[code].symbol == text) {
result.symbol = code;
......@@ -156,7 +171,7 @@ Marka.prototype.findSymbol = function(text) {
}
}
}
console.log(result);
return result;
}
......
......@@ -24,6 +24,8 @@
<li>$99 US</li>
<li>$99 AU</li>
<li>$99 CA</li>
<li>$99CA</li>
<li>$ 99CA</li>
<li>€902</li>
<li>$ 99 CA</li>
<li>€ 902</li>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment