Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

dozen

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dozen

Load config from a dozen sources, normalize and validate with Zod, Valibot or ArkType

Source
npmnpm
Version
0.11.1
Version published
Weekly downloads
46
-75.79%
Maintainers
1
Weekly downloads
 
Created
Source

dozen

Load config from a dozen sources, normalize and validate with Zod, Valibot or ArkType

npm package   Buy me a beer


Quickstart

npm install dozen
import dozen from 'dozen'

// The simplest case.

// - Reads from:
//     1. .env, .env.local, .env.${NODE_ENV}, .env.${NODE_ENV}.local files
//     2. Environment variables (process.env)
// - Coerces strings to numbers and booleans when applicable
// - Merges into a single object
// - Converts keys to camelCase

const config = await dozen().build()
import dozen from 'dozen'
import { z } from 'zod'

// An advanced case.

const dz = dozen({
  // Giving a name makes dozen look for config files with that name
  name: 'myapp',
  // The merged config object will be validated against this schema.
  // This can be any standard schema, e.g. from Zod, Valibot, ArkType, etc.
  schema: z.object({
    host: z.string(),
    port: z.number(),
    enabled: z.boolean(),
  })
})

// Sources can be added later
dz.add(dozen.file('config.json'))

// CLI arguments aren't read by default, but supported via dozen.argv()
dz.add(dozen.argv())

// It accepts partial config objects as well
dz.add({ port: 8008 })

// - Reads from:
//     1. The "myapp" field in package.json;
//     2. myapp.config.json, myapprc.yaml, .myapprc and other config files with the given name;
//     3. .env, .env.local, .env.${NODE_ENV}, .env.${NODE_ENV}.local files
//     4. Environment variables (process.env)
//     5. CLI arguments (process.argv)
//     6. The config object passed to dz.add()
// - For env values, keeps only those with the MYAPP_ prefix, then removes the prefix
// - Coerces strings to numbers and booleans for env and argv values when applicable
// - Converts keys to camelCase
// - Validates with the schema

const config = await dzn.build()

Keywords

config

FAQs

Package last updated on 05 Apr 2025

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