2.0.4 • Published 1 month ago

@selfagency/xcfg v2.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

xcfg

MIT License GitHub Issues Known Vulnerabilities

Cross-platform config file management made easy. Works great with command-line tools and Electron apps. Originally written in CommonJS by Jonathan Beebe, this is a complete rewrite in TypeScript using updated JavaScript conventions and Node.js APIs, with both ESM and CJS exports.

Overview

When building command-line tools and desktop apps with Node.js, there exists a common need for managing application configuration files.

xcfg is a package that saves you the trouble of validating config paths across multiple platforms and creating the config file. It makes config file management easy by handling all IO operations under the hood, and provides a simple get() and set() interface for individual configuration properties. JSON is used as the config file format to be easy on both machines and humans (and to eliminate the need for 3rd party dependencies).

Installation

cd node-project
npm install xcfg

Usage

Require the module and create a new instance:

import Xcfg from 'xcfg';
const xcfg = await Xcfg.create('agency.self.myapp');

On construction, after sanitizing the id, it is used to create a configuration file (if it doesn't already exist) at the following path: ~/.config/agency.self.myapp/config.json

After that, you can use the xcfg instance to get, set, and delete properties on the in-memory object:

xcfg.set('foo', 'bar');
xcfg.get('foo'); // bar
xcfg.del('foo');
xcfg.get('foo'); // undefined

The above will only manipulate the in-memory config instance. To persist changes to disk, use save():

xcfg.save();

And while there's a little more to it than that, that's the basic idea and really all you need to know to use this package. To see more methods and options, view the documentation.

Documentation

Documentation is available in the docs directory and can be recompiled with npm run docs.

Tests

npm run test

All tests were written using Jest.

Linting

This project uses eslint and Prettier to enforce code correctness and style. You can check for errors by running:

npm run lint

License

Copyright (c) 2023, Daniel Sieradski; 2017, Jonathan Beebe

This code was derived from https://github.com/jonbeebe/xcfg.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2.0.4

1 month ago

2.0.3

8 months ago

2.0.2

8 months ago

2.0.1

8 months ago

2.0.0

8 months ago