@twin.org/core 0.9.1-next.5 → 0.9.1-next.6
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.
|
@@ -35,15 +35,21 @@ export class EnvHelper {
|
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Convert an environment variable key to a JSON key.
|
|
38
|
+
* A trailing _* or * is preserved as a wildcard suffix (e.g. TWIN_REST_PATH_* → "restPath*").
|
|
38
39
|
* @param envVarKey The environment variable key.
|
|
39
40
|
* @param prefix The prefix of the environment variable key, if not provided gets all.
|
|
40
41
|
* @returns The JSON key.
|
|
41
42
|
*/
|
|
42
43
|
static envVarKeyToJsonKey(envVarKey, prefix) {
|
|
44
|
+
const isWildcard = envVarKey.endsWith("*");
|
|
45
|
+
if (isWildcard) {
|
|
46
|
+
envVarKey = envVarKey.replace(/_?\*$/, "");
|
|
47
|
+
}
|
|
43
48
|
if (Is.stringValue(prefix) && envVarKey.startsWith(prefix)) {
|
|
44
49
|
envVarKey = envVarKey.replace(prefix, "");
|
|
45
50
|
}
|
|
46
|
-
|
|
51
|
+
const camelKey = StringHelper.camelCase(envVarKey.toLowerCase());
|
|
52
|
+
return isWildcard ? `${camelKey}*` : camelKey;
|
|
47
53
|
}
|
|
48
54
|
/**
|
|
49
55
|
* Convert a JSON key to an environment variable key.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"envHelper.js","sourceRoot":"","sources":["../../../src/helpers/envHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,SAAS;IACrB;;;;;OAKG;IACI,MAAM,CAAC,SAAS,CACtB,OAA6C,EAC7C,MAAe;QAEf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C,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,QAAQ,GAAG,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC;QACjE,OAAO,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,kBAAkB,CAAC,OAAe,EAAE,MAAe;QAChE,MAAM,SAAS,GAAG,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QAChE,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,OAAO,GAAG,MAAM,GAAG,SAAS,EAAE,CAAC;QAChC,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ObjectHelper } from \"./objectHelper.js\";\nimport { StringHelper } from \"./stringHelper.js\";\nimport { Is } from \"../utils/is.js\";\n\n/**\n * Environment variable helper.\n */\nexport class EnvHelper {\n\t/**\n\t * Get the environment variable as an object with camel cased names.\n\t * @param envVars The environment variables.\n\t * @param prefix The prefix of the environment variables, if not provided gets all.\n\t * @returns The object with camel cased names.\n\t */\n\tpublic static envToJson<T = { [id: string]: string }>(\n\t\tenvVars: { [id: string]: string | undefined },\n\t\tprefix?: string\n\t): T {\n\t\tconst result: { [id: string]: string } = {};\n\n\t\tif (Is.object(envVars)) {\n\t\t\tif (Is.empty(prefix)) {\n\t\t\t\tfor (const envVar in envVars) {\n\t\t\t\t\tif (Is.stringValue(envVars[envVar])) {\n\t\t\t\t\t\tObjectHelper.propertySet(\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tEnvHelper.envVarKeyToJsonKey(envVar, prefix),\n\t\t\t\t\t\t\tenvVars[envVar]\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const envVar in envVars) {\n\t\t\t\t\tif (envVar.startsWith(prefix) && Is.stringValue(envVars[envVar])) {\n\t\t\t\t\t\tObjectHelper.propertySet(\n\t\t\t\t\t\t\tresult,\n\t\t\t\t\t\t\tEnvHelper.envVarKeyToJsonKey(envVar, prefix),\n\t\t\t\t\t\t\tenvVars[envVar]\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn result as T;\n\t}\n\n\t/**\n\t * Convert an environment variable key to a JSON key.\n\t * A trailing _* or * is preserved as a wildcard suffix (e.g. TWIN_REST_PATH_* → \"restPath*\").\n\t * @param envVarKey The environment variable key.\n\t * @param prefix The prefix of the environment variable key, if not provided gets all.\n\t * @returns The JSON key.\n\t */\n\tpublic static envVarKeyToJsonKey(envVarKey: string, prefix?: string): string {\n\t\tconst isWildcard = envVarKey.endsWith(\"*\");\n\t\tif (isWildcard) {\n\t\t\tenvVarKey = envVarKey.replace(/_?\\*$/, \"\");\n\t\t}\n\t\tif (Is.stringValue(prefix) && envVarKey.startsWith(prefix)) {\n\t\t\tenvVarKey = envVarKey.replace(prefix, \"\");\n\t\t}\n\t\tconst camelKey = StringHelper.camelCase(envVarKey.toLowerCase());\n\t\treturn isWildcard ? `${camelKey}*` : camelKey;\n\t}\n\n\t/**\n\t * Convert a JSON key to an environment variable key.\n\t * @param jsonKey The JSON key.\n\t * @param prefix The prefix of the environment variable key, if not provided gets all.\n\t * @returns The environment variable key.\n\t */\n\tpublic static jsonKeyToEnvVarKey(jsonKey: string, prefix?: string): string {\n\t\tconst envVarKey = StringHelper.snakeCase(jsonKey).toUpperCase();\n\t\tif (Is.stringValue(prefix)) {\n\t\t\treturn `${prefix}${envVarKey}`;\n\t\t}\n\t\treturn envVarKey;\n\t}\n}\n"]}
|
|
@@ -15,6 +15,7 @@ export declare class EnvHelper {
|
|
|
15
15
|
}, prefix?: string): T;
|
|
16
16
|
/**
|
|
17
17
|
* Convert an environment variable key to a JSON key.
|
|
18
|
+
* A trailing _* or * is preserved as a wildcard suffix (e.g. TWIN_REST_PATH_* → "restPath*").
|
|
18
19
|
* @param envVarKey The environment variable key.
|
|
19
20
|
* @param prefix The prefix of the environment variable key, if not provided gets all.
|
|
20
21
|
* @returns The JSON key.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.1-next.6](https://github.com/iotaledger/twin-framework/compare/core-v0.9.1-next.5...core-v0.9.1-next.6) (2026-07-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add wildcard support to the envhelper ([c064d46](https://github.com/iotaledger/twin-framework/commit/c064d46d36bbee8022a741b985d2b64c8f9572e4))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/nameof bumped from 0.9.1-next.5 to 0.9.1-next.6
|
|
16
|
+
* devDependencies
|
|
17
|
+
* @twin.org/nameof-transformer bumped from 0.9.1-next.5 to 0.9.1-next.6
|
|
18
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.9.1-next.5 to 0.9.1-next.6
|
|
19
|
+
|
|
3
20
|
## [0.9.1-next.5](https://github.com/iotaledger/twin-framework/compare/core-v0.9.1-next.4...core-v0.9.1-next.5) (2026-06-29)
|
|
4
21
|
|
|
5
22
|
|
|
@@ -51,6 +51,7 @@ The object with camel cased names.
|
|
|
51
51
|
> `static` **envVarKeyToJsonKey**(`envVarKey`, `prefix?`): `string`
|
|
52
52
|
|
|
53
53
|
Convert an environment variable key to a JSON key.
|
|
54
|
+
A trailing _* or * is preserved as a wildcard suffix (e.g. TWIN_REST_PATH_* → "restPath*").
|
|
54
55
|
|
|
55
56
|
#### Parameters
|
|
56
57
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/core",
|
|
3
|
-
"version": "0.9.1-next.
|
|
3
|
+
"version": "0.9.1-next.6",
|
|
4
4
|
"description": "Helper methods/classes for data type checking/validation/guarding/error handling",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/nameof": "0.9.1-next.
|
|
17
|
+
"@twin.org/nameof": "0.9.1-next.6",
|
|
18
18
|
"intl-messageformat": "11.2.8",
|
|
19
19
|
"rfc6902": "5.2.0"
|
|
20
20
|
},
|