Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fs.typeof method #11

Open
aleclarson opened this issue Oct 21, 2024 · 0 comments
Open

Add fs.typeof method #11

aleclarson opened this issue Oct 21, 2024 · 0 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@aleclarson
Copy link
Contributor

It returns the path type according to its on-disk representation.

Possible results include: file, directory, symlink, socket, fifo, characterDevice, blockDevice

// The path argument may be absolute or relative to the root directory.
fs.typeof('foo')

The best use case for this is a switch statement.

switch (fs.typeof(path)) {
  case 'file': 
    // ...
    break

  case 'directory':
    // ...
    break

  default:
    throw new Error('unsupported file type')
}

This is better than using fs.stat or fs.lstat, because change events don't need to be watched for like they do with those methods. Just need to use the existenceWatcher, I think.

@aleclarson aleclarson added good first issue Good for newcomers help wanted Extra attention is needed labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant