Code Monkey home page Code Monkey logo

configorium's Introduction

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

configorium's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.