@mangar2/configuration

1.2.0 • Public • Published

Abstract

Provides a function to sanitize configuration file input and to provide default values

Contents

Meta

File configuration.js
Abstract Provides a function to sanitize configuration file input and to provide default values
Author Volker Böhm
Copyright Copyright ( c ) 2020 Volker Böhm
License This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose .

Global functions

sanitize

sanitize (configuration, defaultValues, checkInput) => {Object}

Sanitizes configuration input and merges it with default values , if not provided in configuration

Example

const configuration = { one: 'one', two: 'not two' }
const defaultValues = { two: 'two', three: 3 }
const checkInput = new CheckInput({
    type: 'object',
    properties: {
        one: { type: 'string' },
        two: { type: 'string' },
        three: { type: 'number' }
    },
    required: ['one', 'two', 'trhee']
})
configuration = sanitize(configuration, defaultValues, checkInput)
// configuration is now { one: 'one', two: 'not two', three: 3 }

sanitize Parameters

Name Type Description
configuration Object provided configuration ( from configuration file ) , the function changes this object directly , you may ignore the return value
defaultValues Object configuration subset with default values
checkInput CheckInput check function to sanitize the configuration . Please set all attributes as mandatory , they get optional by providing default values

sanitize returns

Type Description
Object merged configuration in provided configuration object

Readme

Keywords

Package Sidebar

Install

npm i @mangar2/configuration

Weekly Downloads

0

Version

1.2.0

License

LGPL-3.0-or-later

Unpacked Size

8.46 kB

Total Files

5

Last publish

Collaborators

  • mangar2