Hugo Bernier f583732935 React Comparer Web Part (#768)
* Initial version

* Added more property pane fields

* Fixed recent tab style

* Update RecentFilesTab.module.scss

* Update RecentFilesTab.tsx

* Fixed an issue with unitialized PnP  causing wrong API url

* Update package-solution.json

* Cleaned up code and comments.

* Update FileBrowser.tsx

* Update FileBrowser.types.ts

* Update DocumentLibraryBrowser.tsx

* Update RecentFilesTab.tsx

* Added OneDrive support

* Fixed a little speelliing mistake
2019-02-09 12:19:31 +02:00

29 lines
774 B
TypeScript

import * as strings from 'PropertyPaneFilePickerStrings';
/**
* Formats a file size in the right unit
* TODO: Move to a common library
*/
export function FormatBytes(bytes, decimals) {
if (bytes == 0) {
return strings.EmptyFileSize;
}
const k: number = 1024;
const dm = decimals <= 0 ? 0 : decimals || 2;
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + strings.SizeUnit[i];
}
/**
* Gets the current domain url
*/
export function GetAbsoluteDomainUrl(url: string): string {
if (url !== undefined) {
const myURL = new URL(url.toLowerCase());
return myURL.protocol + "//" + myURL.host;
} else {
return undefined;
}
}