Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
A multi-format, file-based configuration library for Node. It streamlines reading and parsing configurations from JSON, CSON and YAML files, with support for adding your own file-type handlers.
This project is simple right now, but there are some fun features planned for a future release.
You can use Conifer with JavaScript or CoffeeScript:
var conifer = require('conifer');
conifer = require 'conifer'
In the examples below, it's assumed that you've required Conifer as above.
This function parses a config file asynchronously. It accepts two arguments – a file path and a callback function. The file path must be an unempty string and the callback should accept two arguments itself: the parsed config store, and an error object.
conifer.parse('example.json', function (store, err) {
if (err !== null) {
throw err;
}
// do something with `store`
});
In the callback, store
will be either a
conifer.Store
instance on success or null
.
err
will be null
on success, or an Error object on failure.
This function parses a config file synchronously. It accepts
a single argument – a file path. The file path must be an
unempty string. This function returns a
conifer.Store
instance on success, and
throws if parsing fails.
store = conifer.parseSync('example.json');
This is the class which is instantiated in parsing, and holds parsed configurations. The constructor for this class accepts a simple object of key/value pairs.
The get method accepts a single argument, the name of the configuration to get, and returns the requested configuration (or undefined if it's not set).
var config = new conifer.Store({foo: 'bar'});
config.get('foo'); // bar
The set method accepts a two arguments, the name of the configuration to set and the value to set it to.
var config = new conifer.Store({});
config.set('foo', 'bar');
config.get('foo'); // bar
Conifer can be extended to work with almost any configuration format. It's just a case of writing a handler for that file type. The handler API is extremely simple:
This function adds a new handler. It accepts two arguments – a file extension and a handler function. The handler function should accept a content string and return a successfully parsed object or throw an error.
conifer.handler.setHandler('xml', function (fileContent) {
try {
return myMagicXmlLib.parse(fileContent);
} catch (error) {
throw error;
}
});
With the above code, any call to
conifer.parse
or
conifer.parseSync
with a file path that
has a .xml
extension will use the specified handler function
to parse the file content.
This function gets a handler that's been set already. This function accepts a single argument – the file extension to get the handler for, and returns the requested function.
conifer.handler.getHandler('json'); // [Function]
This function removes a handler that's been set already. This function accepts a single argument – the file extension to get the handler for.
conifer.handler.removeHandler('json');
conifer.handler.getHandler('json'); // undefined
In order to develop Conifer, you'll need to install the following npm modules globally like so:
npm install -g coffee-script
npm install -g jake
And then install development dependencies locally with:
npm install
Once you have these dependencies, you will be able to run the following commands:
jake build
: Build JavaScript from the CoffeeScript source.
jake lint
: Run CoffeeLint on the CoffeeScript source.
jake test
: Run all unit tests.
Dual licensed under the MIT or GPL Version 2 licenses.
FAQs
A multi-format, file-based configuration library for Node.
We found that conifer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.