spoko-design-system 0.2.61 → 0.2.63
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 +1 -4
- package/package.json +1 -1
- package/src/utils/getData.ts +22 -3
- package/src/utils/text.ts +2 -2
package/index.ts
CHANGED
|
@@ -53,11 +53,8 @@ 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
|
-
|
|
57
|
-
// export { default as getData } from './src/utils/getData';
|
|
58
|
-
// export { getData } from './src/utils/getData';
|
|
59
56
|
export { getTranslation, text2paragraphs, countWords, firstSentence, removeSemicolon } from './src/utils/text';
|
|
60
|
-
export {
|
|
57
|
+
export { apiInfo, getData} from './src/utils/getData';
|
|
61
58
|
export { default as formatDate } from './src/utils/text/formatDate';
|
|
62
59
|
export { default as formatLocaleNumber } from './src/utils/text/formatLocaleNumber';
|
|
63
60
|
export { default as formatPad } from './src/utils/text/formatPad';
|
package/package.json
CHANGED
package/src/utils/getData.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const API_URL = import.meta.env.API_URL;
|
|
2
1
|
const version = (Math.random() + 1).toString(36).substring(7); // random version to refresh cache from Cloudflare
|
|
3
2
|
|
|
4
3
|
interface ApiResponse<T> {
|
|
@@ -6,6 +5,27 @@ interface ApiResponse<T> {
|
|
|
6
5
|
data: T;
|
|
7
6
|
}
|
|
8
7
|
|
|
8
|
+
export function getEnvVariable(key, defaultValue = null) {
|
|
9
|
+
// First we check import.meta.env (for ES6 environments)
|
|
10
|
+
if (typeof import.meta !== 'undefined' && typeof import.meta.env !== 'undefined') {
|
|
11
|
+
return import.meta.env[key] || defaultValue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Then check process.env (for Node.js environment)
|
|
15
|
+
if (typeof process !== 'undefined' && typeof process.env !== 'undefined') {
|
|
16
|
+
return process.env[key] || defaultValue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// If no variable is found, the default value is returned
|
|
20
|
+
return defaultValue;
|
|
21
|
+
}
|
|
22
|
+
const API_URL = getEnvVariable('API_URL', 'https://default-api.com');
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export const apiInfo = (name: string) => {
|
|
26
|
+
return API_URL
|
|
27
|
+
}
|
|
28
|
+
|
|
9
29
|
export const getData = async <T>(type: string): Promise<T | null> => {
|
|
10
30
|
const API = `${API_URL}${type}?version=${version}`;
|
|
11
31
|
|
|
@@ -32,5 +52,4 @@ export const getData = async <T>(type: string): Promise<T | null> => {
|
|
|
32
52
|
}
|
|
33
53
|
};
|
|
34
54
|
|
|
35
|
-
export default getData;
|
|
36
|
-
export { API_URL as apiInfo };
|
|
55
|
+
export default getData;
|
package/src/utils/text.ts
CHANGED