npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cfg-lite

v1.3.1

Published

A secure management config file

Downloads

22

Readme

Cfg Lite

Configration or data file encryption is cumbersome, but it is essential.

CfgLite makes this behavior easy.

Encrypts all files with different values.

Install

npm

npm install cfg-lite

yarn

yarn add cfg-lite

Usage

File Init

If the file does not exist, it is new created. And if the file extension does not exist, .cfg is automatically recognized.

You can specify a unique value of up to 32 characters.

import CfgLite from 'cfg-lite';

const cfg = new CfgLite('/path/to/file.cfg');
const uniqueCfg = new CfgLite('/path/to/file', 'MyUniqueKey');

Get

All keys are separated by periods. Therefore, the key cannot contain periods.

If the value doesn't exist, it returns undefined like optional chaining.

The object is returned as a deep copy.

/*
cfg data
{
	key1: 'hello',
}
*/
cfg.get('key1'); // 'hello'
cfg.get('key1.key2.key-key'); // undefined

Set

/*
cfg data
{
}
*/

cfg.set('key1.key2', 55); // ok
cfg.set('key3.key4.key5', cfg.get('key1')); // ok

/*
result cfg data
{
	key1: {
		key2: 55
	},
	key3: {
		key4: {
			key5: {
				key1: {
					key2: 55
				},
			},
		},
	}
}
*/

Merge

Overwrite the object with new values.

/*
cfg data
{
	key1: {
		key2: 11,
		key3: 22
	}
}
*/

cfg.merge('key1', { key2: 33, key4: 55 });

/*
result cfg data
{
	key1: {
		key2: 33,
		key3: 22,
		key4: 55
	}
}
*/

Delete

/*
cfg data
{
	key1: 'hello'
}
*/

cfg.delete('key1');

/*
result cfg data
{
}
*/

Or you can clear all values.

cfg.deleteAll();

Save

It is inefficient to write a file every time there is a new change. To save the changes to a file you need to use the following function.

cfg.save();
cfg.save('new.cfg'); // New save, Leave before cfg file
cfg.save('new.cfg', true); // New save, Remove before cfg file

Result

{
	"a": {
		"b": {
			"c": "Hello"
		},
		"c": 55
	},
	"c": {
		"d": {
			"e": "Hello"
		}
	},
	"d": true
}

Command line

Global install

npm install -g cfg-lite

Decoding commed

cfg [cfg file] [key]

Thanks.