Skip to content

Latest commit

 

History

History
80 lines (70 loc) · 1.66 KB

File metadata and controls

80 lines (70 loc) · 1.66 KB

LetsConfig

🚧 It is under development. 🚧

Load config file (.ts) & Return type-safe object.

Features

⚡ load configuration 🎓 stop configure configuration

Installation

pnpm add letsconfig

Cookbooks

// start with default config

const myConfig = new LetsConfig({});

// simple configuration, extend config properties

default: {
    name: {
        value: 'Dorage Lee',
        description: 'username in service',
        modfied: {
            firstName: (name) => name.split(' ')[0]
            lastName: (name) => name.split(' ')[1]
        }
    }
}

// start with load file

// find with filename
const myConfig = LetsConfig.Load({
    // find by absolute path
    name: '~/.config/lets.config.ts',
    // find by relative path
    name: 'lets.config.ts',
    // find by relative path
    name: './configs/lets.config.ts',
    // find by regex
    name: /lets\.config\.(?=development|production)\.ts/,
    // find by matcher
    name: (filename, fullpath) => {
        if(filename === /lets\.${process.env.NODE_ENV}\.ts/) return true;
        return false;
    }
    ...
})

// validate configuration file by zod

const myConfig = LetsConfig.Load({
    ...
    // find with string
    validator: (config:any) => {
        if (zConfig.safeParse(config).success)
            return {};
        return config;
    }
})

// merge multiple configs

myConfig.merge('~/lets.config.ts')

Roadmaps

// help typing config // generate pretty config file // add custom loader // pass configuration by cli arguments // arguments > custom configuration file > default configuration