Apply new eslint rules; default to prettier for styling
This commit is contained in:
parent
f22cce8881
commit
dc84af9937
218 changed files with 3876 additions and 3564 deletions
|
@ -13,25 +13,25 @@ describe('@/lib/formatters.ts', function () {
|
|||
|
||||
describe('bytesToString()', function () {
|
||||
it.each([
|
||||
[ 0, '0 Bytes' ],
|
||||
[ 0.5, '0 Bytes' ],
|
||||
[ 0.9, '0 Bytes' ],
|
||||
[ 100, '100 Bytes' ],
|
||||
[ 100.25, '100.25 Bytes' ],
|
||||
[ 100.998, '101 Bytes' ],
|
||||
[ 512, '512 Bytes' ],
|
||||
[ 1000, '1 KB' ],
|
||||
[ 1024, '1.02 KB' ],
|
||||
[ 5068, '5.07 KB' ],
|
||||
[ 10_000, '10 KB' ],
|
||||
[ 11_864, '11.86 KB' ],
|
||||
[ 1_000_000, '1 MB' ],
|
||||
[ 1_356_000, '1.36 MB' ],
|
||||
[ 1_024_000, '1.02 MB' ],
|
||||
[ 1_000_000_000, '1 GB' ],
|
||||
[ 1_024_000_000, '1.02 GB' ],
|
||||
[ 1_678_342_000, '1.68 GB' ],
|
||||
[ 1_000_000_000_000, '1 TB' ],
|
||||
[0, '0 Bytes'],
|
||||
[0.5, '0 Bytes'],
|
||||
[0.9, '0 Bytes'],
|
||||
[100, '100 Bytes'],
|
||||
[100.25, '100.25 Bytes'],
|
||||
[100.998, '101 Bytes'],
|
||||
[512, '512 Bytes'],
|
||||
[1000, '1 KB'],
|
||||
[1024, '1.02 KB'],
|
||||
[5068, '5.07 KB'],
|
||||
[10_000, '10 KB'],
|
||||
[11_864, '11.86 KB'],
|
||||
[1_000_000, '1 MB'],
|
||||
[1_356_000, '1.36 MB'],
|
||||
[1_024_000, '1.02 MB'],
|
||||
[1_000_000_000, '1 GB'],
|
||||
[1_024_000_000, '1.02 GB'],
|
||||
[1_678_342_000, '1.68 GB'],
|
||||
[1_000_000_000_000, '1 TB'],
|
||||
])('should format %d bytes as "%s"', function (input, output) {
|
||||
expect(bytesToString(input)).toBe(output);
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@ const _CONVERSION_UNIT = 1000;
|
|||
/**
|
||||
* Given a value in megabytes converts it back down into bytes.
|
||||
*/
|
||||
function mbToBytes (megabytes: number): number {
|
||||
function mbToBytes(megabytes: number): number {
|
||||
return Math.floor(megabytes * _CONVERSION_UNIT * _CONVERSION_UNIT);
|
||||
}
|
||||
|
||||
|
@ -11,25 +11,21 @@ function mbToBytes (megabytes: number): number {
|
|||
* Given an amount of bytes, converts them into a human readable string format
|
||||
* using "1000" as the divisor.
|
||||
*/
|
||||
function bytesToString (bytes: number): string {
|
||||
function bytesToString(bytes: number): string {
|
||||
if (bytes < 1) return '0 Bytes';
|
||||
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(_CONVERSION_UNIT));
|
||||
const value = Number((bytes / Math.pow(_CONVERSION_UNIT, i)).toFixed(2));
|
||||
|
||||
return `${value} ${[ 'Bytes', 'KB', 'MB', 'GB', 'TB' ][i]}`;
|
||||
return `${value} ${['Bytes', 'KB', 'MB', 'GB', 'TB'][i]}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an IPv4 or IPv6 address.
|
||||
*/
|
||||
function ip (value: string): string {
|
||||
function ip(value: string): string {
|
||||
// noinspection RegExpSimplifiable
|
||||
return /([a-f0-9:]+:+)+[a-f0-9]+/.test(value) ? `[${value}]` : value;
|
||||
}
|
||||
|
||||
export {
|
||||
ip,
|
||||
mbToBytes,
|
||||
bytesToString,
|
||||
};
|
||||
export { ip, mbToBytes, bytesToString };
|
||||
|
|
|
@ -2,14 +2,14 @@
|
|||
* Given a valid six character HEX color code, converts it into its associated
|
||||
* RGBA value with a user controllable alpha channel.
|
||||
*/
|
||||
function hexToRgba (hex: string, alpha = 1): string {
|
||||
function hexToRgba(hex: string, alpha = 1): string {
|
||||
// noinspection RegExpSimplifiable
|
||||
if (!/#?([a-fA-F0-9]{2}){3}/.test(hex)) {
|
||||
return hex;
|
||||
}
|
||||
|
||||
// noinspection RegExpSimplifiable
|
||||
const [ r, g, b ] = hex.match(/[a-fA-F0-9]{2}/g)!.map(v => parseInt(v, 16));
|
||||
const [r, g, b] = hex.match(/[a-fA-F0-9]{2}/g)!.map((v) => parseInt(v, 16));
|
||||
|
||||
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
||||
}
|
||||
|
|
|
@ -12,19 +12,11 @@ describe('@/lib/objects.ts', function () {
|
|||
expect(isObject(null)).toBe(false);
|
||||
});
|
||||
|
||||
it.each([
|
||||
undefined,
|
||||
123,
|
||||
'foobar',
|
||||
() => ({}),
|
||||
Function,
|
||||
String(123),
|
||||
isObject,
|
||||
() => null,
|
||||
[],
|
||||
[ 1, 2, 3 ],
|
||||
])('should return false for %p', function (value) {
|
||||
expect(isObject(value)).toBe(false);
|
||||
});
|
||||
it.each([undefined, 123, 'foobar', () => ({}), Function, String(123), isObject, () => null, [], [1, 2, 3]])(
|
||||
'should return false for %p',
|
||||
function (value) {
|
||||
expect(isObject(value)).toBe(false);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* is not null.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
function isObject (val: unknown): val is {} {
|
||||
function isObject(val: unknown): val is {} {
|
||||
return typeof val === 'object' && val !== null && !Array.isArray(val);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ function isObject (val: unknown): val is {} {
|
|||
* and the prototype value.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
function isEmptyObject (val: {}): boolean {
|
||||
function isEmptyObject(val: {}): boolean {
|
||||
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ function isEmptyObject (val: {}): boolean {
|
|||
* easier.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
function getObjectKeys<T extends {}> (o: T): (keyof T)[] {
|
||||
function getObjectKeys<T extends {}>(o: T): (keyof T)[] {
|
||||
return Object.keys(o) as (keyof typeof o)[];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function capitalize (value: string): string {
|
||||
function capitalize(value: string): string {
|
||||
return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue