Skip to content

Instantly share code, notes, and snippets.

@shamasis
Last active December 30, 2015 08:39
Show Gist options
  • Save shamasis/7804182 to your computer and use it in GitHub Desktop.
Save shamasis/7804182 to your computer and use it in GitHub Desktop.
Function to test whether a path has any hidden folder in it or whether a file is hidden or not using regular expressions and not using the file-system. I find it particularly useful to validate a path that is user-provided and does not actually exist on disk. For unix based systems only.
/**
* Tests whether a path is a directory or possibly a file reference.
*
* @param {string} path
* @returns {boolean}
*/
isUnixDirectory: function (path) {
return (/(^\.+$)|(\/$)/).test(path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment