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


TypeScript strings.endsWith函數代碼示例

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


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

示例1: sanitizeFilePath

export function sanitizeFilePath(candidate: string, cwd: string): string {

	// Special case: allow to open a drive letter without trailing backslash
	if (isWindows && endsWith(candidate, ':')) {
		candidate += sep;
	}

	// Ensure absolute
	if (!isAbsolute(candidate)) {
		candidate = join(cwd, candidate);
	}

	// Ensure normalized
	candidate = normalize(candidate);

	// Ensure no trailing slash/backslash
	if (isWindows) {
		candidate = rtrim(candidate, sep);

		// Special case: allow to open drive root ('C:\')
		if (endsWith(candidate, ':')) {
			candidate += sep;
		}

	} else {
		candidate = rtrim(candidate, sep);

		// Special case: allow to open root ('/')
		if (!candidate) {
			candidate = sep;
		}
	}

	return candidate;
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:35,代碼來源:extpath.ts

示例2: compareAnything

export function compareAnything(one: string, other: string, lookFor: string): number {
	let elementAName = one.toLowerCase();
	let elementBName = other.toLowerCase();

	// Sort prefix matches over non prefix matches
	const prefixCompare = compareByPrefix(one, other, lookFor);
	if (prefixCompare) {
		return prefixCompare;
	}

	// Sort suffix matches over non suffix matches
	let elementASuffixMatch = strings.endsWith(elementAName, lookFor);
	let elementBSuffixMatch = strings.endsWith(elementBName, lookFor);
	if (elementASuffixMatch !== elementBSuffixMatch) {
		return elementASuffixMatch ? -1 : 1;
	}

	// Understand file names
	let r = compareFileNames(elementAName, elementBName);
	if (r !== 0) {
		return r;
	}

	// Compare by name
	return elementAName.localeCompare(elementBName);
}
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:26,代碼來源:comparers.ts

示例3: isValidBasename

export function isValidBasename(name: string): boolean {
	if (!name || name.length === 0 || /^\s+$/.test(name)) {
		return false; // require a name that is not just whitespace
	}

	INVALID_FILE_CHARS.lastIndex = 0; // the holy grail of software development
	if (INVALID_FILE_CHARS.test(name)) {
		return false; // check for certain invalid file characters
	}

	if (isWindows && WINDOWS_FORBIDDEN_NAMES.test(name)) {
		return false; // check for certain invalid file names
	}

	if (name === '.' || name === '..') {
		return false; // check for reserved values
	}

	if (isWindows && endsWith(name, '.')) {
		return false; // Windows: file cannot end with a "."
	}

	if (isWindows && name.length !== name.trim().length) {
		return false; // Windows: file cannot end with a whitespace
	}

	return true;
}
開發者ID:sangohan,項目名稱:KodeStudio,代碼行數:28,代碼來源:paths.ts

示例4: startWatching

	public startWatching(): () => void {
		if (this.contextService.getWorkspace().folders[0].uri.scheme !== Schemas.file) {
			return () => { };
		}
		let basePath: string = normalize(this.contextService.getWorkspace().folders[0].uri.fsPath);

		if (basePath && basePath.indexOf('\\\\') === 0 && endsWith(basePath, sep)) {
			// for some weird reason, node adds a trailing slash to UNC paths
			// we never ever want trailing slashes as our base path unless
			// someone opens root ("/").
			// See also https://github.com/nodejs/io.js/issues/1765
			basePath = rtrim(basePath, sep);
		}

		const watcher = new OutOfProcessWin32FolderWatcher(
			basePath,
			this.ignored,
			events => this.onRawFileEvents(events),
			error => this.onError(error),
			this.verboseLogging
		);

		return () => {
			this.isDisposed = true;
			watcher.dispose();
		};
	}
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:27,代碼來源:watcherService.ts

示例5: normalizeGitHubUrl

export function normalizeGitHubUrl(url: string): string {
	// If the url has a .git suffix, remove it
	if (endsWith(url, '.git')) {
		url = url.substr(0, url.length - 4);
	}

	// Remove trailing slash
	url = rtrim(url, '/');

	if (endsWith(url, '/new')) {
		url = rtrim(url, '/new');
	}

	if (endsWith(url, '/issues')) {
		url = rtrim(url, '/issues');
	}

	return url;
}
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:19,代碼來源:issueReporterUtil.ts

示例6: guessMimeTypeByPath

function guessMimeTypeByPath(path: string, filename: string, associations: ITextMimeAssociationItem[]): string {
	let filenameMatch: ITextMimeAssociationItem;
	let patternMatch: ITextMimeAssociationItem;
	let extensionMatch: ITextMimeAssociationItem;

	// We want to prioritize associations based on the order they are registered so that the last registered
	// association wins over all other. This is for https://github.com/Microsoft/vscode/issues/20074
	for (let i = associations.length - 1; i >= 0; i--) {
		const association = associations[i];

		// First exact name match
		if (filename === association.filenameLowercase) {
			filenameMatch = association;
			break; // take it!
		}

		// Longest pattern match
		if (association.filepattern) {
			if (!patternMatch || association.filepattern.length > patternMatch.filepattern.length) {
				const target = association.filepatternOnPath ? path : filename; // match on full path if pattern contains path separator
				if (match(association.filepatternLowercase, target)) {
					patternMatch = association;
				}
			}
		}

		// Longest extension match
		if (association.extension) {
			if (!extensionMatch || association.extension.length > extensionMatch.extension.length) {
				if (strings.endsWith(filename, association.extensionLowercase)) {
					extensionMatch = association;
				}
			}
		}
	}

	// 1.) Exact name match has second highest prio
	if (filenameMatch) {
		return filenameMatch.mime;
	}

	// 2.) Match on pattern
	if (patternMatch) {
		return patternMatch.mime;
	}

	// 3.) Match on extension comes next
	if (extensionMatch) {
		return extensionMatch.mime;
	}

	return null;
}
開發者ID:costincaraivan,項目名稱:vscode,代碼行數:53,代碼來源:mime.ts

示例7: normalizeGitHubIssuesUrl

export function normalizeGitHubIssuesUrl(url: string): string {
	// If the url has a .git suffix, remove it
	if (endsWith(url, '.git')) {
		url = url.substr(0, url.length - 4);
	}

	// Remove trailing slash
	url = rtrim(url, '/');

	// If the url already ends with issues/new, it's beautiful, return it
	if (endsWith(url, 'issues/new')) {
		return url;
	}

	// Add new segment if it does not exist
	if (endsWith(url, 'issues')) {
		return url + '/new';
	}

	return url + '/issues/new';
}
開發者ID:AllureFer,項目名稱:vscode,代碼行數:21,代碼來源:issueReporterUtil.ts

示例8: getSimpleWorkspaceLabel

export function getSimpleWorkspaceLabel(workspace: IWorkspaceIdentifier | URI, workspaceHome: URI): string {
	if (isSingleFolderWorkspaceIdentifier(workspace)) {
		return basename(workspace);
	}
	// Workspace: Untitled
	if (isEqualOrParent(workspace.configPath, workspaceHome)) {
		return localize('untitledWorkspace', "Untitled (Workspace)");
	}

	let filename = basename(workspace.configPath);
	if (endsWith(filename, WORKSPACE_EXTENSION)) {
		filename = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
	}
	return localize('workspaceName', "{0} (Workspace)", filename);
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:15,代碼來源:label.ts

示例9: parseMultiRootStorage

export function parseMultiRootStorage(storage: IStorageLegacy, targetWorkspaceId: string): StorageObject {
	const multiRootStoragePrefix = `${COMMON_WORKSPACE_PREFIX}${targetWorkspaceId}/`;

	const multiRootWorkspaceStorage: StorageObject = Object.create(null);
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		if (startsWith(key, multiRootStoragePrefix) && !endsWith(key, StorageLegacyService.WORKSPACE_IDENTIFIER)) {
			// storage://workspace/root:<id>/someKey => someKey
			multiRootWorkspaceStorage[key.substr(multiRootStoragePrefix.length)] = storage.getItem(key);
		}
	}

	return multiRootWorkspaceStorage;
}
開發者ID:,項目名稱:,代碼行數:15,代碼來源:

示例10: parseNoWorkspaceStorage

export function parseNoWorkspaceStorage(storage: IStorageLegacy) {
	const noWorkspacePrefix = `${StorageLegacyService.WORKSPACE_PREFIX}__$noWorkspace__`;

	const noWorkspaceStorage: StorageObject = Object.create(null);
	for (let i = 0; i < storage.length; i++) {
		const key = storage.key(i);

		// No Workspace key is for extension development windows
		if (startsWith(key, noWorkspacePrefix) && !endsWith(key, StorageLegacyService.WORKSPACE_IDENTIFIER)) {
			// storage://workspace/__$noWorkspace__someKey => someKey
			noWorkspaceStorage[key.substr(NO_WORKSPACE_PREFIX.length)] = storage.getItem(key);
		}
	}

	return noWorkspaceStorage;
}
開發者ID:,項目名稱:,代碼行數:16,代碼來源:


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