Code Monkey home page Code Monkey logo

conficurse's Introduction

Conficurse Config Loader

The conficurse library will load your config YAML, JSON and JS files as a Javascript object. This is great for huge configuration file hierarchies or applications with deep structures.

Awesome features:

  • Env support, merges files automatically based on your current environment
  • Supports callback functions for modifying file content before and after load
  • Can lazy load modules using Javascript proxy objects
  • You can load your files async in parallel using promises

Install

npm i conficurse

Usage

See the test/config directory for an example directory structure.

var loader = require('conficurse')

// Path is the directory relative to where you run the command
var config = loader.load('config')

// Lazy load, functions won't be required until you use them
var pages = loader.load('app/pages', { lazy: true })

// Load files async using promises, can be used with Promise.all
var pages = await loader.load('app/pages', { async: true })

// We also have this convenience function
var pages = await loader.loadAsync('app/pages')

// Change content on load
var config = loader.load('config', {
  onload: function({
    mode,
    dir,
    file,
    base,
    ext,
    trail,
    content
  }) {
    if (ext == 'yml') {
      return YAML.load(content)
    }
    return content
  }
})

// Change content before require
var app = loader.load('app', {
  onrequire: function({
    mode,
    dir,
    file,
    base,
    ext,
    trail,
    content
  }) {
    return content.replace('@', process.cwd())
  }
})

Caveats

These are some things to be aware of:

  • You cannot use env with .js files
  • Only .js files can be lazy loaded
  • Only .js files supports onrequire callbacks

MIT licensed. Enjoy!

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.