Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
libre
marka
Commits
567927ca
Commit
567927ca
authored
Jan 27, 2016
by
Smari McCarthy
Browse files
Support more formats
parent
a0ac45f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
9 deletions
+26
-9
js/marka.js
js/marka.js
+24
-9
test/format.html
test/format.html
+2
-0
No files found.
js/marka.js
View file @
567927ca
...
...
@@ -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
(
"
(
"
+
format
1
+
"
|
"
+
format2
+
"
|
"
+
format3
+
"
)
"
,
"
g
"
)
var
regex
=
new
RegExp
(
"
(
"
+
format
s
.
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
;
}
...
...
test/format.html
View file @
567927ca
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment