-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Dashboard table item for Rate Limits
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { HumanReadableFilterPipe } from './humanreadable.filter.pipe'; | ||
|
||
describe('HumanReadableFilterPipe', () => { | ||
const pipe = new HumanReadableFilterPipe(); | ||
|
||
const datatable = [{ | ||
'given': '180000000000', | ||
'expected': '180s' | ||
}, | ||
{ | ||
'given': '4096.0', | ||
'expected': '4096ns' | ||
}, | ||
{ | ||
'given': '7200000000000', | ||
'expected': '120m' | ||
}, | ||
{ | ||
'given': '1337', | ||
'expected': '1337ns' | ||
}, | ||
{ | ||
'given': 'traefik', | ||
'expected': 'traefik', | ||
}, | ||
{ | ||
'given': '-23', | ||
'expected': '-23', | ||
}, | ||
{ | ||
'given': '0', | ||
'expected': '0', | ||
}, | ||
]; | ||
|
||
datatable.forEach(item => { | ||
it((item.given + ' should be transformed to ' + item.expected ), () => { | ||
expect(pipe.transform(item.given)).toEqual(item.expected); | ||
}); | ||
}); | ||
|
||
it('create an instance', () => { | ||
expect(pipe).toBeTruthy(); | ||
}); | ||
|
||
}); |
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,27 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
/** | ||
* HumanReadableFilterPipe converts a time period in nanoseconds to a human-readable | ||
* string. | ||
*/ | ||
@Pipe({name: 'humanreadable'}) | ||
export class HumanReadableFilterPipe implements PipeTransform { | ||
transform(value): any { | ||
let result = ''; | ||
const powerOf10 = Math.floor(Math.log10(value)); | ||
|
||
if (powerOf10 > 11) { | ||
result = value / (60 * Math.pow(10, 9)) + 'm'; | ||
} else if (powerOf10 > 9) { | ||
result = value / Math.pow(10, 9) + 's'; | ||
} else if (powerOf10 > 6) { | ||
result = value / Math.pow(10, 6) + 'ms'; | ||
} else if (value > 0) { | ||
result = Math.floor(value) + 'ns'; | ||
} else { | ||
result = value; | ||
} | ||
|
||
return result; | ||
} | ||
} |
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