UNPKG

@difizen/mana-common

Version:

61 lines (60 loc) 2.13 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { posix } from 'path-browserify'; import { CharCode } from "./char-code"; var posixPath = posix; var slash = '/'; export var Utils; (function (_Utils) { function joinPath(uri) { for (var _len = arguments.length, paths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { paths[_key - 1] = arguments[_key]; } return uri.with({ path: posixPath.join.apply(posixPath, [uri.path].concat(paths)) }); } _Utils.joinPath = joinPath; function resolvePath(uri) { var path = uri.path; var slashAdded = false; if (path[0] !== slash) { path = slash + path; // make the path abstract: for posixPath.resolve the first segments has to be absolute or cwd is used. slashAdded = true; } for (var _len2 = arguments.length, paths = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { paths[_key2 - 1] = arguments[_key2]; } var resolvedPath = posixPath.resolve.apply(posixPath, [path].concat(paths)); if (slashAdded && resolvedPath[0] === slash && !uri.authority) { resolvedPath = resolvedPath.substring(1); } return uri.with({ path: resolvedPath }); } _Utils.resolvePath = resolvePath; function dirname(uri) { if (uri.path.length === 0 || uri.path === slash) { return uri; } var path = posixPath.dirname(uri.path); if (path.length === 1 && path.charCodeAt(0) === CharCode.Period) { path = ''; } return uri.with({ path: path }); } _Utils.dirname = dirname; function basename(uri) { return posixPath.basename(uri.path); } _Utils.basename = basename; function extname(uri) { return posixPath.extname(uri.path); } _Utils.extname = extname; })(Utils || (Utils = {}));