FCF 2.0 development in progress...
> > > > > >
[News] [JS Packages API] [JS Downloads] [Donate to the project] [Contacts]

constructor() method from fcf.Configuration class

constructor({configuration, enableDefaultParams, mergeParamNames} a_options)

Class: fcf.Configuration

Package: fcf-framework-core

File: fcf.js

Available from version: 2.0.2

Class constructor

Arguments

{configuration, enableDefaultParams, mergeParamNames} a_options
- Additional object creation options
  • object|fcf.Configuration configuration - The configuration object whose fields will be copied into the created object. If the object is an instance of the fcf.Configuration class and the fields in the configuration object are changed, then the changes will be reflected in the new object. Object parameters are added to the configuration similar to the append method

  • boolean enableDefaultParams - If the parameter is equal to true, then the object is created with the preset fields of the framework system settings. The list of predefined fields can be found on the package description page: fcf-framework-core

  • string|array[string] mergeParamNames - Specifies which parameter names will be treated as merge parameter settings, i.e., act as an analogue of the merge property.

Example: Using the constructor without parameters

const fcf = require("fcf-framework-core"); const config = new fcf.Configuration(); config.append({ theme: "dark", version: 1 }); fcf.log.log("APP", "Theme:", config.theme); fcf.log.log("APP", "Version:", config.version);

Output:

2026-05-27 03:31:57.425 [PID:339592] [LOG] [MOD:APP]: Theme: dark 2026-05-27 03:31:57.425 [PID:339592] [LOG] [MOD:APP]: Version: 1

Example: Passing merge rules directly via constructor

We immediately say: "if you see the 'plugins' field, use fcf.append" to merge it with the current value.

const fcf = require("fcf-framework-core"); const config = new fcf.Configuration({ merge: { "plugins": "fcf.append", "metadata.tags": "fcf.append" // Deep paths can be specified via dot notation } }); config.append({ plugins: ["auth"], metadata: { tags: ["v1"] } }); config.append({ plugins: ["logger"], metadata: { tags: ["stable"] } }); fcf.log.log("APP", "Plugins:", config.plugins); fcf.log.log("APP", "Tags:", config.metadata.tags);

Output:

2026-05-27 03:31:57.429 [PID:339592] [LOG] [MOD:APP]: Plugins: [ "auth", "logger" ] 2026-05-27 03:31:57.430 [PID:339592] [LOG] [MOD:APP]: Tags: [ "v1", "stable" ]

Example: Using merge with an external file (via 'file' property)

This demonstrates how fcf can automatically load a file containing the merge function if it is not found in the global scope.

file: merge_helpers.js

fcf.sumNumbers = (a_current, a_source)=>{ return a_current + a_source; }

file: index.js

const fcf = require("fcf-framework-core"); const config = new fcf.Configuration({ merge: { "counters": { function: "fcf.sumNumbers", file: "merge_helpers.js" // Path in FCF format, // relative paths are allowed // since loading is performed via fcf.require } } }); // Suppose fcf.sumNumbers is defined in the file above // For testing, we create it right here to make the example working fcf.sumNumbers = (a_cur, a_src) => (a_cur || 0) + (a_src || 0); config.append({ counters: 10 }); config.append({ counters: 5 }); fcf.log.log("APP", "Counters:", config.counters);

Output:

2026-05-27 03:31:57.433 [PID:339592] [LOG] [MOD:APP]: Counters: 15

Example: Using the mergeParamNames parameter

mergeParamNames specifies property names that will be treated as a configuration object for merging.

const fcf = require("fcf-framework-core"); // Register a custom function for the example (typeof global !== 'undefined' ? global : window).myCustomMerge = (a_cur, a_src) => { return fcf.str(a_cur) + " | " + fcf.str(a_src); }; const config = new fcf.Configuration({ // We specify that the 'ex_merge' field contains a configuration object // with field merge rules. mergeParamNames: ["ex_merge"], }); config.append({ ex_merge: { "version_string": "myCustomMerge", }, version_string: "1.0" }); config.append({ version_string: "2.0" }); fcf.log.log("APP", "Version:", config.version_string);

Output:

2026-05-27 03:31:57.431 [PID:339592] [LOG] [MOD:APP]: Version: 1.0 | 2.0

Example: Full combination: enableDefaultParams + merge + mergeParamNames

The most powerful scenario: take default framework parameters and apply our own merge rules.

const fcf = require("fcf-framework-core"); const config = new fcf.Configuration({ enableDefaultParams: true, // Load base settings (aliases, translations, etc.) mergeParamNames: ["aliases_merge_instructions"], // Specify that aliases_merge_instructions // contains merge rules }); // There might already be some aliases in defaults. Let's add our own. config.append({ aliases_merge_instructions:{ // Object containing field merge rules "web_aliases": "fcf.append" // Use append to merge aliases }, web_aliases: { "my_app:home": "/index.html" } }); config.append({ web_aliases: { "my_app:about": "/about.html" } }); // Contains both default and our new aliases fcf.log.log("APP", "Config keys:", Object.keys(config)); fcf.log.log("APP", "Merged Aliases:", config.web_aliases);

Output:

2026-05-27 03:31:57.437 [PID:339592] [LOG] [MOD:APP]: Config keys: [ "warnEmptyContext", "defaultLanguage", "moduleDirectories", "webModuleDirectory", "aliases", "translations", "sessionLifetime", "tokenize", "sources", "packages", "aliases_merge_instructions", "web_aliases" ] 2026-05-27 03:31:57.438 [PID:339592] [LOG] [MOD:APP]: Merged Aliases: { "my_app:home" : "/index.html", "my_app:about" : "/about.html" }