0.5.11 • Published 10 months ago

conficurse v0.5.11

Weekly downloads
14
License
MIT
Repository
github
Last release
10 months ago

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!

0.5.10

11 months ago

0.5.11

10 months ago

0.5.8

11 months ago

0.5.9

11 months ago

0.5.7

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.6

1 year ago

0.5.5

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.3.9

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

3 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.2

4 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago