-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from espenja/features/70-add-file-size
feat: add support for file_size tag
- Loading branch information
Showing
7 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,33 @@ | ||
import humanFileSize from "file-size"; | ||
import type { Data } from "../data"; | ||
import { CONFIG_KEYS } from "../constants"; | ||
import { FileSizeConfig, FileSizeSpec, WorkspaceExtensionConfiguration } from "../config"; | ||
|
||
export const getFileSize = (config: WorkspaceExtensionConfiguration, dataClass: Data) => { | ||
if (dataClass.fileSize === undefined) return undefined; | ||
|
||
let fixed = 2; | ||
if (config[CONFIG_KEYS.FileSizeFixed] === 0 || config[CONFIG_KEYS.FileSizeFixed]) { | ||
fixed = config[CONFIG_KEYS.FileSizeFixed]; | ||
} | ||
|
||
let spacer = " "; | ||
if (config[CONFIG_KEYS.FileSizeSpacer] === "" || config[CONFIG_KEYS.FileSizeSpacer]) { | ||
spacer = config[CONFIG_KEYS.FileSizeSpacer]; | ||
} | ||
|
||
let fileSize: string | undefined = undefined; | ||
const fileSizeSpec: FileSizeSpec = config[CONFIG_KEYS.FileSizeSpec] || "iec"; | ||
const fileSizeConfig: FileSizeConfig = { | ||
fixed, | ||
spacer | ||
}; | ||
|
||
if (config[CONFIG_KEYS.FileSizeHumanReadable]) { | ||
fileSize = humanFileSize(dataClass.fileSize, fileSizeConfig).human(fileSizeSpec); | ||
} else { | ||
fileSize = `${dataClass.fileSize.toLocaleString()}${fileSizeConfig.spacer}B`; | ||
} | ||
|
||
return fileSize; | ||
}; |
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