Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@apparts/config

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apparts/config

A config-loading framework

npmnpm
Version
1.0.5
Version published
Weekly downloads
44
158.82%
Maintainers
1
Weekly downloads
 
Created
Source

#+TITLE: Config #+DATE: [2019-02-07 Thu] #+AUTHOR: Philipp Uhl

  • Usage

Storage in an environment variable can be done in two ways:

  • as a string that is parsable by JSON.parse
  • as a Base-64 encoded string that decodes to a JSON.parse-parsable string

** Node environment

To require a configuration that is stored in one of the files

  • =config/my-color.json=
  • =config/my-color.js= or the environment variable =MY_COLOR= (note, a dash becomes an underscore and everything is in uppercase): #+BEGIN_SRC sh const Colors = require('apparts-config').get('my-color'); #+END_SRC

** Webpack for web environment

To require a configuration that is stored in the environment variable =MY_COLOR= (note, a dash becomes an underscore and everything is in uppercase): #+BEGIN_SRC sh const Colors = require('apparts-config').get('my-color'); #+END_SRC

In order to create environment variables use the following webpack (v

2.0) configuration options:

#+BEGIN_SRC js module.exports = env => { return { plugins: [ new webpack.DefinePlugin({ 'process.env': { 'MY_COLOR': JSON.stringify(JSON.stringify(require('./src/utils/colors.js'))) } }), ] } }; #+END_SRC

** React-Nativ environment

This package is not supported for that kind of environment. In order to use packages that require this package anyways the following configuration is necessary:

It is necessary to create an alias for the module. This requires the module =babel-plugin-module-resolver= to be installed and the following to be present in the file =babel.config.js=:

#+BEGIN_SRC js module.exports = { // ... "plugins": [ ["module-resolver", { "alias": { "apparts-config": "./src/config.js" } }] ] }; #+END_SRC

The file =./src/config.js= must be like the following and containing all the configuration:

#+BEGIN_SRC js module.exports.get = (config) => { return { // my configs here configName: { // all my configuration for configName } // ... }[config]; }; #+END_SRC

FAQs

Package last updated on 26 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts