configorium
v0.0.3
Published
๐ฆโ๏ธ Effortlessly manage configs with nyxdefaults! Simplify your config read/write process. Get started now!
Readme
๐๐ Discover the perfect JavaScript environment with Configorium! This powerful package offers lightning-fast detection of the current environment with incredible accuracy. ๐ต๏ธโโ๏ธ Easily tailor your code to the right environment and avoid compatibility issues with the advanced detection capabilities of Configorium. ๐ช๐ผ Take your development to the next level and ensure optimal performance with Configorium!
๐ฆ Installation
Install:
# nyxi
nyxi configorium
# pnpm
pnpm add configorium
# npm
npm install configorium
# yarn
yarn add configoriumImport Configorium into your Node.js project:
// CommonJS
const { read, update, write } = require('configorium')
// ESM
import { read, update, write } from 'configorium'๐ก Usage
Read/Write config couldn't be easier with Configorium! See the examples below:
.conf:
db.username=db username
db.password=db pass
db.enabled=trueUpdate config:
update({ 'db.enabled': true })Push to an array:
update({ 'modules[]': 'test' })Read/Write config:
const config = read()
config.enabled = false
write(config)User Config:
It is common to keep config in the user's home directory (MacOS: /Users/{name}, Linux: /home/{name}, Windows: C:\users\{name}). Use the following shortcuts for quick access:
writeUser({ token: 123 }, '.zoorc') // Will be saved in {home}/.zoorc
const conf = readUser('.zoorc') // { token: 123 }๐ Unflatten
Configorium uses flat to automatically flat/unflat when writing and reading rcfile. It allows you to define nested objects using . keys. For example:
hello.world = true<=>{ hello: { world: true }test.0 = A<=>tags: [ 'A' ]
Note: If you want to disable this feature for keys that can override, pass the flat: true option.
๐ Native Values
Configorium uses nyxjason to convert values into native JavaScript values. Reading count=123 results in { count: 123 } (instead of { count: "123" }). To preserve strings as is, you can use quotes like count="123".
๐ Exports
const defaults: RCOptions
function parse(contents: string, options?: RCOptions): RC
function parseFile(path: string, options?: RCOptions): RC
function read(options?: RCOptions | string): RC
function readUser(options?: RCOptions | string): RC
function serialize(config: RC): string
function write(config: RC, options?: RCOptions | string): void
function writeUser(config: RC, options?: RCOptions | string): void
function update(config: RC, options?: RCOptions | string): RC
function updateUser(config: RC, options?: RCOptions | string): RCTypes:
type RC = Record<string, any>
interface RCOptions {
name?: string
dir?: string
flat?: boolean
}Defaults:
{
name: '.conf',
dir: process.cwd(),
flat: false
}Why Configorium?
Be the first one to guess ๐
๐ License
MIT ๐

