Giter VIP home page Giter VIP logo

Comments (3)

jordanmkoncz avatar jordanmkoncz commented on September 14, 2024 15

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 react-native-config.

Here's an example .env file:

STRING="https://www.google.com"
EMPTY_STRING=
BOOLEAN=true
NUMBER=5

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 ENV object using the values directly from react-native-config (before parsing using dotenv-parse-variables) looks like this:

{
  "STRING": "https://www.google.com",
  "EMPTY_STRING": "",
  "BOOLEAN": "true",
  "NUMBER": "5"
}

And after parsing using dotenv-parse-variables, it looks like this:

{
  "STRING": "https://www.google.com",
  "EMPTY_STRING": "",
  "BOOLEAN": true,
  "NUMBER": 5
}

from react-native-config.

pedro avatar pedro commented on September 14, 2024

I'd encourage you to do that in JS land! Maybe define your own Config module, that sits between your app and this package, casting values accordingly?

Long term I'd love to support different types, but since .env doesn't have it we'd have to either use another format to define the env (most likely json) or allow apps to somehow configure this package telling it what config it needs and what are their types. For a reference this is exactly what we've done in Pliny, a Ruby framework, so I think this could work well!

Let me know if you do this in your app or want to take a stab at a pull here! Closing in the meantime.

from react-native-config.

rpereira avatar rpereira commented on September 14, 2024

Hi @pedro,

Thanks for your help. I made the cast with JS, as you suggested. The idea of supporting different types is really cool.

from react-native-config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.