Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a7652553
Commit
a7652553
authored
May 29, 2017
by
kushalpandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `bytesToMiB` converter method
parent
233d1ee8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
1 deletion
+18
-1
app/assets/javascripts/lib/utils/number_utils.js
app/assets/javascripts/lib/utils/number_utils.js
+10
-0
spec/javascripts/lib/utils/number_utility_spec.js
spec/javascripts/lib/utils/number_utility_spec.js
+8
-1
No files found.
app/assets/javascripts/lib/utils/number_utils.js
View file @
a7652553
...
@@ -42,3 +42,13 @@ export function formatRelevantDigits(number) {
...
@@ -42,3 +42,13 @@ export function formatRelevantDigits(number) {
export
function
bytesToKiB
(
number
)
{
export
function
bytesToKiB
(
number
)
{
return
number
/
BYTES_IN_KIB
;
return
number
/
BYTES_IN_KIB
;
}
}
/**
* Utility function that calculates MiB of the given bytes.
*
* @param {Number} number bytes
* @return {Number} MiB
*/
export
function
bytesToMiB
(
number
)
{
return
number
/
(
BYTES_IN_KIB
*
BYTES_IN_KIB
);
}
spec/javascripts/lib/utils/number_utility_spec.js
View file @
a7652553
import
{
formatRelevantDigits
,
bytesToKiB
}
from
'
~/lib/utils/number_utils
'
;
import
{
formatRelevantDigits
,
bytesToKiB
,
bytesToMiB
}
from
'
~/lib/utils/number_utils
'
;
describe
(
'
Number Utils
'
,
()
=>
{
describe
(
'
Number Utils
'
,
()
=>
{
describe
(
'
formatRelevantDigits
'
,
()
=>
{
describe
(
'
formatRelevantDigits
'
,
()
=>
{
...
@@ -45,4 +45,11 @@ describe('Number Utils', () => {
...
@@ -45,4 +45,11 @@ describe('Number Utils', () => {
expect
(
bytesToKiB
(
1000
)).
toEqual
(
0.9765625
);
expect
(
bytesToKiB
(
1000
)).
toEqual
(
0.9765625
);
});
});
});
});
describe
(
'
bytesToMiB
'
,
()
=>
{
it
(
'
calculates MiB for the given bytes
'
,
()
=>
{
expect
(
bytesToMiB
(
1048576
)).
toEqual
(
1
);
expect
(
bytesToMiB
(
1000000
)).
toEqual
(
0.95367431640625
);
});
});
});
});
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