@intlayer/config 1.0.0

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.
Files changed (114) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/client.cjs +48 -0
  3. package/dist/cjs/client.cjs.map +1 -0
  4. package/dist/cjs/client.d.ts +16 -0
  5. package/dist/cjs/configFile/buildConfigurationFields.cjs +182 -0
  6. package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -0
  7. package/dist/cjs/configFile/buildConfigurationFields.d.ts +10 -0
  8. package/dist/cjs/configFile/getConfiguration.cjs +90 -0
  9. package/dist/cjs/configFile/getConfiguration.cjs.map +1 -0
  10. package/dist/cjs/configFile/getConfiguration.d.ts +12 -0
  11. package/dist/cjs/configFile/index.cjs +35 -0
  12. package/dist/cjs/configFile/index.cjs.map +1 -0
  13. package/dist/cjs/configFile/index.d.ts +6 -0
  14. package/dist/cjs/configFile/loadConfigurationFile.cjs +110 -0
  15. package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -0
  16. package/dist/cjs/configFile/loadConfigurationFile.d.ts +8 -0
  17. package/dist/cjs/configFile/searchConfigurationFile.cjs +63 -0
  18. package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -0
  19. package/dist/cjs/configFile/searchConfigurationFile.d.ts +9 -0
  20. package/dist/cjs/defaultValues/internationalization.cjs +42 -0
  21. package/dist/cjs/defaultValues/internationalization.cjs.map +1 -0
  22. package/dist/cjs/defaultValues/internationalization.d.ts +6 -0
  23. package/dist/cjs/defaultValues/locales.cjs +266 -0
  24. package/dist/cjs/defaultValues/locales.cjs.map +1 -0
  25. package/dist/cjs/defaultValues/locales.d.ts +234 -0
  26. package/dist/cjs/defaultValues/middleware.cjs +49 -0
  27. package/dist/cjs/defaultValues/middleware.cjs.map +1 -0
  28. package/dist/cjs/defaultValues/middleware.d.ts +15 -0
  29. package/dist/cjs/defaultValues/server.cjs +61 -0
  30. package/dist/cjs/defaultValues/server.cjs.map +1 -0
  31. package/dist/cjs/defaultValues/server.d.ts +23 -0
  32. package/dist/cjs/envVariables/formatEnvVariable.cjs +52 -0
  33. package/dist/cjs/envVariables/formatEnvVariable.cjs.map +1 -0
  34. package/dist/cjs/envVariables/formatEnvVariable.d.ts +3 -0
  35. package/dist/cjs/envVariables/getConfiguration.cjs +170 -0
  36. package/dist/cjs/envVariables/getConfiguration.cjs.map +1 -0
  37. package/dist/cjs/envVariables/getConfiguration.d.ts +21 -0
  38. package/dist/cjs/envVariables/index.cjs +48 -0
  39. package/dist/cjs/envVariables/index.cjs.map +1 -0
  40. package/dist/cjs/envVariables/index.d.ts +10 -0
  41. package/dist/cjs/envVariables/utils.cjs +56 -0
  42. package/dist/cjs/envVariables/utils.cjs.map +1 -0
  43. package/dist/cjs/envVariables/utils.d.ts +16 -0
  44. package/dist/cjs/index.cjs +53 -0
  45. package/dist/cjs/index.cjs.map +1 -0
  46. package/dist/cjs/index.d.ts +22 -0
  47. package/dist/cjs/types/index.cjs +21 -0
  48. package/dist/cjs/types/index.cjs.map +1 -0
  49. package/dist/cjs/types/index.d.ts +89 -0
  50. package/dist/esm/client.d.mts +16 -0
  51. package/dist/esm/client.mjs +17 -0
  52. package/dist/esm/client.mjs.map +1 -0
  53. package/dist/esm/configFile/buildConfigurationFields.d.mts +10 -0
  54. package/dist/esm/configFile/buildConfigurationFields.mjs +159 -0
  55. package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -0
  56. package/dist/esm/configFile/getConfiguration.d.mts +12 -0
  57. package/dist/esm/configFile/getConfiguration.mjs +52 -0
  58. package/dist/esm/configFile/getConfiguration.mjs.map +1 -0
  59. package/dist/esm/configFile/index.d.mts +6 -0
  60. package/dist/esm/configFile/index.mjs +2 -0
  61. package/dist/esm/configFile/index.mjs.map +1 -0
  62. package/dist/esm/configFile/loadConfigurationFile.d.mts +8 -0
  63. package/dist/esm/configFile/loadConfigurationFile.mjs +76 -0
  64. package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -0
  65. package/dist/esm/configFile/searchConfigurationFile.d.mts +9 -0
  66. package/dist/esm/configFile/searchConfigurationFile.mjs +32 -0
  67. package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -0
  68. package/dist/esm/defaultValues/internationalization.d.mts +6 -0
  69. package/dist/esm/defaultValues/internationalization.mjs +5 -0
  70. package/dist/esm/defaultValues/internationalization.mjs.map +1 -0
  71. package/dist/esm/defaultValues/locales.d.mts +234 -0
  72. package/dist/esm/defaultValues/locales.mjs +235 -0
  73. package/dist/esm/defaultValues/locales.mjs.map +1 -0
  74. package/dist/esm/defaultValues/middleware.d.mts +15 -0
  75. package/dist/esm/defaultValues/middleware.mjs +15 -0
  76. package/dist/esm/defaultValues/middleware.mjs.map +1 -0
  77. package/dist/esm/defaultValues/server.d.mts +23 -0
  78. package/dist/esm/defaultValues/server.mjs +23 -0
  79. package/dist/esm/defaultValues/server.mjs.map +1 -0
  80. package/dist/esm/envVariables/formatEnvVariable.d.mts +3 -0
  81. package/dist/esm/envVariables/formatEnvVariable.mjs +21 -0
  82. package/dist/esm/envVariables/formatEnvVariable.mjs.map +1 -0
  83. package/dist/esm/envVariables/getConfiguration.d.mts +21 -0
  84. package/dist/esm/envVariables/getConfiguration.mjs +110 -0
  85. package/dist/esm/envVariables/getConfiguration.mjs.map +1 -0
  86. package/dist/esm/envVariables/index.d.mts +10 -0
  87. package/dist/esm/envVariables/index.mjs +17 -0
  88. package/dist/esm/envVariables/index.mjs.map +1 -0
  89. package/dist/esm/envVariables/utils.d.mts +16 -0
  90. package/dist/esm/envVariables/utils.mjs +25 -0
  91. package/dist/esm/envVariables/utils.mjs.map +1 -0
  92. package/dist/esm/index.d.mts +22 -0
  93. package/dist/esm/index.mjs +21 -0
  94. package/dist/esm/index.mjs.map +1 -0
  95. package/dist/esm/types/index.d.mts +89 -0
  96. package/dist/esm/types/index.mjs +1 -0
  97. package/dist/esm/types/index.mjs.map +1 -0
  98. package/package.json +88 -0
  99. package/src/client.ts +16 -0
  100. package/src/configFile/buildConfigurationFields.ts +214 -0
  101. package/src/configFile/getConfiguration.ts +75 -0
  102. package/src/configFile/index.ts +1 -0
  103. package/src/configFile/loadConfigurationFile.ts +97 -0
  104. package/src/configFile/searchConfigurationFile.ts +48 -0
  105. package/src/defaultValues/internationalization.ts +9 -0
  106. package/src/defaultValues/locales.ts +463 -0
  107. package/src/defaultValues/middleware.ts +11 -0
  108. package/src/defaultValues/server.ts +18 -0
  109. package/src/envVariables/formatEnvVariable.ts +32 -0
  110. package/src/envVariables/getConfiguration.ts +121 -0
  111. package/src/envVariables/index.ts +8 -0
  112. package/src/envVariables/utils.ts +47 -0
  113. package/src/index.ts +23 -0
  114. package/src/types/index.ts +144 -0
@@ -0,0 +1,47 @@
1
+ function getEnvValue(value: unknown, type: 'boolean'): boolean | undefined;
2
+ function getEnvValue(value: unknown, type: 'number'): number | undefined;
3
+ function getEnvValue<T extends string>(
4
+ value: unknown,
5
+ type: 'string'
6
+ ): T | undefined;
7
+ function getEnvValue<T>(value: unknown, type: 'object'): T | undefined;
8
+ function getEnvValue<T>(value: unknown, type: 'array'): T[] | undefined;
9
+ function getEnvValue(
10
+ value: unknown,
11
+ type: 'string' | 'boolean' | 'number' | 'object' | 'array'
12
+ ) {
13
+ // Handle cases where the environment variable is not set
14
+ if (value === undefined) {
15
+ return undefined;
16
+ }
17
+
18
+ try {
19
+ switch (type) {
20
+ case 'boolean':
21
+ // Convert string to boolean explicitly
22
+ return value === 'true' || value === '1';
23
+
24
+ case 'number':
25
+ // Convert string to number, return undefined if conversion fails
26
+ return Number(value);
27
+
28
+ case 'string':
29
+ // Return the string directly
30
+ return value;
31
+
32
+ case 'object':
33
+ case 'array':
34
+ // Attempt to parse the value as JSON
35
+ return JSON.parse(value as string);
36
+
37
+ default:
38
+ return undefined;
39
+ }
40
+ } catch (error) {
41
+ // Log error and return undefined if any error occurs during parsing
42
+ console.error(`Error parsing environment variable`);
43
+ return undefined;
44
+ }
45
+ }
46
+
47
+ export { getEnvValue };
package/src/index.ts ADDED
@@ -0,0 +1,23 @@
1
+ export { getConfiguration } from './configFile/getConfiguration';
2
+
3
+ export type {
4
+ InternationalizationConfig,
5
+ ServerSetCookieRule,
6
+ MiddlewareConfig,
7
+ CustomIntlayerConfig,
8
+ BaseContentConfig,
9
+ BaseDerivedConfig,
10
+ ResultDirDerivedConfig,
11
+ PatternsContentConfig,
12
+ ContentConfig,
13
+ IntlayerConfig,
14
+ } from './types';
15
+ export { Locales } from './defaultValues/locales';
16
+ export {
17
+ formatEnvVariable,
18
+ intlayerIntlConfiguration,
19
+ intlayerMiddlewareConfiguration,
20
+ intlayerContentConfiguration,
21
+ intlayerConfiguration,
22
+ getConfiguration as getClientConfiguration,
23
+ } from './envVariables/index';
@@ -0,0 +1,144 @@
1
+ import type { Locales } from '../defaultValues/locales';
2
+
3
+ export type InternationalizationConfig = {
4
+ // Available languages in the app
5
+ locales: Locales[]; // default [Locales.ENGLISH, Locales.FRENCH, Locales.SPANISH]
6
+
7
+ // Default language
8
+ defaultLocale: Locales; // default Locales.ENGLISH
9
+ };
10
+
11
+ export type ServerSetCookieRule = 'always' | 'never';
12
+ export type MiddlewareConfig = {
13
+ // Header name to get the language
14
+ headerName: string; // default 'x-intlayer-locale'
15
+
16
+ // Cookie name to get the language
17
+ cookieName: string; // default 'NEXT_LOCALE'
18
+
19
+ // Prefix the default language in the URL
20
+ prefixDefault: boolean; // default false
21
+
22
+ // Base path
23
+ basePath: string; // default ''
24
+
25
+ // Set cookie on server
26
+ serverSetCookie: ServerSetCookieRule; // default 'always'
27
+
28
+ // No prefix
29
+ noPrefix: boolean; // default false;
30
+ };
31
+
32
+ export type CustomIntlayerConfig = {
33
+ /**
34
+ * Internationalization configuration
35
+ */
36
+
37
+ internationalization?: Partial<InternationalizationConfig>;
38
+
39
+ /**
40
+ * Middleware configuration
41
+ */
42
+
43
+ middleware?: Partial<MiddlewareConfig>;
44
+
45
+ /**
46
+ * Content configuration
47
+ */
48
+ content?: Partial<ContentConfig>;
49
+ };
50
+
51
+ export type IntlayerConfig = {
52
+ /**
53
+ * Internationalization configuration
54
+ */
55
+
56
+ internationalization: InternationalizationConfig;
57
+
58
+ /**
59
+ * Middleware configuration
60
+ */
61
+
62
+ middleware: MiddlewareConfig;
63
+
64
+ /**
65
+ * Content configuration
66
+ */
67
+ content: ContentConfig;
68
+ };
69
+
70
+ export type BaseContentConfig = {
71
+ // File extensions of content to look for
72
+ fileExtensions: string[]; // default ['.content.ts', '.content.js', '.content.json']
73
+
74
+ // Directory of the project
75
+ baseDir: string; // default process.cwd()
76
+
77
+ // Directory name where the content is stored
78
+ contentDirName: string; // default 'src'
79
+
80
+ // Directories to exclude
81
+ excludedPath: string[]; // default ['node_modules']
82
+
83
+ // Result directory name
84
+ resultDirName: string; // default '.intlayer'
85
+
86
+ // Module augmentation directory name
87
+ moduleAugmentationDirName: string; // default 'types'
88
+
89
+ // Bundle directory name
90
+ bundleDirName: string; // default 'bundle'
91
+
92
+ // Bundle file extension
93
+ bundleFileExtension: string; // default '.bundle.js'
94
+
95
+ // Dictionary directory name
96
+ dictionariesDirName: string; // default 'dictionary'
97
+
98
+ // Types directory name
99
+ typeDirName: string; // default 'types'
100
+
101
+ // Main directory name
102
+ mainDirName: string; // default 'main'
103
+ };
104
+
105
+ export type BaseDerivedConfig = {
106
+ // Directory to watch - emplacement where the content is stored
107
+ contentDir: string; // default {{baseDir}} / {{contentDirName}}
108
+
109
+ // Result directory
110
+ resultDir: string; // default {{baseDir}} / {{resultDirName}}
111
+
112
+ // Result directory
113
+ moduleAugmentationDir: string; // default {{baseDir}} / {{moduleAugmentationDirName}}
114
+ };
115
+
116
+ export type ResultDirDerivedConfig = {
117
+ // Bundle directory
118
+ bundleDir: string; // default {{resultDir}} / {{bundleDirName}}
119
+
120
+ // Dictionary directory
121
+ dictionariesDir: string; // default {{resultDir}} / {{dictionaryDirName}}
122
+
123
+ // Types directory
124
+ typesDir: string; // default {{resultDir}} / {{typeDirName}}
125
+
126
+ // Main directory
127
+ mainDir: string; // default {{resultDir}} / {{mainDirName}}
128
+ };
129
+
130
+ export type PatternsContentConfig = {
131
+ // Pattern of files to watch
132
+ watchedFilesPattern: string[];
133
+
134
+ // Pattern of files to watch including the relative path
135
+ watchedFilesPatternWithPath: string[];
136
+
137
+ // Pattern of files to output
138
+ outputFilesPatternWithPath: string;
139
+ };
140
+
141
+ export type ContentConfig = BaseContentConfig &
142
+ BaseDerivedConfig &
143
+ ResultDirDerivedConfig &
144
+ PatternsContentConfig;