@contentstorage/core 0.3.33 → 0.3.34

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.
@@ -20,7 +20,7 @@ export declare function initContentStorage(config: AppConfig): void;
20
20
  */
21
21
  export declare function getText<Path extends keyof ContentStructure>(contentKey: Path, variables?: ContentStructure[Path] extends {
22
22
  variables: infer Vars;
23
- } ? keyof Vars : Record<string, any>): GetTextReturn | '';
23
+ } ? keyof Vars : Record<string, any>): GetTextReturn;
24
24
  export declare function getImage(contentKey: keyof ContentStructure): GetImageReturn | undefined;
25
25
  export declare function getVariation<Path extends keyof ContentStructure>(contentKey: Path, variationKey?: ContentStructure[Path] extends {
26
26
  data: infer D;
@@ -45,10 +45,14 @@ export function initContentStorage(config) {
45
45
  * @returns The text string from the JSON, or the fallbackValue, or undefined.
46
46
  */
47
47
  export function getText(contentKey, variables) {
48
+ const defaultVal = {
49
+ contentKey,
50
+ text: '',
51
+ };
48
52
  if (!activeContent) {
49
53
  const msg = `[Contentstorage] getText: Content not loaded (Key: "${String(contentKey)}"). Ensure setContentLanguage() was called and completed successfully.`;
50
54
  console.warn(msg);
51
- return '';
55
+ return defaultVal;
52
56
  }
53
57
  const keys = contentKey.split('.');
54
58
  let current = activeContent;
@@ -59,7 +63,7 @@ export function getText(contentKey, variables) {
59
63
  else {
60
64
  const msg = `[Contentstorage] getText: Path "${String(contentKey)}" not found in loaded content.`;
61
65
  console.warn(msg);
62
- return '';
66
+ return defaultVal;
63
67
  }
64
68
  }
65
69
  if (typeof current === 'string') {
@@ -77,7 +81,7 @@ export function getText(contentKey, variables) {
77
81
  else {
78
82
  const msg = `[Contentstorage] getText: Value at path "${String(contentKey)}" is not a string (actual type: ${typeof current}).`;
79
83
  console.warn(msg);
80
- return '';
84
+ return defaultVal;
81
85
  }
82
86
  }
83
87
  export function getImage(contentKey) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@contentstorage/core",
3
3
  "author": "Kaido Hussar <kaidohus@gmail.com>",
4
4
  "homepage": "https://contentstorage.app",
5
- "version": "0.3.33",
5
+ "version": "0.3.34",
6
6
  "type": "module",
7
7
  "description": "Fetch content from contentstorage and generate TypeScript types",
8
8
  "module": "dist/index.js",