當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript path.normalize函數代碼示例

本文整理匯總了TypeScript中vs/base/common/path.normalize函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript normalize函數的具體用法?TypeScript normalize怎麽用?TypeScript normalize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了normalize函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getPathLabel

export function getPathLabel(resource: URI | string, userHomeProvider?: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string {
	if (typeof resource === 'string') {
		resource = URI.file(resource);
	}

	// return early if we can resolve a relative path label from the root
	if (rootProvider) {
		const baseResource = rootProvider.getWorkspaceFolder(resource);
		if (baseResource) {
			const hasMultipleRoots = rootProvider.getWorkspace().folders.length > 1;

			let pathLabel: string;
			if (isEqual(baseResource.uri, resource)) {
				pathLabel = ''; // no label if paths are identical
			} else {
				pathLabel = relativePath(baseResource.uri, resource)!;
			}

			if (hasMultipleRoots) {
				const rootName = (baseResource && baseResource.name) ? baseResource.name : basename(baseResource.uri);
				pathLabel = pathLabel ? (rootName + ' • ' + pathLabel) : rootName; // always show root basename if there are multiple
			}

			return pathLabel;
		}
	}

	// return if the resource is neither file:// nor untitled:// and no baseResource was provided
	if (resource.scheme !== Schemas.file && resource.scheme !== Schemas.untitled) {
		return resource.with({ query: null, fragment: null }).toString(true);
	}

	// convert c:\something => C:\something
	if (hasDriveLetter(resource.fsPath)) {
		return normalize(normalizeDriveLetter(resource.fsPath));
	}

	// normalize and tildify (macOS, Linux only)
	let res = normalize(resource.fsPath);
	if (!isWindows && userHomeProvider) {
		res = tildify(res, userHomeProvider.userHome);
	}

	return res;
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:45,代碼來源:labels.ts

示例2: builtinExtensionsPath

	@memoize
	get builtinExtensionsPath(): string {
		const fromArgs = parsePathArg(this._args['builtin-extensions-dir'], process);
		if (fromArgs) {
			return fromArgs;
		} else {
			return path.normalize(path.join(getPathFromAmdModule(require, ''), '..', 'extensions'));
		}
	}
開發者ID:joelday,項目名稱:vscode,代碼行數:9,代碼來源:environmentService.ts

示例3: extensionTestsLocationURI

	@memoize
	get extensionTestsLocationURI(): URI | undefined {
		const s = this._args.extensionTestsPath;
		if (s) {
			if (/^[^:/?#]+?:\/\//.test(s)) {
				return URI.parse(s);
			}
			return URI.file(path.normalize(s));
		}
		return undefined;
	}
開發者ID:joelday,項目名稱:vscode,代碼行數:11,代碼來源:environmentService.ts

示例4: assertMapping

export function assertMapping(writeFileIfDifferent: boolean, mapper: IKeyboardMapper, file: string): Promise<void> {
	const filePath = path.normalize(getPathFromAmdModule(require, `vs/workbench/services/keybinding/test/${file}`));

	return readFile(filePath).then((buff) => {
		let expected = buff.toString();
		const actual = mapper.dumpDebugInfo();
		if (actual !== expected && writeFileIfDifferent) {
			const destPath = filePath.replace(/vscode\/out\/vs/, 'vscode/src/vs');
			writeFile(destPath, actual);
		}

		assert.deepEqual(actual.split(/\r\n|\n/), expected.split(/\r\n|\n/));
	});
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:14,代碼來源:keyboardMapperTestUtils.ts

示例5: parsePathArg

function parsePathArg(arg: string | undefined, process: NodeJS.Process): string | undefined {
	if (!arg) {
		return undefined;
	}

	// Determine if the arg is relative or absolute, if relative use the original CWD
	// (VSCODE_CWD), not the potentially overridden one (process.cwd()).
	const resolved = path.resolve(arg);

	if (path.normalize(arg) === resolved) {
		return resolved;
	} else {
		return path.resolve(process.env['VSCODE_CWD'] || process.cwd(), arg);
	}
}
開發者ID:joelday,項目名稱:vscode,代碼行數:15,代碼來源:environmentService.ts

示例6: isRootOrDriveLetter

export function isRootOrDriveLetter(path: string): boolean {
	const pathNormalized = normalize(path);

	if (isWindows) {
		if (path.length > 3) {
			return false;
		}

		return isWindowsDriveLetter(pathNormalized.charCodeAt(0))
			&& pathNormalized.charCodeAt(1) === CharCode.Colon
			&& (path.length === 2 || pathNormalized.charCodeAt(2) === CharCode.Backslash);
	}

	return pathNormalized === posix.sep;
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:15,代碼來源:extpath.ts

示例7: test

	test('getFirstFrame', () => {
		let stack = 'at vscode.commands.registerCommand (/Users/someone/Desktop/test-ts/out/src/extension.js:18:17)';
		let frame = getFirstFrame(stack)!;

		assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
		assert.equal(frame.line, 18);
		assert.equal(frame.column, 17);

		stack = 'at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17';
		frame = getFirstFrame(stack)!;

		assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
		assert.equal(frame.line, 18);
		assert.equal(frame.column, 17);

		stack = 'at c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17';
		frame = getFirstFrame(stack)!;

		assert.equal(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
		assert.equal(frame.line, 18);
		assert.equal(frame.column, 17);

		stack = 'at e.$executeContributedCommand(c:\\Users\\someone\\Desktop\\end-js\\extension.js:18:17)';
		frame = getFirstFrame(stack)!;

		assert.equal(frame.uri.fsPath, 'c:\\Users\\someone\\Desktop\\end-js\\extension.js');
		assert.equal(frame.line, 18);
		assert.equal(frame.column, 17);

		stack = 'at /Users/someone/Desktop/test-ts/out/src/extension.js:18:17\nat /Users/someone/Desktop/test-ts/out/src/other.js:28:27\nat /Users/someone/Desktop/test-ts/out/src/more.js:38:37';
		frame = getFirstFrame(stack)!;

		assert.equal(frame.uri.fsPath, normalize('/Users/someone/Desktop/test-ts/out/src/extension.js'));
		assert.equal(frame.line, 18);
		assert.equal(frame.column, 17);
	});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:36,代碼來源:console.test.ts

示例8: extensionDevelopmentLocationURI

	@memoize
	get extensionDevelopmentLocationURI(): URI[] | undefined {
		const s = this._args.extensionDevelopmentPath;
		if (Array.isArray(s)) {
			return s.map(p => {
				if (/^[^:/?#]+?:\/\//.test(p)) {
					return URI.parse(p);
				}
				return URI.file(path.normalize(p));
			});
		} else if (s) {
			if (/^[^:/?#]+?:\/\//.test(s)) {
				return [URI.parse(s)];
			}
			return [URI.file(path.normalize(s))];
		}
		return undefined;
	}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:18,代碼來源:environmentService.ts

示例9: getEncodedDebugData

	static getEncodedDebugData(modelUri: uri): { name: string, path: string, sessionId?: string, sourceReference?: number } {
		let path: string;
		let sourceReference: number | undefined;
		let sessionId: string | undefined;

		switch (modelUri.scheme) {
			case Schemas.file:
				path = normalize(modelUri.fsPath);
				break;
			case DEBUG_SCHEME:
				path = modelUri.path;
				if (modelUri.query) {
					const keyvalues = modelUri.query.split('&');
					for (let keyvalue of keyvalues) {
						const pair = keyvalue.split('=');
						if (pair.length === 2) {
							switch (pair[0]) {
								case 'session':
									sessionId = decodeURIComponent(pair[1]);
									break;
								case 'ref':
									sourceReference = parseInt(pair[1]);
									break;
							}
						}
					}
				}
				break;
			default:
				path = modelUri.toString();
				break;
		}

		return {
			name: resources.basenameOrAuthority(modelUri),
			path,
			sourceReference,
			sessionId
		};
	}
開發者ID:eamodio,項目名稱:vscode,代碼行數:40,代碼來源:debugSource.ts

示例10: test

	test('Files: relative path matched once', function (done: () => void) {
		this.timeout(testTimeout);
		const engine = new FileSearchEngine({
			type: QueryType.File,
			folderQueries: ROOT_FOLDER_QUERY,
			filePattern: path.normalize(path.join('examples', 'company.js'))
		});

		let count = 0;
		let res: IRawFileMatch;
		engine.search((result) => {
			if (result) {
				count++;
			}
			res = result;
		}, () => { }, (error) => {
			assert.ok(!error);
			assert.equal(count, 1);
			assert.equal(path.basename(res.relativePath), 'company.js');
			done();
		});
	});
開發者ID:PKRoma,項目名稱:vscode,代碼行數:22,代碼來源:search.test.ts


注:本文中的vs/base/common/path.normalize函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。