An open API service indexing awesome lists of open source software.

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. 🎱

Awesome Lists containing this project

README

          


Icon of UNC Path

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. β˜•




Donate to igorskyflyer




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/)).