File tree 3 files changed +56
-8
lines changed
src/internal/filepathlite
3 files changed +56
-8
lines changed Original file line number Diff line number Diff line change 73
73
}
74
74
}
75
75
76
- if ( ! globalThis . path ) {
77
- globalThis . path = {
78
- resolve ( ...pathSegments ) {
79
- return pathSegments . join ( "/" ) ;
80
- }
81
- }
82
- }
76
+ if ( ! globalThis . path ) {
77
+ globalThis . path = {
78
+ resolve ( ...pathSegments ) {
79
+ return pathSegments . join ( "/" ) ;
80
+ } ,
81
+ isAbsolute ( path ) {
82
+ return path [ 0 ] === "/" ;
83
+ } ,
84
+ parse ( path ) {
85
+ return {
86
+ root : "/"
87
+ }
88
+ } ,
89
+ normalize ( path ) {
90
+ return path ;
91
+ } ,
92
+ sep : "/" ,
93
+ }
94
+ }
83
95
84
96
if ( ! globalThis . crypto ) {
85
97
throw new Error ( "globalThis.crypto is not available, polyfill required (crypto.getRandomValues only)" ) ;
Original file line number Diff line number Diff line change
1
+ // Copyright 2024 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ //go:build js && wasm
6
+
7
+ package filepathlite
8
+
9
+ import "syscall/js"
10
+
11
+ func IsPathSeparator (c uint8 ) bool {
12
+ return c == '\\' || c == '/'
13
+ }
14
+
15
+ var jsPath = js .Global ().Get ("path" )
16
+
17
+ var (
18
+ Separator = jsPath .Get ("sep" ).String ()[0 ]
19
+ )
20
+
21
+ func isLocal (path string ) bool {
22
+ return ! jsPath .Call ("isAbsolute" , path ).Bool ()
23
+ }
24
+
25
+ func localize (path string ) (string , error ) {
26
+ return jsPath .Call ("normalize" , path ).String (), nil
27
+ }
28
+
29
+ func IsAbs (path string ) bool {
30
+ return jsPath .Call ("isAbsolute" , path ).Bool ()
31
+ }
32
+
33
+ func volumeNameLen (path string ) int {
34
+ length := jsPath .Call ("parse" , path ).Get ("root" ).Get ("length" ).Int ()
35
+ return max (0 , length - 1 )
36
+ }
Original file line number Diff line number Diff line change 2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
- //go:build unix || (js && wasm) || wasip1
5
+ //go:build unix || wasip1
6
6
7
7
package filepathlite
8
8
You can’t perform that action at this time.
0 commit comments