Skip to content

Commit affc7ba

Browse files
committed
feat: handle boolean and numbers as env vars
1 parent dd0b169 commit affc7ba

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

.env.development

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
API_URL=https://dummyjson.com/
22

3-
## TOTO: add the variable to your CI and remove it from here, not recommended setting sensitive values on your git repo
4-
SECRET_KEY=my-secret-key
3+
## TODO: add the variable to your CI and remove it from here, not recommended setting sensitive values on your git repo
4+
SECRET_KEY=my-secret-key
5+
VAR_NUMBER=10 # this is a number variable
6+
VAR_BOOL=true # this is a boolean variable

.env.production

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
API_URL=https://dummyjson.com/
22

3-
## TOTO: add the variable to your CI and remove it from here, not recommended setting sensitive values on your git repo
4-
SECRET_KEY=my-secret-key
3+
## TODO: add the variable to your CI and remove it from here, not recommended setting sensitive values on your git repo
4+
SECRET_KEY=my-secret-key
5+
VAR_NUMBER=10 # this is a number variable
6+
VAR_BOOL=true # this is a boolean variable

.env.staging

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
API_URL=https://dummyjson.com/
22

3-
## TOTO: add the variable to your CI and remove it from here, not recommended setting sensitive values on your git repo
4-
SECRET_KEY=my-secret-key
3+
## TODO: add the variable to your CI and remove it from here, not recommended setting sensitive values on your git repo
4+
SECRET_KEY=my-secret-key
5+
VAR_NUMBER=10 # this is a number variable
6+
VAR_BOOL=true # this is a boolean variable

env.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ const client = z.object({
7979

8080
// ADD YOUR CLIENT ENV VARS HERE
8181
API_URL: z.string(),
82+
VAR_NUMBER: z.number(),
83+
VAR_BOOL: z.boolean(),
8284
});
8385

8486
const buildTime = z.object({
@@ -89,7 +91,7 @@ const buildTime = z.object({
8991
});
9092

9193
/**
92-
* @type {Record<keyof z.infer<typeof client> , string | undefined>}
94+
* @type {Record<keyof z.infer<typeof client> , unknown>}
9395
*/
9496
const _clientEnv = {
9597
APP_ENV,
@@ -101,10 +103,12 @@ const _clientEnv = {
101103

102104
// ADD YOUR ENV VARS HERE TOO
103105
API_URL: process.env.API_URL,
106+
VAR_NUMBER: Number(process.env.VAR_NUMBER),
107+
VAR_BOOL: process.env.VAR_BOOL === 'true',
104108
};
105109

106110
/**
107-
* @type {Record<keyof z.infer<typeof buildTime> , string | undefined>}
111+
* @type {Record<keyof z.infer<typeof buildTime> , unknown>}
108112
*/
109113
const _buildTimeEnv = {
110114
EXPO_ACCOUNT_OWNER,

0 commit comments

Comments
 (0)