@knime/utils 1.2.0 → 1.2.2
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 +12 -0
- package/package.json +1 -1
- package/src/fileExtensions.ts +24 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @knime/utils
|
|
2
2
|
|
|
3
|
+
## 1.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 96ce3a3: Add util to get file name without extension
|
|
8
|
+
|
|
9
|
+
## 1.2.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- d58ea81: Fix direct import to prevent typescript error
|
|
14
|
+
|
|
3
15
|
## 1.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knime/utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Internal utility functions and constants shared across @knime packages.",
|
|
5
5
|
"homepage": "https://knime.github.io/webapps-common/",
|
|
6
6
|
"license": "GPL 3 and Additional Permissions according to Sec. 7 (SEE the file LICENSE)",
|
package/src/fileExtensions.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Gets the file extension
|
|
3
|
+
* @param nameOrPath can take a full file name (e.g "file.txt") or a path to a file
|
|
4
|
+
* (e.g "file://path/to/file.txt" OR "/path/to/file.txt")
|
|
5
|
+
* @returns just the file extension (e.g "txt")
|
|
6
|
+
*/
|
|
7
|
+
export const getFileExtension = (nameOrPath: string): string => {
|
|
8
|
+
const basename = nameOrPath.split(/[\\/]/).pop() ?? "";
|
|
9
|
+
|
|
10
|
+
const parts = basename.split(".");
|
|
4
11
|
|
|
5
|
-
if (basename === "" ||
|
|
12
|
+
if (basename === "" || parts.length === 1) {
|
|
6
13
|
return "";
|
|
7
14
|
}
|
|
8
15
|
|
|
9
|
-
return
|
|
16
|
+
return parts.at(-1) ?? "";
|
|
10
17
|
};
|
|
11
18
|
|
|
12
19
|
/**
|
|
@@ -32,6 +39,18 @@ const KNWF = Object.freeze({
|
|
|
32
39
|
const extension = getFileExtension(file.name);
|
|
33
40
|
return extension === this.extension;
|
|
34
41
|
},
|
|
42
|
+
/**
|
|
43
|
+
* Gets the name of a .knwf file without the extension. If the file is not
|
|
44
|
+
* matched as a .knwf file then this function will return the default value,
|
|
45
|
+
* which is empty string ("") if param is not provided
|
|
46
|
+
*/
|
|
47
|
+
getNameOrDefault(file: File, defaultValue = ""): string {
|
|
48
|
+
if (!this.matches(file)) {
|
|
49
|
+
return defaultValue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return file.name.replace(`.${this.extension}`, "");
|
|
53
|
+
},
|
|
35
54
|
});
|
|
36
55
|
|
|
37
56
|
export const knimeFileFormats = { KNAR, KNWF };
|