@app-config/utils
Advanced tools
Comparing version 2.8.2 to 2.8.3
@@ -15,3 +15,3 @@ export declare const isBrowser: boolean; | ||
export declare function isPrimitive(obj: Json): obj is JsonPrimitive; | ||
export declare function generateModuleText(fullConfig: Json, { environment, useGlobalNamespace, validationFunctionCode, esmValidationCode, }: { | ||
export declare function generateModuleText(fullConfig: Json | undefined, { environment, useGlobalNamespace, validationFunctionCode, esmValidationCode, }: { | ||
environment: string | undefined; | ||
@@ -18,0 +18,0 @@ useGlobalNamespace: boolean; |
@@ -15,8 +15,22 @@ export const isBrowser = typeof window === 'object' && typeof document === 'object' && document.nodeType === 9; | ||
const privateEnvName = '_appConfigEnvironment'; | ||
const config = JSON.stringify(fullConfig); | ||
let generatedText = ''; | ||
if (useGlobalNamespace) { | ||
if (fullConfig === undefined) { | ||
generatedText += ` | ||
const globalNamespace = (typeof window === 'undefined' ? globalThis : window) || {}; | ||
const config = globalNamespace.${privateName}; | ||
if (typeof config === 'undefined') { | ||
throw new Error('Config is not loaded in ${privateName}'); | ||
} | ||
export { config }; | ||
export default config; | ||
`; | ||
} | ||
else if (useGlobalNamespace) { | ||
const config = JSON.stringify(fullConfig); | ||
generatedText += ` | ||
const globalNamespace = (typeof window === 'undefined' ? globalThis : window) || {}; | ||
const configValue = ${config}; | ||
@@ -40,2 +54,3 @@ | ||
else { | ||
const config = JSON.stringify(fullConfig); | ||
generatedText += ` | ||
@@ -42,0 +57,0 @@ const config = ${config}; |
@@ -15,3 +15,3 @@ export declare const isBrowser: boolean; | ||
export declare function isPrimitive(obj: Json): obj is JsonPrimitive; | ||
export declare function generateModuleText(fullConfig: Json, { environment, useGlobalNamespace, validationFunctionCode, esmValidationCode, }: { | ||
export declare function generateModuleText(fullConfig: Json | undefined, { environment, useGlobalNamespace, validationFunctionCode, esmValidationCode, }: { | ||
environment: string | undefined; | ||
@@ -18,0 +18,0 @@ useGlobalNamespace: boolean; |
@@ -20,8 +20,22 @@ "use strict"; | ||
const privateEnvName = '_appConfigEnvironment'; | ||
const config = JSON.stringify(fullConfig); | ||
let generatedText = ''; | ||
if (useGlobalNamespace) { | ||
if (fullConfig === undefined) { | ||
generatedText += ` | ||
const globalNamespace = (typeof window === 'undefined' ? globalThis : window) || {}; | ||
const config = globalNamespace.${privateName}; | ||
if (typeof config === 'undefined') { | ||
throw new Error('Config is not loaded in ${privateName}'); | ||
} | ||
export { config }; | ||
export default config; | ||
`; | ||
} | ||
else if (useGlobalNamespace) { | ||
const config = JSON.stringify(fullConfig); | ||
generatedText += ` | ||
const globalNamespace = (typeof window === 'undefined' ? globalThis : window) || {}; | ||
const configValue = ${config}; | ||
@@ -45,2 +59,3 @@ | ||
else { | ||
const config = JSON.stringify(fullConfig); | ||
generatedText += ` | ||
@@ -47,0 +62,0 @@ const config = ${config}; |
{ | ||
"name": "@app-config/utils", | ||
"description": "Common utilities used in @app-config", | ||
"version": "2.8.2", | ||
"version": "2.8.3", | ||
"license": "MPL-2.0", | ||
@@ -6,0 +6,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15143
244