@jasperoosthoek/react-toolbox 0.5.7 → 0.6.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/README.md +1 -1
- package/change-log.md +6 -0
- package/dist/index.js +2 -2
- package/dist/index.js.LICENSE.txt +16 -2
- package/dist/utils/utils.d.ts +5 -0
- package/package.json +7 -9
- package/src/utils/hooks.ts +3 -1
- package/src/utils/utils.ts +24 -0
|
@@ -4,11 +4,25 @@
|
|
|
4
4
|
http://jedwatson.github.io/classnames
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/*!
|
|
8
|
+
* mime-db
|
|
9
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
10
|
+
* Copyright(c) 2015-2022 Douglas Christopher Wilson
|
|
11
|
+
* MIT Licensed
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/*!
|
|
15
|
+
* mime-types
|
|
16
|
+
* Copyright(c) 2014 Jonathan Ong
|
|
17
|
+
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
18
|
+
* MIT Licensed
|
|
19
|
+
*/
|
|
20
|
+
|
|
7
21
|
/**
|
|
8
22
|
* @license React
|
|
9
|
-
* react-jsx-runtime.production.
|
|
23
|
+
* react-jsx-runtime.production.js
|
|
10
24
|
*
|
|
11
|
-
* Copyright (c)
|
|
25
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
12
26
|
*
|
|
13
27
|
* This source code is licensed under the MIT license found in the
|
|
14
28
|
* LICENSE file in the root directory of this source tree.
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
1
2
|
export declare const isEmpty: (value: unknown) => boolean;
|
|
2
3
|
export declare const snakeToCamelCase: (str: string) => string;
|
|
3
4
|
export declare const camelToSnakeCase: (str: string) => string;
|
|
@@ -5,3 +6,7 @@ export declare const pluralToSingle: (str: string) => string;
|
|
|
5
6
|
export declare const arrayToObject: <T extends any[]>(array: T, byKey: string) => any;
|
|
6
7
|
export declare const roundFixed: (str: string | number, decimals?: number) => string;
|
|
7
8
|
export declare const round: (str: string | number, decimals?: number) => number;
|
|
9
|
+
export type DownloadFileOptions = {
|
|
10
|
+
axios: AxiosInstance;
|
|
11
|
+
};
|
|
12
|
+
export declare const downloadFile: (url: string, filename: string, options: DownloadFileOptions) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jasperoosthoek/react-toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"author": "jasperoosthoek",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@babel/preset-typescript": "^7.18.6",
|
|
23
23
|
"@babel/register": "^7.13.16",
|
|
24
24
|
"@testing-library/jest-dom": "^5.16.5",
|
|
25
|
-
"@testing-library/react": "^
|
|
25
|
+
"@testing-library/react": "^16.2.0",
|
|
26
26
|
"@types/jest": "^29.5.2",
|
|
27
27
|
"@types/lodash": "^4.14.191",
|
|
28
28
|
"@types/node": "^18.11.19",
|
|
@@ -50,19 +50,17 @@
|
|
|
50
50
|
"url": "https://github.com/jasperoosthoek/react-toolbox/issues"
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://github.com/jasperoosthoek/react-toolbox#readme",
|
|
53
|
-
"dependencies": {
|
|
54
|
-
},
|
|
55
53
|
"peerDependencies": {
|
|
56
54
|
"axios": "^1.4.0",
|
|
57
55
|
"bootstrap": "^5.1.3",
|
|
58
56
|
"moment": "^2.29.4",
|
|
59
|
-
"react": "^
|
|
60
|
-
"react-bootstrap": "^2.
|
|
57
|
+
"react": "^19.0.0",
|
|
58
|
+
"react-bootstrap": "^2.10.9",
|
|
61
59
|
"react-dnd": "^16.0.1",
|
|
62
|
-
"react-dom": "^
|
|
60
|
+
"react-dom": "^19.0.0",
|
|
63
61
|
"react-icons": "^5.3.0",
|
|
64
|
-
"react-localization": "^
|
|
65
|
-
"react-redux": "^9.
|
|
62
|
+
"react-localization": "^2.0.5",
|
|
63
|
+
"react-redux": "^9.2.0",
|
|
66
64
|
"redux": "^5.0.1",
|
|
67
65
|
"redux-thunk": "^3.1.0"
|
|
68
66
|
},
|
package/src/utils/hooks.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { useDispatch } from 'react-redux';
|
|
|
3
3
|
|
|
4
4
|
// https://stackoverflow.com/questions/53446020/how-to-compare-oldvalues-and-newvalues-on-react-hooks-useeffect
|
|
5
5
|
export const usePrevious = <T>(value: T): T | undefined => {
|
|
6
|
-
|
|
6
|
+
// Explicitly set initial value to `undefined`
|
|
7
|
+
const ref = useRef<T | undefined>(undefined);
|
|
8
|
+
|
|
7
9
|
useEffect(() => {
|
|
8
10
|
ref.current = value;
|
|
9
11
|
});
|
package/src/utils/utils.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import axios, { AxiosInstance } from 'axios';
|
|
1
2
|
|
|
2
3
|
export const isEmpty = (value: unknown) =>
|
|
3
4
|
value === undefined
|
|
@@ -40,3 +41,26 @@ export const arrayToObject = <T extends any[]>(array: T, byKey: string) => Objec
|
|
|
40
41
|
|
|
41
42
|
export const roundFixed = (str: string | number, decimals?: number) => parseFloat(`${str}`).toFixed(decimals || 0);
|
|
42
43
|
export const round = (str: string | number, decimals?: number) => parseFloat(parseFloat(`${str}`).toFixed(decimals || 0));
|
|
44
|
+
|
|
45
|
+
export type DownloadFileOptions = {
|
|
46
|
+
axios: AxiosInstance;
|
|
47
|
+
}
|
|
48
|
+
export const downloadFile = (url: string, filename: string, options: DownloadFileOptions) => (
|
|
49
|
+
// https://gist.github.com/javilobo8/097c30a233786be52070986d8cdb1743
|
|
50
|
+
|
|
51
|
+
(options.axios || axios.create())({
|
|
52
|
+
url,
|
|
53
|
+
method: 'GET',
|
|
54
|
+
responseType: 'blob',
|
|
55
|
+
}).then((response) => {
|
|
56
|
+
const url = window.URL.createObjectURL(new Blob([response.data]));
|
|
57
|
+
const link = document.createElement('a');
|
|
58
|
+
link.href = url;
|
|
59
|
+
link.setAttribute(
|
|
60
|
+
'download',
|
|
61
|
+
filename,
|
|
62
|
+
);
|
|
63
|
+
document.body.appendChild(link);
|
|
64
|
+
link.click();
|
|
65
|
+
})
|
|
66
|
+
);
|