spoko-design-system 0.2.59 → 0.2.61
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/index.ts +2 -1
- package/package.json +1 -1
- package/src/utils/getData.ts +7 -6
package/index.ts
CHANGED
|
@@ -53,10 +53,11 @@ export { default as getProductChecklist } from './src/utils/product/getProductCh
|
|
|
53
53
|
export { default as getShorterDescription } from './src/utils/seo/getShorterDescription';
|
|
54
54
|
|
|
55
55
|
// Utils: Text
|
|
56
|
-
|
|
56
|
+
|
|
57
57
|
// export { default as getData } from './src/utils/getData';
|
|
58
58
|
// export { getData } from './src/utils/getData';
|
|
59
59
|
export { getTranslation, text2paragraphs, countWords, firstSentence, removeSemicolon } from './src/utils/text';
|
|
60
|
+
export { default as getData} from './src/utils/getData';
|
|
60
61
|
export { default as formatDate } from './src/utils/text/formatDate';
|
|
61
62
|
export { default as formatLocaleNumber } from './src/utils/text/formatLocaleNumber';
|
|
62
63
|
export { default as formatPad } from './src/utils/text/formatPad';
|
package/package.json
CHANGED
package/src/utils/getData.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
1
|
const API_URL = import.meta.env.API_URL;
|
|
4
2
|
const version = (Math.random() + 1).toString(36).substring(7); // random version to refresh cache from Cloudflare
|
|
5
3
|
|
|
6
|
-
interface ApiResponse {
|
|
4
|
+
interface ApiResponse<T> {
|
|
7
5
|
success: boolean;
|
|
8
|
-
data:
|
|
6
|
+
data: T;
|
|
9
7
|
}
|
|
10
8
|
|
|
11
|
-
export const getData = async (type: string): Promise<
|
|
9
|
+
export const getData = async <T>(type: string): Promise<T | null> => {
|
|
12
10
|
const API = `${API_URL}${type}?version=${version}`;
|
|
13
11
|
|
|
14
12
|
try {
|
|
@@ -19,7 +17,7 @@ export const getData = async (type: string): Promise<any | null> => {
|
|
|
19
17
|
return null;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
const jsonObject: ApiResponse = await response.json();
|
|
20
|
+
const jsonObject: ApiResponse<T> = await response.json();
|
|
23
21
|
|
|
24
22
|
// Return data if API call is successful
|
|
25
23
|
if (jsonObject.success) {
|
|
@@ -33,3 +31,6 @@ export const getData = async (type: string): Promise<any | null> => {
|
|
|
33
31
|
return null;
|
|
34
32
|
}
|
|
35
33
|
};
|
|
34
|
+
|
|
35
|
+
export default getData;
|
|
36
|
+
export { API_URL as apiInfo };
|