@igor.dvlpr/unc-path

🥽 Provides ways of parsing UNC paths and checking whether they are valid. 🎱

Usage no npm install needed!

<script type="module">
  import igorDvlprUncPath from 'https://cdn.skypack.dev/@igor.dvlpr/unc-path';
</script>

README

UNC Path

🥽 Provides ways of parsing UNC paths and checking whether they are valid. 🎱


UNC Path



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


Usage


Install it first by doing

npm i @igor.dvlpr/unc-path

and call require in your code, i.e.:

const unc = require('@igor.dvlpr/unc-path')
// or destructure the object and import only needed function(s)
// e.g.
const { isValid } = require('@igor.dvlpr/unc-path')

// do something cool with it

API


isValid() => returns whether the given path is a UNC one.


Signature

isValid(path): boolean

Parameters

path: string // a string that represents the path to process

Example

const { isValid } = require('@igor.dvlpr/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

{
    'server': string,
    'resource': string
}

Signature

parse(path): Object

Parameters

path: string // a string that represents the path to process

Example

const { parse } = require('@igor.dvlpr/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: '',
        }
*/