@igorskyflyer/zitto
v1.0.0
Published
🤫 Zitto - quiet config, loud clarity. A zero-dependency TypeScript/JavaScript helper for merging defaults and options across Node, Deno, Bun, and browsers. 🍯
Maintainers
Readme
📃 Table of Contents
🤖 Features
- ⚡ Always returns defaults when no opts passed
- 🛠 Merges known keys with defaults
- 🚫 Throws on unknown keys at runtime
- 🧩 Enforces object shape with TS and runtime
- 🔒 Strict variant drops extras automatically
- 🪶 Tiny zero-dep footprint
- 📦 Predictable results across runtimes
🕵🏼 Usage
Install it by executing any of the following, depending on your preferred package manager:
pnpm add @igorskyflyer/zittoyarn add @igorskyflyer/zittonpm i @igorskyflyer/zitto🤹🏼 API
defineOptions
function defineOptions<T extends object>(
defaults: T,
options?: Partial<T>
): TMerge defaults with optional user options.
T - Shape of the defaults object
defaults - Base configuration with required keys
options - Optional overrides, must be a subset of defaults
Returns a new object with defaults and overrides merged.
defineStrictOptions
function defineStrictOptions<T extends object, U extends Partial<T>>(
defaults: T,
options?: U
): TMerge defaults with optional user options, dropping unknown keys.
T - Shape of the defaults object
U - Subset of T allowed as overrides
defaults - Base configuration with required keys
options - Optional overrides, must be a subset of defaults
Throws a TypeError if options is not an object
Throws an Error if options contains unknown keys
Returns a new object with defaults and known overrides merged.
🗒️ Examples
import { defineOptions, defineStrictOptions } from '@igorskyflyer/zitto'
const opts = defineOptions({ retries: 3, verbose: false }, { verbose: true })
// => { retries: 3, verbose: true }
const opts = defineStrictOptions({ retries: 3, verbose: false }, { retries: 5, extra: 'x' })
// => { retries: 5, verbose: false } // 'extra' is dropped📝 Changelog
📑 Read about the latest changes in the CHANGELOG.
🪪 License
Licensed under the MIT license.
💖 Support
🧬 Related
🥞 Removes HTML code from the given string. Can even extract text-only from the given an HTML string. ✨
🔼 Checks whether the given path is the root of a drive or filesystem. ⛔
🥽 Provides ways of parsing UNC paths and checking whether they are valid. 🎱
📚 A package for fetching Windows registry keys. 🗝
🐯 A utility that lets you manipulate HTML elements, their attributes and innerHTML as strings, on the go and then render the modified HTML. Very useful in SSG projects. 💤
👨🏻💻 Author
Created by Igor Dimitrijević (@igorskyflyer).
