Skip to content

vatsal2210/cosmic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌌 Cosmic

Find and load configuration for your app, based on cosmiconfig, with fallback to environment variables.

Coverage Status Travis Status

⭐ Features

Cosmic, like cosmiconfig, will look for a configuration file:

  • a package.json property
  • a JSON or YAML, extensionless "rc file"
  • an "rc file" with the extensions .json, .yaml, .yml, or .js.
  • a .config.js CommonJS module

For example, if the app name is "cosmic", these files will be searched:

  • a cosmic property in package.json
  • a .cosmicrc file in JSON or YAML format
  • a .cosmicrc.json file
  • a .cosmicrc.yaml, .cosmicrc.yml, or .cosmicrc.js file
  • a cosmic.config.js file exporting a JS object

Apart from these, it also looks for:

  • a cosmic.yaml, cosmic.yml, or cosmic.js file without "rc"
  • Environment variables

πŸ’‘ Usage

Install the package from npm:

npm install @vatsal2210/cosmic

Import and use:

import { cosmic } from '@vatsal2210/cosmic';

const config = await cosmic('project'); // {}

Use the config function to fetch a value:

import { cosmic, config } from '@vatsal2210/cosmic';

await cosmic('project');
const environment = config('nodeEnv');

Clear the cache and fetch configuration available:

import { clearCosmicCache } from '@vatsal2210/cosmic';

clearCosmicCache();

Sync functions are also available:

import { cosmicSync } from '@vatsal2210/cosmic';

const config = cosmicSync('project'); // {}

πŸ‘©β€πŸ’» Development

Build TypeScript:

npm run build

Run unit tests and view coverage:

npm run test-without-reporting

About

🌌 Find and load configuration for your app, based on cosmiconfig

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published