@leancodepl/config 9.1.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.
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
package/index.cjs.js ADDED
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Creates a getter function for accessing Vite-injected configuration values from environment variables on development,
5
+ * on production it will return the value from the environment variables.
6
+ * You can check leancodepl/tools repository for more information. There's nginx-base defined which parses it out.
7
+ *
8
+ * The keys are automatically prefixed with 'VITE_' when accessing import.meta.env.
9
+ *
10
+ * @template TConfigKey - The string type for configuration keys.
11
+ * @returns An object containing the `getInjectedConfig` method.
12
+ * @example
13
+ * ```typescript
14
+ * const { getInjectedConfig } = mkGetInjectedConfig<'API_URL' | 'API_KEY'>();
15
+ * const apiUrl = getInjectedConfig('API_URL');
16
+ * ```
17
+ */ function mkGetInjectedConfig() {
18
+ return {
19
+ getInjectedConfig: (key)=>undefined[`VITE_${key}`]
20
+ };
21
+ }
22
+
23
+ exports.mkGetInjectedConfig = mkGetInjectedConfig;
package/index.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.esm.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Creates a getter function for accessing Vite-injected configuration values from environment variables on development,
3
+ * on production it will return the value from the environment variables.
4
+ * You can check leancodepl/tools repository for more information. There's nginx-base defined which parses it out.
5
+ *
6
+ * The keys are automatically prefixed with 'VITE_' when accessing import.meta.env.
7
+ *
8
+ * @template TConfigKey - The string type for configuration keys.
9
+ * @returns An object containing the `getInjectedConfig` method.
10
+ * @example
11
+ * ```typescript
12
+ * const { getInjectedConfig } = mkGetInjectedConfig<'API_URL' | 'API_KEY'>();
13
+ * const apiUrl = getInjectedConfig('API_URL');
14
+ * ```
15
+ */ function mkGetInjectedConfig() {
16
+ return {
17
+ getInjectedConfig: (key)=>import.meta.env[`VITE_${key}`]
18
+ };
19
+ }
20
+
21
+ export { mkGetInjectedConfig };
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@leancodepl/config",
3
+ "version": "9.1.0",
4
+ "license": "Apache-2.0",
5
+ "exports": {
6
+ "./package.json": "./package.json",
7
+ ".": {
8
+ "module": "./index.esm.js",
9
+ "types": "./index.d.ts",
10
+ "import": "./index.cjs.mjs",
11
+ "default": "./index.cjs.js"
12
+ }
13
+ },
14
+ "module": "./index.esm.js",
15
+ "main": "./index.cjs.js",
16
+ "types": "./index.d.ts"
17
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ declare global {
2
+ interface ImportMeta {
3
+ env: Record<`VITE_${string}`, string | undefined>;
4
+ }
5
+ }
6
+ /**
7
+ * Creates a getter function for accessing Vite-injected configuration values from environment variables on development,
8
+ * on production it will return the value from the environment variables.
9
+ * You can check leancodepl/tools repository for more information. There's nginx-base defined which parses it out.
10
+ *
11
+ * The keys are automatically prefixed with 'VITE_' when accessing import.meta.env.
12
+ *
13
+ * @template TConfigKey - The string type for configuration keys.
14
+ * @returns An object containing the `getInjectedConfig` method.
15
+ * @example
16
+ * ```typescript
17
+ * const { getInjectedConfig } = mkGetInjectedConfig<'API_URL' | 'API_KEY'>();
18
+ * const apiUrl = getInjectedConfig('API_URL');
19
+ * ```
20
+ */
21
+ export declare function mkGetInjectedConfig<TConfigKey extends string>(): {
22
+ getInjectedConfig: (key: TConfigKey) => string | undefined;
23
+ };