Ninja Pumpkin Mutants

    dyna-config-handler
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.4 • Public • Published

    About

    The dyna-config-handler simplifies the configuration handling in json files for node-js applications.

    Written in Typescript, runs everywhere, universal and in non Typscript projects.

    Usage

    import {} from "";
    
    interface IMyConfig {
        databaseName: string;
        bufferSize: number;
    }
    
    const ch = new DynaConfigHandler<IMyConfig>({
        filename: './myConfigFile.json',
        defaults: {
            databaseName: 'superChat-20',
            bufferSize: 2000000,
        },
    });
    
    ch.load()
    .then(() => {
        // configuration is loaded
        ch.config.databaseName; // == 'superChat-20'
    })
    .catch((error: IError) => {
        // system error loading this file
    });
    
    // later in the code
    
    ch.save(); // return promise
    
    

    Constructor, configuration of the dyna-config-handler

    The constructor accepts one configuration object of this interface:

    IConfiguration<C> {		// where C is your interface of your configuration
      filename?: string;
      defaults?: C;
      config?: C;
    }
    

    Methods

    reset(): void

    Set the configuration to defaults or to {} if defaults are not defined.

    save(humanReadable: boolean = true): Promise

    Saves the configuration.

    load(): Promise

    Loads the configuration from the filename defined in the constructor.

    You in the IConfiguration you defined filename you habe to call this in order to load the configuration.

    Note: the config object is replaced with this.

    delete(): Promise

    Returns Promise boolean if the file is really deleted. It will return false if there is no file. In case of disk error the Promise.reject will be called so catch it.

    Properties

    config (shorthand c)

    This is your configuration. You are free to change it. You can save it at any time you want. dyna-config-handler is not changing anything from it.

    Keywords

    none

    Install

    npm i dyna-config-handler

    DownloadsWeekly Downloads

    2

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    41.7 kB

    Total Files

    29

    Last publish

    Collaborators

    • dennisat