Check if UNIX Path has Hidden Directory or File

This snippet of code uses regular expression to test if a path string contains any hidden directory. The use-case was derived from the difficulty in determining whether directory is hidden or not using NodeJS path module. Owing to the possibility of their existence within a long path string, this function returns false if any directory or the terminal file of a path has a name that starts with a dot.

 * Checks whether a path starts with or contains a hidden file or a folder.
 * @param {string} source - The path of the file that needs to be validated.
 * returns {boolean} - `true` if the source is blacklisted and otherwise `false`.
 * @example
 * console.log(isUnixHiddenPath('~/documents')); // prints `false`
 * console.log(isUnixHiddenPath('~/documents/file.txt')); // prints `false`
 * console.log(isUnixHiddenPath('~/source/repo/.gitignore')); // prints `true`
 * console.log(isUnixHiddenPath('~/source/repo/.git/config')); // prints `true` 
var isUnixHiddenPath = function (path) { 
    return (/(^|./).+[^/.]/g).test(path); 

A relevant StackOverflow question is located at and a gist is at

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.