0

I have a function that takes in input a config file; this config file is in fact an object, something like

file first.js

// first config file

const common = require(../common)

// function that returns random day,month,year
const { day, month, year } = time.getDate()

module.exports = {
    ...common,

    dayToChoose: day,
    monthToChoose: month,
    yearToChoose: year,

    [other data]
}

since I can have different versions of this config file, each of them named differently (second.js, third.js, etc. with different data each), I created a "basic" configuration common to all of those files.

common.js is a config file that contains some data.

My question is: can common.js contain something like

const { commonDay, commonMonth, commonYear } = time.getDate()

module.exports = {
    dayToChoose: commonDay,
    monthToChoose: commonMonth,
    yearToChoose: commonYear
}

and put something in my first config file that says "if day, month, and year already exists, take those data, otherwise take the data present in the first.js file" ?

Something like

// first config file

const common = require(../common)

// function that returns random day,month,year
const { day, month, year } = time.getDate()

module.exports = {
    ...common,

    dayToChoose: dayToChoose || day,        // error: dayToChoose is not defined
    monthToChoose: monthToChoose || month,  // like above
    yearToChoose: yearToChoose || year,     // like above

    [other data which varies]
}

Don Diego
  • 1,309
  • 3
  • 23
  • 46

0 Answers0