π Find and load configuration for your app, based on cosmiconfig
Find and load configuration for your app, based on cosmiconfig, with fallback to environment variables.
Cosmic, like cosmiconfig, will look for a configuration file:
package.json
propertyFor example, if the app name is βcosmicβ, these files will be searched:
package.json
.cosmicrc
file in JSON or YAML format.cosmicrc.json
file.cosmicrc.yaml
, .cosmicrc.yml
, or .cosmicrc.js
filecosmic.config.js
file exporting a JS objectApart from these, it also looks for:
cosmic.yaml
, cosmic.yml
, or cosmic.js
file without βrcβInstall the package from npm:
npm install @anandchowdhary/cosmic
Import and use:
import { cosmic } from "@anandchowdhary/cosmic";
const config = await cosmic("project"); // {}
Use the config
function to fetch a value:
import { cosmic, config } from "@anandchowdhary/cosmic";
await cosmic("project");
const environment = config("nodeEnv");
Clear the cache and fetch configuration available:
import { clearCosmicCache } from "@anandchowdhary/cosmic";
clearCosmicCache();
Sync functions are also available:
import { cosmicSync } from "@anandchowdhary/cosmic";
const config = cosmicSync("project"); // {}
Build TypeScript:
npm run build
Run unit tests and view coverage:
npm run test-without-reporting