@linzjs/step-ag-grid 14.9.2 → 14.9.3

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "14.9.2",
5
+ "version": "14.9.3",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -44,7 +44,6 @@
44
44
  "react": ">=17",
45
45
  "react-dom": ">=17",
46
46
  "react-transition-state": "^2.0.2",
47
- "sanitize-filename": "^1.6.3",
48
47
  "uuid": "^9.0.0"
49
48
  },
50
49
  "scripts": {
@@ -13,7 +13,17 @@ describe("sanitiseFileName", () => {
13
13
  expect(isFloat(".1")).toBe(true);
14
14
  });
15
15
  test("sanitiseFileName", () => {
16
- expect(sanitiseFileName(" LT 1235/543 &%//*$ ")).toBe("LT_1235-543_&%-$");
17
- expect(sanitiseFileName(" @filename here!!! ")).toBe("@filename_here!!!");
16
+ expect(sanitiseFileName(" LT 1235/543 &%//*$.csv ")).toBe("LT_1235-543_-.csv");
17
+ expect(sanitiseFileName(" @filename here!!!.csv ")).toBe("filename_here.csv");
18
+ // Trim to 64 char max for non extension part
19
+ expect(sanitiseFileName("long_long_long_long_long_long_long_long_long_long_long_long_long_long_.csv")).toBe(
20
+ "long_long_long_long_long_long_long_long_long_long_long_long_long.csv",
21
+ );
22
+ // Test with no extension
23
+ expect(sanitiseFileName("long_long_long_long_long_long_long_long_long_long_long_long_long_long_")).toBe(
24
+ "long_long_long_long_long_long_long_long_long_long_long_long_long",
25
+ );
26
+ // Test with no name
27
+ expect(sanitiseFileName(".csv")).toBe(".csv");
18
28
  });
19
29
  });
package/src/utils/util.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { isEmpty, negate } from "lodash-es";
2
- import sanitize from "sanitize-filename";
3
2
 
4
3
  export const isNotEmpty = negate(isEmpty);
5
4
 
@@ -47,11 +46,15 @@ export const stringByteLengthIsInvalid = (str: string, maxBytes: number) =>
47
46
 
48
47
  export const fnOrVar = (fn: any, param: any) => (typeof fn === "function" ? fn(param) : fn);
49
48
 
50
- /**
51
- * Trim filename and replaces troublesome characters.
52
- *
53
- * e.g. " LT 1235/543 &%//*$ " => "LT_1235-543_&%-$"
54
- * e.g. " @filename here!!!" => "@filename_here!!!"
55
- */
56
- export const sanitiseFileName = (filename: string): string =>
57
- sanitize(filename.trim().replaceAll(/(\/|\\)+/g, "-")).replaceAll(/\s+/g, "_");
49
+ export const sanitiseFileName = (filename: string): string => {
50
+ const valid = filename
51
+ .trim()
52
+ .replaceAll(/(\/|\\)+/g, "-")
53
+ .replaceAll(/\s+/g, "_")
54
+ .replaceAll(/[^\w\-āēīōūĀĒĪŌŪ.]/g, "");
55
+ const parts = valid.split(".");
56
+ const fileExt = parts.length > 1 ? parts.pop() : undefined;
57
+ // Arbitrary max filename length of 64 chars + extension
58
+ if (!fileExt) return valid.slice().slice(0, 64);
59
+ return valid.slice(0, -fileExt.length - 1).slice(0, 64) + "." + fileExt;
60
+ };