Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

teeny-conf

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

teeny-conf

A small npm package to handle config files in Node apps. Works fine with Electron and NW.js

  • 6.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24
decreased by-22.58%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 27 Jun 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc