Skip to content

Commit 790414a

Browse files
committed
release v0.1.0
0 parents  commit 790414a

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* text=auto eol=lf
2+
*.bat text eol=crlf
3+
*.cmd text eol=crlf
4+
*.ps1 text eol=crlf

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: ci
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
name: ${{ matrix.kind }} ${{ matrix.os }}
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [macOS-latest, ubuntu-latest, windows-latest]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Setup Deno
16+
uses: denolib/setup-deno@master
17+
with:
18+
deno-version: 1.3
19+
20+
- name: Format
21+
run: deno fmt --check
22+
23+
- name: Lint
24+
run: deno lint --unstable
25+
26+
- name: Test
27+
run: deno test

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.log
2+
.cache
3+
.DS_Store
4+
*bak
5+
.history
6+
.temp/**

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 0.1.0 - [2020-08-24]
4+
5+
- first release

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) justjavac.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# deno_is_unc_path
2+
3+
[![tag](https://img.shields.io/github/release/justjavac/deno_is_unc_path)](https://github.com/justjavac/deno_is_unc_path/releases)
4+
[![Build Status](https://github.com/justjavac/deno_is_unc_path/workflows/ci/badge.svg?branch=master)](https://github.com/justjavac/deno_is_unc_path/actions)
5+
[![license](https://img.shields.io/github/license/justjavac/deno_is_unc_path)](https://github.com/justjavac/deno_is_unc_path/blob/master/LICENSE)
6+
7+
Whether the filepath is a windows [UNC](https://msdn.microsoft.com/en-us/library/gg465305.aspx) file path.
8+
9+
ABNF syntax:
10+
11+
```plain
12+
UNC = "\\" host-name "\" share-name [ "\" object-name ]
13+
host-name = "[" IPv6address "]" / IPv4address / reg-name
14+
; IPv6address, IPv4address, and reg-name as specified in [RFC3986]
15+
share-name = 1*80pchar
16+
pchar = %x20-21 / %x23-29 / %x2D-2E / %x30-39 / %x40-5A / %x5E-7B / %x7D-FF
17+
object-name = *path-name [ "\" file-name ]
18+
path-name = 1*255pchar
19+
file-name = 1*255fchar [ ":" stream-name [ ":" stream-type ] ]
20+
fchar = %x20-21 / %x23-29 / %x2B-2E / %x30-39 / %x3B / %x3D / %x40-5B / %x5D-7B / %x7D-FF
21+
stream-name = *schar
22+
schar = %x01-2E / %x30-39 / %x3B-5B /%x5D-FF
23+
stream-type = 1*schar
24+
```
25+
26+
## Usage
27+
28+
```ts
29+
import isUncPath from "https://deno.land/x/is_unc_path/mod.ts";
30+
31+
// return `true`
32+
isUncPath('\\/foo/bar');
33+
isUncPath('\\\\foo/bar');
34+
isUncPath('\\\\foo\\admin$');
35+
isUncPath('\\\\foo\\admin$\\system32');
36+
isUncPath('\\\\foo\\temp');
37+
isUncPath('\\\\/foo/bar');
38+
isUncPath('\\\\\\/foo/bar');
39+
40+
// return `false`
41+
isUncPath('/foo/bar');
42+
isUncPath('/');
43+
isUncPath('/foo');
44+
isUncPath('/foo/');
45+
isUncPath('c:');
46+
isUncPath('c:.');
47+
isUncPath('c:./');
48+
isUncPath('c:./file');
49+
isUncPath('c:/');
50+
isUncPath('c:/file');
51+
```
52+
53+
## License
54+
55+
[deno_is_unc_path](https://github.com/justjavac/deno_is_unc_path) is released under the MIT License. See the bundled [LICENSE](./LICENSE) file for details.

mod.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const UNC_PATH_REGEX = /^[\\\/]{2,}[^\\\/]+[\\\/]+[^\\\/]+/;
2+
3+
/**
4+
* Whether the filepath is a windows [UNC](https://msdn.microsoft.com/en-us/library/gg465305.aspx) file path.
5+
* @param path
6+
*/
7+
export default function isUncPath(path: string): boolean {
8+
return UNC_PATH_REGEX.test(path);
9+
}

mod_test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// base on https://gDeno.testhub.com/jonschlinkert/is-isUncPath-path/blob/9bd6a77c5b12115869963d1b4c3078dda51c15da/test.js
2+
3+
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
4+
5+
import isUncPath from "./mod.ts";
6+
7+
Deno.test("should return true for UNC paths", function () {
8+
assertEquals(isUncPath("\\/foo/bar"), true);
9+
assertEquals(isUncPath("\\\\foo/bar"), true);
10+
assertEquals(isUncPath("\\\\foo\\admin$"), true);
11+
assertEquals(isUncPath("\\\\foo\\admin$\\system32"), true);
12+
assertEquals(isUncPath("\\\\foo\\temp"), true);
13+
assertEquals(isUncPath("\\\\/foo/bar"), true);
14+
assertEquals(isUncPath("\\\\\\/foo/bar"), true);
15+
});
16+
17+
Deno.test("should return false for non-UNC paths", function () {
18+
assertEquals(isUncPath("/foo/bar"), false);
19+
assertEquals(isUncPath("/"), false);
20+
assertEquals(isUncPath("/foo"), false);
21+
assertEquals(isUncPath("/foo/"), false);
22+
assertEquals(isUncPath("c:"), false);
23+
assertEquals(isUncPath("c:."), false);
24+
assertEquals(isUncPath("c:./"), false);
25+
assertEquals(isUncPath("c:./file"), false);
26+
assertEquals(isUncPath("c:/"), false);
27+
assertEquals(isUncPath("c:/file"), false);
28+
});

0 commit comments

Comments
 (0)