https://github.com/igorskyflyer/npm-unc-path
π₯½ Provides ways of parsing UNC paths and checking whether they are valid. π±
https://github.com/igorskyflyer/npm-unc-path
back-end biome filesystem igorskyflyer javascript node nodejs npm parser path typescript unc vitest
Last synced: 4 months ago
JSON representation
π₯½ Provides ways of parsing UNC paths and checking whether they are valid. π±
- Host: GitHub
- URL: https://github.com/igorskyflyer/npm-unc-path
- Owner: igorskyflyer
- License: mit
- Created: 2021-06-26T19:15:07.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-08-29T17:46:11.000Z (10 months ago)
- Last Synced: 2025-08-29T19:39:20.329Z (10 months ago)
- Topics: back-end, biome, filesystem, igorskyflyer, javascript, node, nodejs, npm, parser, path, typescript, unc, vitest
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@igorskyflyer/unc-path
- Size: 306 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
UNC Path
π₯½ Provides ways of parsing UNC paths and checking whether they are valid. π±
## π Table of Contents
- [Features](#-features)
- [Usage](#-usage)
- [API](#-api)
- [Examples](#οΈ-examples)
- [Changelog](#-changelog)
- [Support](#-support)
- [License](#-license)
- [Related](#-related)
- [Author](#-author)
## π€ Features
- π Detects UNC paths for both Windows and UNIX formats
- π₯οΈ Extracts `server` and `resource` parts with named capture groups
- π¦ Returns a typed object with `server` and `resource` keys
- π§© Simple API with `isValid()` and `parse()` functions
- β‘ Lightweight, zeroβdependency implementation
- π‘οΈ Handles empty or invalid inputs gracefully
- π Uses clear, maintainable regular expressions
- π TypeScript types for strong, predictable usage
- π Reusable patterns for consistent path parsing
## π΅πΌ Usage
Install it by executing any of the following, depending on your preferred package manager:
```bash
pnpm add @igorskyflyer/unc-path
```
```bash
yarn add @igorskyflyer/unc-path
```
```bash
npm i @igorskyflyer/unc-path
```
## π€ΉπΌ API
`isValid()` `=>` returns whether the given path is a UNC one.
Signature
```ts
isValid(path): boolean
```
Parameters
```ts
path: string // a string that represents the path to process
```
#### ποΈ Examples
```ts
import { isValid } from '@igorskyflyer/unc-path'
console.log(isValid('//ComputerName/SharedFolder/')) // returns true
console.log(isValid('//ComputerName/SharedFolder/file.mp4')) // returns true
console.log(isValid('/ComputerName/SharedFolder/')) // returns false
```
`parse()` `=>` parses the provided UNC path and returns UNC path's components as
```ts
{
'server': string,
'resource': string
}
```
Signature
```ts
parse(path): Object
```
Parameters
```ts
path: string // a string that represents the path to process
```
#### Example
```ts
import { parse } from '@igorskyflyer/unc-path'
console.log(parse('//Server/Dev/file.js'))
/*
returns {
server: 'Server',
resource: '/Dev/file.js',
}
*/
console.log(parse('/Server/Dev/file.js'))
/*
returns {
server: '',
resource: '',
}
*/
```
## π Changelog
π The changelog is available here, [CHANGELOG.md](https://github.com/igorskyflyer/npm-unc-path/blob/main/CHANGELOG.md).
## πͺͺ License
Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-unc-path/blob/main/LICENSE).
## π Support
I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. β
Thank you for supporting my efforts! ππ
## 𧬠Related
[@igorskyflyer/encode-entities](https://www.npmjs.com/package/@igorskyflyer/encode-entities)
> _πββοΈ Fast and simple Map and RegExp based HTML entities encoder. π_
[@igorskyflyer/regkeys](https://www.npmjs.com/package/@igorskyflyer/regkeys)
> _π An NPM package for fetching Windows registry keys. π_
[@igorskyflyer/upath](https://www.npmjs.com/package/@igorskyflyer/upath)
> _π Provides a universal way of formatting file-paths in Unix-like and Windows operating systems as an alternative to the built-in path.normalize(). π§¬_
[@igorskyflyer/is-rootdir](https://www.npmjs.com/package/@igorskyflyer/is-rootdir)
> _πΌ Provides a way to check if the given path is the root drive/directory. β_
[@igorskyflyer/valid-path](https://www.npmjs.com/package/@igorskyflyer/valid-path)
> _π§° Provides ways of testing whether a given value can be a valid file/directory name. π_
## π¨π»βπ» Author
Created by **Igor DimitrijeviΔ** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).