forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUtils.js
More file actions
1 lines (1 loc) · 1.14 KB
/
Utils.js
File metadata and controls
1 lines (1 loc) · 1.14 KB
1
var nodeURL=require("url"),path=require("path");function pathToUri(filePath){var newPath=convertWinToPosixPath(filePath);return"/"!==newPath[0]&&(newPath=`/${newPath}`),encodeURI(`file://${newPath}`).replace(/[?#]/g,encodeURIComponent)}function uriToPath(uri){var url=nodeURL.URL.parse(uri);if("file:"!==url.protocol||void 0===url.path)return uri;let filePath=decodeURIComponent(url.path);return"win32"===process.platform?("/"===filePath[0]&&(filePath=filePath.substr(1)),filePath):filePath}function convertPosixToWinPath(filePath){return filePath.replace(/\//g,"\\")}function convertWinToPosixPath(filePath){return filePath.replace(/\\/g,"/")}function convertToLSPPosition(pos){return{line:pos.line,character:pos.ch}}function convertToWorkspaceFolders(paths){var workspaceFolders;return paths.map(function(folderPath){var uri,name;return{uri:pathToUri(folderPath),name:path.basename(folderPath)}})}exports.uriToPath=uriToPath,exports.pathToUri=pathToUri,exports.convertPosixToWinPath=convertPosixToWinPath,exports.convertWinToPosixPath=convertWinToPosixPath,exports.convertToLSPPosition=convertToLSPPosition,exports.convertToWorkspaceFolders=convertToWorkspaceFolders;