Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
a0f0699a85 | |||
adcd6eaf79 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.15.4",
|
||||
"version": "0.15.6",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
@ -10,7 +10,7 @@ export type HttpRequestOptions = {
|
||||
decode?: boolean;
|
||||
fragment?: string;
|
||||
headers?: {[key: string | symbol]: string | null | undefined};
|
||||
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
||||
method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
||||
query?: {key: string, value: string}[] | {[key: string]: string};
|
||||
url?: string;
|
||||
[key: string]: any;
|
||||
|
@ -6,6 +6,14 @@ export function createHex(length: number) {
|
||||
return Array(length).fill(null).map(() => Math.round(Math.random() * 0xF).toString(16)).join('');
|
||||
}
|
||||
|
||||
export function formatBytes(bytes: number, decimals = 2) {
|
||||
if (bytes === 0) return '0 Bytes';
|
||||
const k = 1024;
|
||||
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* String of all letters
|
||||
*
|
||||
|
Reference in New Issue
Block a user