npm.io
1.2.0 • Published 5 years ago

@mangar2/configuration

Licence
LGPL-3.0-or-later
Version
1.2.0
Deps
2
Size
8 kB
Vulns
0
Weekly
0

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

Keywords