1.2.0 • Published 3 years ago

@mangar2/configuration v1.2.0

Weekly downloads
3
License
LGPL-3.0-or-later
Repository
github
Last release
3 years ago

Abstract

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

Contents

Meta

Fileconfiguration.js
AbstractProvides a function to sanitize configuration file input and to provide default values
AuthorVolker Böhm
CopyrightCopyright ( c ) 2020 Volker Böhm
LicenseThis 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

NameTypeDescription
configurationObjectprovided configuration ( from configuration file ) , the function changes this object directly , you may ignore the return value
defaultValuesObjectconfiguration subset with default values
checkInputCheckInputcheck function to sanitize the configuration . Please set all attributes as mandatory , they get optional by providing default values

sanitize returns

TypeDescription
Objectmerged configuration in provided configuration object