6.2.4 • Published 1 year ago

teeny-conf v6.2.4

Weekly downloads
40
License
MIT
Repository
github
Last release
1 year ago

teeny-conf

Build Status Dependencies

A small npm package to handle one or multiple config files in Node apps. Works well with Electron and NW.js.

All I/O operations are synchronous and write operation are atomic to avoid files corruption.

Saving and reloading are manual, in case you have to handle large files and avoid useless I/O operations.

Why another ?

I didn't find what I wanted on npm, I was needing a conf I could put in a variable, so I could export it without any problem to another scope.

Installation

npm install teeny-conf

Usage

Basic

config.js:

import teeny from 'teeny-conf';

const config = new teeny('config.json'));

conf.set('language', 'en');
conf.save(); // Save is a manual operation

Nested keys

config.js:

import teeny from 'teeny-conf';

const config = new teeny('config.json', {
  some: {
    nested: {
      property: 42
    }
  }
}));

conf.get('some.nested.property'); // -> 42

Using an export

config.js:

import teeny from 'teeny-conf';

const config = new teeny('config.json'));

export default config;

main.js

import config from './config.js';
// now you can use config.set(), config.get(), etc...

API

All key in the docs refer to a usual key or a nested key.

Constructor

new teeny(configPath[, defaultConfig])

Params

configPath String the filename where you want your config / your config already is. If the directory/file does not exist, it will be created automatically.

defaultConfig Object the default configuration to use if the config file does not already exists.

Return value

A teeny object.

teenyconf.get([key])

Get the key value in your config. If no key is specified, returns the whole conf. Please note set does not support sub-keys yet.

Params

key String (optional) name of the key

Return value

any

teenyconf.set(key, value)

Set key to value.

Params

key String name of the key

value any the new value for this key

teenyconf.has(key)

Check if a key exists in the conf.

Params

key String name of the key

Return value

Boolean

teenyconf.delete(key)

Delete key.

Params

key String name of the key

teenyconf.clear()

Clear the conf and set it to empty object.

teenyconf.save([minify])

Save the current config into its associated file.

Params

minify Boolean default to false. Let you minify the content of the file

Return value

none

teenyconf.reload()

Reload the configuration from file. Can be useful if you have multiple instances of teeny-conf using the same file.

Return value

none

6.2.1

1 year ago

6.2.0

1 year ago

6.2.3

1 year ago

6.2.2

1 year ago

6.2.4

1 year ago

5.0.1

2 years ago

5.0.0

2 years ago

6.1.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

4.0.0

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.0

8 years ago

1.0.1

8 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago