Skip to content

Instantly share code, notes, and snippets.

@shamasis
Last active December 29, 2015 17:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shamasis/7704671 to your computer and use it in GitHub Desktop.
Check whether a path has hidden directory or whether a file/directory is hidden.http://stackoverflow.com/questions/8905680/nodejs-check-for-hidden-files/
/**
* 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`.
*/
var isUnixHiddenPath = function (path) {
return (/(\/|^)\.[^\/\.]/g).test(path);
};
@iahu
Copy link

iahu commented Sep 14, 2015

test this case:
isUnixHiddenPath('../test'); // true
isUnixHiddenPath('./'); // true

It better change to
return (/(\/|^|.)\.[^\/\.]/g).test(path);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment