Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Julien Jerphanion
Rex Dri
Commits
33da560a
Commit
33da560a
authored
Mar 03, 2019
by
Florent Chehab
Browse files
Fixes
#73
removed firefox bug with regex
parent
ff8b40ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/utils/parseMoney.js
View file @
33da560a
...
...
@@ -4,11 +4,12 @@
* @returns
*/
function
getMoneyRegex
()
{
return
/
(?<
!`
)
:
(\d
*
[
.,
]?\d
*
)(\w{3})
:/g
;
// regex lookbehind is not supported in Firefox at this time
// can't use it to detect code markdown: /(?<!`):(\d*[.,]?\d*)(\w{3}):/g;
return
/:
(\d
*
[
.,
]?\d
*
)(\w{3})
:/g
;
}
/**
* Parses a string to determine if there are some currency in it.
*
...
...
@@ -46,7 +47,12 @@ export default function parseMoney(str) {
amount
=
parseFloat
(
match
[
"
1
"
].
replace
(
"
,
"
,
"
.
"
)),
// fix numbers with "," as decimal separators
currency
=
match
[
"
2
"
].
toUpperCase
();
// make sure the currency is uppercase
matches
.
push
({
matchStartIndex
,
matchLastIndex
,
amount
,
currency
});
// regex lookbehind is not supported in Firefox at this time
if
(
matchStartIndex
!==
0
&&
str
[
matchStartIndex
-
1
]
===
"
`
"
)
{
// ignore it's for code
}
else
{
matches
.
push
({
matchStartIndex
,
matchLastIndex
,
amount
,
currency
});
}
}
let
res
=
[],
lastIndex
=
0
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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