When I write code, I tend to follow functional paradigms often. The main thing I try to do is use values returned from functions.
What I notice though, is I end up having a sort of function argument funnel where all the functions in the chain have the same arguments.
import fs from 'fs'
import path from 'path'
function dbFilePath(dbFilename: string) {
const filePath = path.join(__dirname, "../", dbFilename + ".db")
return filePath
}
export function fileData(dbFilename: string) {
const file = dbFilePath(dbFilename)
const fileContent = fs.readFileSync(
file,
"utf-8"
);
return fileContent
}
In this example code (which works fine), both functions have the same argument. This is an example of what I normally do.
What is best practice for structuring this piece of code?