Socket
Socket
Sign inDemoInstall

@igor.dvlpr/is-rootdir

Package Overview
Dependencies
2
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @igor.dvlpr/is-rootdir

🔼 Provides a way to check if the given path is the root drive/directory. ⛔


Version published
Maintainers
1
Created

Readme

Source

is-rootdir

🔼 Provides a way to check if the given path is the root/drive directory. ⛔

Uses String manipulation techniques and it doesn't actually check if the path exists.


💖 Support further development

Donate to igorskyflyer



✨ Since version 2.0.0 is-rootdir is a hybrid module that supports both CommonJS (legacy) and ES modules, thanks to Modern Module.


Usage

Install it first by issuing,

npm i "@igor.dvlpr/is-rootdir"

Three functions are exposed,

  • isRootDirectory(path: string): boolean,
  • isRootDirectoryUnix(path: string): boolean,
  • isRootDirectoryWin(path: string): boolean.

isDirectoryRoot() internally uses isRootDirectoryUnix() and isRootDirectoryWin() functions while taking into accont the host OS and uses the appropriate function for it [OS], useful for cross-platform calls without having to worry about the path separators and related issues.


Use it as follows:

import { isRootDirectoryUnix, isRootDirectoryWin } from '@igor.dvlpr/is-rootdir'

// no examples and tests for isRootDirectory, read more above

console.log(isRootDirectoryUnix('')) // prints false

console.log(isRootDirectoryUnix('/')) // prints true

console.log(isRootDirectoryUnix('/////////')) // prints true - thanks to uPath, paths are normalized first 🤗

console.log(isRootDirectoryUnix('home')) // prints false

console.log(isRootDirectoryUnix('/home')) // prints false

console.log(isRootDirectoryUnix('/home/user')) // prints false

console.log(isRootDirectoryWin('')) // prints false

console.log(isRootDirectoryWin('D:')) // prints true

console.log(isRootDirectoryWin('D:\\\\\\\\\\')) // prints true - thanks to uPath, paths are normalized first 🤗

console.log(isRootDirectoryWin('D:\\')) // prints false

console.log(isRootDirectoryWin('D:\\Dev')) // prints false

console.log(isRootDirectoryWin('D:\\Dev\\Projects')) // prints false

Keywords

FAQs

Last updated on 10 Dec 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc