3.2.3 • Published 10 months ago

@m234/config v3.2.3

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

@m234/config

npm version npm downloads github github issues

Node.js config library for command-line tools with strict type check. Uses yaml format.

Features

  • Validates the config types when loading: any, string, record, struct, integer, number, boolean.
  • Each type has options. For examlple there is the 'pattern' option for strings and numbers.
  • Struct type has dynamic properties validation ability.

Install

npm i @m234/config

Usage

import {homedir} from "node:os"
import {exit} from "node:process"
import {join} from "node:path"
import {Config, Types} from "@m234/config"

function exitFail(message: string | undefined) {
    console.error(message)
    process.exit(1)
}

const aORb = Types.literal({choices: new Set(['a', 'b'])})
const cfg = new Config({
    path: join(homedir(), 'app.yaml'), // or use `find-config` package
    type: Types.struct({
        properties:{
            id: Types.integer({min: 0})
            // min 8 chars password
            password: Types.string({pattern: /.{8,}/})
            records: Types.array({
                elementType: aORb
            })
        }
    })
})

exitFail(cfg.failLoad())
console.log(cfg.get('id') === 0)
console.log(cfg.getPrintable())
3.2.2

10 months ago

3.2.1

10 months ago

3.2.0

11 months ago

3.1.1

11 months ago

1.0.0

1 year ago

3.1.0

11 months ago

3.2.3

10 months ago

3.0.0

12 months ago

2.0.3

12 months ago

2.0.2

12 months ago

2.0.1

12 months ago

2.0.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago