-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert "true" and "false" string values to boolean #49
Comments
I'd encourage you to do that in JS land! Maybe define your own Long term I'd love to support different types, but since Let me know if you do this in your app or want to take a stab at a pull here! Closing in the meantime. |
Hi @pedro, Thanks for your help. I made the cast with JS, as you suggested. The idea of supporting different types is really cool. |
In case anyone else wants to implement this, I've found an easy solution that works well. I'm using https://github.com/niftylettuce/dotenv-parse-variables to parse the variables provided by Here's an example
Here's the code: // env.js
import Config from 'react-native-config';
import dotenvParseVariables from 'dotenv-parse-variables';
const ENV = {
STRING: Config.STRING,
EMPTY_STRING: Config.EMPTY_STRING,
BOOLEAN: Config.BOOLEAN,
NUMBER: Config.NUMBER,
};
dotenvParseVariables(ENV);
export default ENV; The {
"STRING": "https://www.google.com",
"EMPTY_STRING": "",
"BOOLEAN": "true",
"NUMBER": "5"
} And after parsing using {
"STRING": "https://www.google.com",
"EMPTY_STRING": "",
"BOOLEAN": true,
"NUMBER": 5
} |
Hi,
Is it possible to convert "true" and "false" string values to boolean, so that on JS we can do something like
if (Config.DEBUG)
instead ofif (Config.DEBUG == 'true')
.I've tried the following approach, but it does not work.
Thanks.
The text was updated successfully, but these errors were encountered: