As others have said, there is no single solution. I have written a Julia library (HiddenFiles.jl) which attempts to be complete, but there are a lot of edge cases (especially for macOS, with different types of hidden files and constantly changing APIs. More information about the functionality of this algorithm can be found here.