Skip to content

πŸ“¦βœοΈ Effortlessly manage configs with nyxdefaults! Simplify your config read/write process. Get started now!

License

Notifications You must be signed in to change notification settings

nyxblabs/configorium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

cover npm version npm downloads bundle License

πŸ”πŸŒ 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 configorium

Import 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=true

Update 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): RC

Types:

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 πŸ’ž

About

πŸ“¦βœοΈ Effortlessly manage configs with nyxdefaults! Simplify your config read/write process. Get started now!

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project