본문으로 건너뛰기

toValidFilePath

Node.js 런타임 필요 ('qsu/node')

경로에 있는 유효하지 않거나 불필요한 문자를 제거합니다.

... 세그먼트는 해석되어 정리되며, 아무것도 남지 않는 경로는 루트를 반환합니다. 결과는 항상 절대 경로이고, ..는 루트 위로 올라갈 수 없으므로 ../../etc/passwd/etc/passwd가 됩니다.

Parameters

이름타입필수기본값
filePathstringStringstr
isWindowsnamedkeywordbooleanbool
Whether the target operating system to be checked is Windows

named이 파라미터는 named 파라미터로 전달합니다.

keyword이 파라미터는 키워드 인자로 전달하거나, 대신 dict 하나로 전달합니다.

Returns

string

String

str

Examples

javascript
toValidFilePath('C:\\Windows\\System32\\', true); // 'C:\Windows\System32'
toValidFilePath('home/user/.bashrc'); // '/home/user/.bashrc'
toValidFilePath('/home/user/../test'); // '/home/test'
dart
toValidFilePath('C:\\Windows\\System32\\', isWindows: true); // 'C:\Windows\System32'
toValidFilePath('home/user/.bashrc'); // '/home/user/.bashrc'
toValidFilePath('/home/user/../test'); // '/home/test'
python
toValidFilePath('C:\\Windows\\System32\\', True) # 'C:\Windows\System32'
toValidFilePath('home/user/.bashrc') # '/home/user/.bashrc'
toValidFilePath('/home/user/../test') # '/home/test'

Released under the MIT License