@knime/utils 1.9.2 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @knime/utils
2
2
 
3
+ ## 1.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - b27134e: Resolve ignored audit issue (DOMPurify)
8
+
9
+ ## 1.10.0
10
+
11
+ ### Minor Changes
12
+
13
+ - ea3b7e1: Add util to format file-sizes
14
+
3
15
  ## 1.9.2
4
16
 
5
17
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knime/utils",
3
- "version": "1.9.2",
3
+ "version": "1.10.1",
4
4
  "description": "Internal utility functions and constants shared across @knime packages.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,8 @@
14
14
  "dependencies": {
15
15
  "date-fns": "2.30.0",
16
16
  "date-fns-tz": "2.0.0",
17
- "dompurify": "^3.2.7"
17
+ "dompurify": "^3.3.2",
18
+ "filesize": "10.0.6"
18
19
  },
19
20
  "peerDependencies": {
20
21
  "consola": "3.x"
package/src/format.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { filesize } from "filesize";
2
+
1
3
  import getLocalTimeZone from "./localTimezone";
2
4
  /**
3
5
  * Converts the specified date String to human readable text containing the day, month, and year.
@@ -95,3 +97,17 @@ export const formatDateTimeString = (
95
97
  */
96
98
  export const formatLocalDateTimeString = (date: string, showTime: boolean) =>
97
99
  showTime ? formatDateTimeString(date, true) : formatDateString(date, true);
100
+
101
+ export const formatFileSize = (bytes: number, decimals = 1): string => {
102
+ const safeBytes = Number.isFinite(bytes) && bytes >= 0 ? bytes : 0;
103
+ const safeDecimals =
104
+ Number.isFinite(decimals) && decimals >= 0 ? Math.floor(decimals) : 0;
105
+
106
+ return filesize(safeBytes, {
107
+ output: "string",
108
+ base: 2,
109
+ standard: "iec",
110
+ round: safeDecimals,
111
+ pad: true,
112
+ }) as string;
113
+ };
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import { filters } from "./filters";
5
5
  import {
6
6
  formatDateString,
7
7
  formatDateTimeString,
8
+ formatFileSize,
8
9
  formatLocalDateTimeString,
9
10
  formatTimeString,
10
11
  } from "./format";
@@ -55,6 +56,7 @@ export {
55
56
  filters,
56
57
  formatDateString,
57
58
  formatDateTimeString,
59
+ formatFileSize,
58
60
  getDeepActiveElement,
59
61
  formatLocalDateTimeString,
60
62
  formatTimeString,