Coder Social home page Coder Social logo

rcload's Introduction

rcload

Find and load json configuration from a package.json property, rc file, or CommonJS module.

Heavily inspired by cosmiconfig, but super simplified for minimal bundlesize.
The big difference from cosmiconfig is that rcload does not support yaml files.

rcload will search for the following:

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

It is also meant as a partial drop-in replacement which means it return a result object same as cosmiconfig.

Differences from cosmiconfig

  • Supports only JSON and CommonJS formats.
  • Only looks in process.cwd().
  • Limited options.
  • Only synchronous load.

Usage

Install as a dependency.

npm i rcload

Use in your application.

const rcload = require('rcload');

const result = rcload('myapp');

Result

The result object has the following properties:

  • config: The parsed configuration object. undefined if the file is empty.
  • filepath: The path to the configuration file that was found.
  • isEmpty: true if the configuration file is empty.

In contrast to cosmiconfig, isEmpty will remain in the result object when the config is found, e.g.:

const result = rcload('myapp');
// {
//     config: {
//         ...
//     },
//     filepath: "/users/johndoe/www/myapp/.myapprc",
//     isEmpty: false
// }

Options

rcload takes an options object:

  • cwd: the full directory path to search in. Common for package.json and rc files. Defaults to process.cwd().

If you want your config files in another directory this will help, e.g.:

rcload('myapp', {
    cwd: path.join(process.cwd(), 'configs')
})

rcload's People

Contributors

cenobitedk avatar

Watchers

 avatar  avatar  avatar

rcload's Issues

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.