Skip to content

Commit f9d393e

Browse files
committed
docs: update examples
1 parent 0f3cc79 commit f9d393e

File tree

2 files changed

+43
-49
lines changed

2 files changed

+43
-49
lines changed

.changeset/lovely-adults-nail.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@knide/pathnorm": patch
33
---
44

5-
add bundlephobia facts in README
5+
docs: update README examples + add bundlephobia facts

package/README.md

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,64 +40,62 @@ Exports `np` and `unixNp`.
4040
import { np, unixNp } from '@knide/pathnorm'
4141
```
4242

43-
### `np(...parts)`
43+
### `np(...parts)` (POSIX + Win32 + UNC + URLs)
4444

4545
Joins and normalizes path or URL segments. Detects and handles URLs, POSIX paths, Win32 drive letters, UNC paths, and Win32 namespace paths automatically.
4646

4747
```ts
4848
import { np } from '@knide/pathnorm'
49+
4950
// URLs
50-
np("https://abc.def//212/", "dw//we", "23123")
51-
// → "https://abc.def/212/dw/we/23123"
51+
np("https://example.com//api/", "v1//users", "profile")
52+
// → "https://example.com/api/v1/users/profile"
5253

53-
np("exp://abc.def//212/", "dw/we")
54-
// → "exp://abc.def/212/dw/we"
54+
np("exp://com.myapp//screens/", "home")
55+
// → "exp://com.myapp/screens/home"
5556

5657
// POSIX
57-
np("abc.def//212/", "dwwe", "23123")
58-
// → "abc.def/212/dwwe/23123"
59-
60-
np("foo//bar", "/baz")
61-
// → "/foo/bar/baz"
58+
np("/var/www//html/", "assets//images", "logo.png")
59+
// → "/var/www/html/assets/images/logo.png"
6260

63-
np("/foo//bar", "baz")
64-
// → "/foo/bar/baz"
61+
np("uploads//images", "/photos")
62+
// → "/uploads/images/photos"
6563

6664
// Win32 drive letter
67-
np("C:\\foo\\\\bar", "baz")
68-
// → "C:\foo\bar\baz"
65+
np("C:\\Users\\\\Alice\\Documents", "report.pdf")
66+
// → "C:\Users\Alice\Documents\report.pdf"
6967

7068
// UNC
71-
np("\\\\server\\share\\\\folder", "file.txt")
72-
// → "//server/share/folder/file.txt"
69+
np("\\\\server01\\share\\\\docs", "letter.txt")
70+
// → "//server01/share/docs/letter.txt"
7371

7472
// Win32 namespace
75-
np("\\\\?\\C:\\foo\\\\bar", "baz")
76-
// → "//?/C:/foo/bar/baz"
73+
np("\\\\?\\C:\\Users\\\\Alice", "report.pdf")
74+
// → "//?/C:/Users/Alice/report.pdf"
7775

78-
// Mixed slashes in Win32
79-
np("C:\\foo//bar\\\\baz")
80-
// → "C:\foo\bar\baz"
76+
// Mixed slashes
77+
np("C:\\projects//my-app\\\\src")
78+
// → "C:\projects\my-app\src"
8179
```
8280

83-
### `unixNp(...parts)`
81+
### `unixNp(...parts)` (always forward slashes)
8482

85-
Like `np`, but always returns a Unix-style path. Useful when working with Win32 paths but the consumer expects forward slashes.
83+
Like `np`, but always returns forward slashes. Useful when working with Win32 paths in a Unix-expecting context.
8684

8785
```ts
8886
import { unixNp } from '@knide/pathnorm'
89-
unixNp("C:\\foo\\\\bar", "baz")
90-
// → "C:/foo/bar/baz"
9187

92-
unixNp("\\\\server\\share\\\\folder", "file.txt")
93-
// → "//server/share/folder/file.txt"
88+
unixNp("C:\\Users\\\\Alice\\Documents", "report.pdf")
89+
// → "C:/Users/Alice/Documents/report.pdf"
90+
91+
unixNp("\\\\server01\\share\\\\docs", "letter.txt")
92+
// → "//server01/share/docs/letter.txt"
9493

95-
unixNp("\\\\?\\C:\\foo\\\\bar", "baz")
96-
// → "//?/C:/foo/bar/baz"
94+
unixNp("\\\\?\\C:\\Users\\\\Alice", "report.pdf")
95+
// → "//?/C:/Users/Alice/report.pdf"
9796

98-
// POSIX paths pass through unchanged
99-
unixNp("/foo//bar", "baz")
100-
// → "/foo/bar/baz"
97+
unixNp("/var/www//html", "index.html")
98+
// → "/var/www/html/index.html"
10199
```
102100

103101
---
@@ -112,26 +110,22 @@ import { np } from '@knide/pathnorm/posix'
112110

113111
### `np(...parts)` (POSIX + URLs)
114112

115-
Joins and normalizes URL or POSIX path segments.
116-
117113
```ts
118114
import { np } from '@knide/pathnorm/posix'
115+
119116
// URLs
120-
np("https://abc.def//212/", "dw//we", "23123")
121-
// → "https://abc.def/212/dw/we/23123"
117+
np("https://example.com//api/", "v1//users", "profile")
118+
// → "https://example.com/api/v1/users/profile"
122119

123-
np("exp://abc.def//212/", "dw/we")
124-
// → "exp://abc.def/212/dw/we"
120+
np("exp://com.myapp//screens/", "home")
121+
// → "exp://com.myapp/screens/home"
125122

126123
// POSIX
127-
np("abc.def//212/", "dwwe", "23123")
128-
// → "abc.def/212/dwwe/23123"
129-
130-
np("foo//bar", "/baz")
131-
// → "/foo/bar/baz"
124+
np("/var/www//html/", "assets//images", "logo.png")
125+
// → "/var/www/html/assets/images/logo.png"
132126

133-
np("/foo//bar", "baz")
134-
// → "/foo/bar/baz"
127+
np("uploads//images", "/photos")
128+
// → "/uploads/images/photos"
135129

136130
// Typical web usage
137131
np(window.location.origin, "/api/proxy//betterauth")
@@ -148,7 +142,7 @@ np(window.location.origin, "/api/proxy//betterauth")
148142
- Trailing slashes are not preserved.
149143

150144
```ts
151-
// Only first scheme is treated as prefix
152-
np("exp://", "sdfasdf", "abc.def//212/", "dw//we", "23123", "https://")
153-
// → "exp://sdfasdf/abc.def/212/dw/we/23123/https:/"
145+
// Only the first segment's scheme is treated as a URL prefix
146+
np("https://example.com//", "/api/v1", "http://users")
147+
// → "https://example.com/api/v1/http:/users"
154148
```

0 commit comments

Comments
 (0)