Skip to content

Commit

Permalink
Add some utility functions to value-transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Bianca-Morris committed Dec 12, 2024
1 parent 36764a5 commit cadd8b4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions es/components/util/value-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ export function bytesToLargerUnit(bytes) {
return Math.round(bytes * 100) / 100 + ' ' + byteLevels[level];
}
}
export function bytesToLargerUnitNoUnits(bytes) {
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
if (bytes >= 1024 && level < byteLevels.length) {
return bytesToLargerUnitNoUnits(bytes / 1024, level + 1);
} else {
return Math.round(bytes * 100) / 100; // only render the appropriate value
}
}

export function bytesToLargerUnitOnly(bytes) {
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
if (bytes >= 1024 && level < byteLevels.length) {
return bytesToLargerUnitOnly(bytes / 1024, level + 1);
} else {
return byteLevels[level]; // only render the appropriate unit
}
}

export function roundLargeNumber(num) {
var decimalPlaces = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
Expand Down
16 changes: 16 additions & 0 deletions src/components/util/value-transforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ export function bytesToLargerUnit(bytes, level = 0){
}
}

export function bytesToLargerUnitNoUnits(bytes, level = 0){
if (bytes >= 1024 && level < byteLevels.length) {
return bytesToLargerUnitNoUnits(bytes / 1024, level + 1);
} else {
return (Math.round(bytes * 100) / 100); // only render the appropriate value
}
}

export function bytesToLargerUnitOnly(bytes, level = 0){
if (bytes >= 1024 && level < byteLevels.length) {
return bytesToLargerUnitOnly(bytes / 1024, level + 1);
} else {
return byteLevels[level]; // only render the appropriate unit
}
}

export function roundLargeNumber(num, decimalPlaces = 2, level = 0){
if (num >= 1000 && level < numberLevels.length) {
return roundLargeNumber(num / 1000, decimalPlaces, level + 1);
Expand Down

0 comments on commit cadd8b4

Please sign in to comment.