Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Monster
Manage
Activity
Members
Plan
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Javascript
Monster
Commits
602c1604
Verified
Commit
602c1604
authored
2 years ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: Updated regex to capture the negative sign
parent
7fd44c5f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
application/source/dom/dimension.mjs
+1
-2
1 addition, 2 deletions
application/source/dom/dimension.mjs
development/test/cases/dom/dimension.mjs
+10
-1
10 additions, 1 deletion
development/test/cases/dom/dimension.mjs
with
11 additions
and
3 deletions
application/source/dom/dimension.mjs
+
1
−
2
View file @
602c1604
...
@@ -74,7 +74,7 @@ function getDeviceDPI() {
...
@@ -74,7 +74,7 @@ function getDeviceDPI() {
*/
*/
function
convertToPixels
(
value
,
parentElement
=
document
.
documentElement
,
fontSizeElement
=
document
.
documentElement
)
{
function
convertToPixels
(
value
,
parentElement
=
document
.
documentElement
,
fontSizeElement
=
document
.
documentElement
)
{
const
regex
=
/^
([\d
.
]
+
)(
.*
)
$/
;
const
regex
=
/^
(
-
?
[\d
.
]
+
)(
.*
)
$/
;
const
matchResult
=
value
.
match
(
regex
);
const
matchResult
=
value
.
match
(
regex
);
if
(
!
matchResult
)
{
if
(
!
matchResult
)
{
...
@@ -82,7 +82,6 @@ function convertToPixels(value, parentElement = document.documentElement, fontSi
...
@@ -82,7 +82,6 @@ function convertToPixels(value, parentElement = document.documentElement, fontSi
}
}
const
[,
num
,
unit
]
=
matchResult
;
const
[,
num
,
unit
]
=
matchResult
;
const
number
=
parseFloat
(
num
);
const
number
=
parseFloat
(
num
);
const
dpi
=
getDeviceDPI
();
const
dpi
=
getDeviceDPI
();
...
...
This diff is collapsed.
Click to expand it.
development/test/cases/dom/dimension.mjs
+
10
−
1
View file @
602c1604
...
@@ -71,6 +71,15 @@ describe('dimension', () => {
...
@@ -71,6 +71,15 @@ describe('dimension', () => {
expect
(
errorFn
).
to
.
throw
(
Error
,
`Invalid value format:
${
invalidValue
}
`
);
expect
(
errorFn
).
to
.
throw
(
Error
,
`Invalid value format:
${
invalidValue
}
`
);
});
});
it
(
"
should handle negative values correctly
"
,
()
=>
{
const
negativeValue
=
"
-10px
"
;
const
expectedResult
=
-
10
;
const
result
=
convertToPixels
(
negativeValue
);
expect
(
result
).
to
.
equal
(
expectedResult
);
});
it
(
'
should correctly convert em values
'
,
()
=>
{
it
(
'
should correctly convert em values
'
,
()
=>
{
const
testElement
=
document
.
createElement
(
'
div
'
);
const
testElement
=
document
.
createElement
(
'
div
'
);
testElement
.
style
.
fontSize
=
'
16px
'
;
testElement
.
style
.
fontSize
=
'
16px
'
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment