forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI: Show diff in bytes instead of percentage (mrdoob#25630)
* CI: Show diff in bytes instead of percentage * Fix order
- Loading branch information
1 parent
0e29a44
commit 5d558d9
Showing
5 changed files
with
26 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// used in report-size.yml | ||
import { formatBytes } from './formatBytes.js'; | ||
|
||
const filesize = Number( process.argv[ 2 ] ); | ||
const filesizeBase = Number( process.argv[ 3 ] ); | ||
|
||
const diff = ( filesize - filesizeBase ) * 100 / filesizeBase; | ||
const diffString = diff.toFixed( 2 ).slice( - 1 ) === '0' ? diff.toFixed( 1 ) : diff.toFixed( 2 ); | ||
const formatted = `${diff >= 0 ? '+' : ''}${diffString}%`; | ||
const diff = filesize - filesizeBase; | ||
const formatted = `${diff >= 0 ? '+' : '-'}${formatBytes( Math.abs( diff ), 2 )}`; | ||
|
||
console.log( formatted ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function formatBytes( bytes, decimals = 1 ) { | ||
|
||
if ( bytes === 0 ) return '0 B'; | ||
|
||
const k = 1000; | ||
const dm = decimals < 0 ? 0 : decimals; | ||
const sizes = [ 'B', 'kB', 'MB', 'GB' ]; | ||
|
||
const i = Math.floor( Math.log( bytes ) / Math.log( k ) ); | ||
|
||
return parseFloat( ( bytes / Math.pow( k, i ) ).toFixed( dm ) ) + ' ' + sizes[ i ]; | ||
|
||
} |