@igorskyflyer/is-rootdir
v2.2.0
Published
🔼 Checks whether the given path is the root of a drive or filesystem. ⛔
Maintainers
Readme
📃 Table of Contents
🤖 Features
- 🖥 OS‑aware detection - auto‑adjusts logic for Windows or UNIX‑like systems
- 📂 Root path check - quickly tells if a path is a drive root or /
- 🔄 Cross‑platform helpers - uses
@igorskyflyer/upathfor consistent path formatting - 🪟 Windows‑specific check - validates
C:\style root directories - 🐧 UNIX‑specific check - validates / style root directories
- 🧩 Reusable core - single
checkRootDirectory()powers all variants - 🚫 Empty‑safe - gracefully handles missing or empty path strings
🛑 CAUTION
Implementation
Uses
Stringmanipulation techniques and it doesn't actually check if the path exists.
🕵🏼 Usage
Install it by executing any of the following, depending on your preferred package manager:
pnpm add @igorskyflyer/is-rootdiryarn add @igorskyflyer/is-rootdirnpm i @igorskyflyer/is-rootdir🤹🏼 API
Three functions are exposed,
isRootDirectory(path: string): boolean,isRootDirectoryUnix(path: string): boolean,isRootDirectoryWin(path: string): boolean.
💡 TIP
Differences
isDirectoryRoot()internally usesisRootDirectoryUnix()andisRootDirectoryWin()functions while taking into account the host OS and uses the appropriate function for the [OS], useful for cross-platform calls without having to worry about the path separators and related issues.
🗒️ Examples
import { isRootDirectoryUnix, isRootDirectoryWin } from '@igorskyflyer/is-rootdir'
// no examples and tests for isRootDirectory(), read why 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📝 Changelog
📑 The changelog is available here, CHANGELOG.md.
🪪 License
Licensed under the MIT license which is available here, MIT license.
💖 Support
🧬 Related
🕶️ Reads a JSON file into a Map. 🌻
🎡 Parse, manage, compare and output SemVer-compatible version numbers. 🛡
⛸ Strips Markdown headings!🏹
🧮 Calculates an estimated file size of Mp3 files. 🎶
@igorskyflyer/normalized-string
💊 NormalizedString provides you with a String type with consistent line-endings, guaranteed. 📮
👨🏻💻 Author
Created by Igor Dimitrijević (@igorskyflyer).
