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


TypeScript arrays.coalesce函數代碼示例

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


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

示例1: test

	test('coalesce', () => {
		let a = arrays.coalesce([null, 1, null, 2, 3]);
		assert.equal(a.length, 3);
		assert.equal(a[0], 1);
		assert.equal(a[1], 2);
		assert.equal(a[2], 3);

		arrays.coalesce([null, 1, null, void 0, undefined, 2, 3]);
		assert.equal(a.length, 3);
		assert.equal(a[0], 1);
		assert.equal(a[1], 2);
		assert.equal(a[2], 3);

		let b: number[] = [];
		b[10] = 1;
		b[20] = 2;
		b[30] = 3;
		b = arrays.coalesce(b);
		assert.equal(b.length, 3);
		assert.equal(b[0], 1);
		assert.equal(b[1], 2);
		assert.equal(b[2], 3);

		let sparse: number[] = [];
		sparse[0] = 1;
		sparse[1] = 1;
		sparse[17] = 1;
		sparse[1000] = 1;
		sparse[1001] = 1;

		assert.equal(sparse.length, 1002);

		sparse = arrays.coalesce(sparse);
		assert.equal(sparse.length, 5);
	});
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:35,代碼來源:arrays.test.ts

示例2: test

	test('coalesce', function () {
		let a = coalesce([null, 1, null, 2, 3]);
		assert.equal(a.length, 3);
		assert.equal(a[0], 1);
		assert.equal(a[1], 2);
		assert.equal(a[2], 3);

		coalesce([null, 1, null, void 0, undefined, 2, 3]);
		assert.equal(a.length, 3);
		assert.equal(a[0], 1);
		assert.equal(a[1], 2);
		assert.equal(a[2], 3);

		let b = [];
		b[10] = 1;
		b[20] = 2;
		b[30] = 3;
		b = coalesce(b);
		assert.equal(b.length, 3);
		assert.equal(b[0], 1);
		assert.equal(b[1], 2);
		assert.equal(b[2], 3);

		let sparse = [];
		sparse[0] = 1;
		sparse[1] = 1;
		sparse[17] = 1;
		sparse[1000] = 1;
		sparse[1001] = 1;

		assert.equal(sparse.length, 1002);

		sparse = coalesce(sparse);
		assert.equal(sparse.length, 5);
	});
開發者ID:JarnoNijboer,項目名稱:vscode,代碼行數:35,代碼來源:arrays.test.ts

示例3: done

		}, (error: Error[]): void => {
			if (error) {
				error = arrays.coalesce(error); // find any error by removing null values first
			}

			return done(error && error.length > 0 ? error[0] : null);
		});
開發者ID:KTXSoftware,項目名稱:KodeStudio,代碼行數:7,代碼來源:fileSearch.ts

示例4: suggestFilename

export function suggestFilename(langId: string, prefix: string): string {
	const extensions = registeredAssociations
		.filter(assoc => !assoc.userConfigured && assoc.extension && assoc.id === langId)
		.map(assoc => assoc.extension);
	const extensionsWithDotFirst = arrays.coalesce(extensions)
		.filter(assoc => strings.startsWith(assoc, '.'));

	if (extensionsWithDotFirst.length > 0) {
		return prefix + extensionsWithDotFirst[0];
	}

	return extensions[0] || prefix;
}
開發者ID:donaldpipowitch,項目名稱:vscode,代碼行數:13,代碼來源:mime.ts

示例5: test

	test('coalesce - inplace', function () {
		let a = [null, 1, null, 2, 3];
		arrays.coalesce(a, true);
		assert.equal(a.length, 3);
		assert.equal(a[0], 1);
		assert.equal(a[1], 2);
		assert.equal(a[2], 3);

		a = [null, 1, null, void 0, undefined, 2, 3];
		arrays.coalesce(a, true);
		assert.equal(a.length, 3);
		assert.equal(a[0], 1);
		assert.equal(a[1], 2);
		assert.equal(a[2], 3);

		let b = [];
		b[10] = 1;
		b[20] = 2;
		b[30] = 3;
		arrays.coalesce(b, true);
		assert.equal(b.length, 3);
		assert.equal(b[0], 1);
		assert.equal(b[1], 2);
		assert.equal(b[2], 3);

		let sparse = [];
		sparse[0] = 1;
		sparse[1] = 1;
		sparse[17] = 1;
		sparse[1000] = 1;
		sparse[1001] = 1;

		assert.equal(sparse.length, 1002);

		arrays.coalesce(sparse, true);
		assert.equal(sparse.length, 5);
	});
開發者ID:burhandodhy,項目名稱:azuredatastudio,代碼行數:37,代碼來源:arrays.test.ts

示例6: parsePathArguments

function parsePathArguments(cwd: string, args: string[], gotoLineMode?: boolean): string[] {
	const result = args.map(arg => {
		if (typeof arg !== 'string') {
			return null; // TODO@Ben workaround for https://github.com/Microsoft/vscode/issues/7498
		}

		let pathCandidate = arg;

		let parsedPath: IParsedPath;
		if (gotoLineMode) {
			parsedPath = parseLineAndColumnAware(arg);
			pathCandidate = parsedPath.path;
		}

		if (pathCandidate) {
			pathCandidate = preparePath(cwd, pathCandidate);
		}

		let realPath: string;
		try {
			realPath = fs.realpathSync(pathCandidate);
		} catch (error) {
			// in case of an error, assume the user wants to create this file
			// if the path is relative, we join it to the cwd
			realPath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(cwd, pathCandidate));
		}

		const basename = path.basename(realPath);
		if (basename /* can be empty if code is opened on root */ && !paths.isValidBasename(basename)) {
			return null; // do not allow invalid file names
		}

		if (gotoLineMode) {
			parsedPath.path = realPath;
			return toLineAndColumnPath(parsedPath);
		}

		return realPath;
	});

	const caseInsensitive = platform.isWindows || platform.isMacintosh;
	const distinct = arrays.distinct(result, e => e && caseInsensitive ? e.toLowerCase() : e);

	return arrays.coalesce(distinct);
}
開發者ID:Ayush-Mahajan,項目名稱:vscode,代碼行數:45,代碼來源:env.ts

示例7: doValidatePaths

function doValidatePaths(args: string[], gotoLineMode?: boolean): string[] {
	const cwd = process.env['VSCODE_CWD'] || process.cwd();
	const result = args.map(arg => {
		let pathCandidate = String(arg);

		let parsedPath: IPathWithLineAndColumn;
		if (gotoLineMode) {
			parsedPath = parseLineAndColumnAware(pathCandidate);
			pathCandidate = parsedPath.path;
		}

		if (pathCandidate) {
			pathCandidate = preparePath(cwd, pathCandidate);
		}

		let realPath: string;
		try {
			realPath = fs.realpathSync(pathCandidate);
		} catch (error) {
			// in case of an error, assume the user wants to create this file
			// if the path is relative, we join it to the cwd
			realPath = path.normalize(path.isAbsolute(pathCandidate) ? pathCandidate : path.join(cwd, pathCandidate));
		}

		const basename = path.basename(realPath);
		if (basename /* can be empty if code is opened on root */ && !paths.isValidBasename(basename)) {
			return null; // do not allow invalid file names
		}

		if (gotoLineMode) {
			parsedPath.path = realPath;
			return toPath(parsedPath);
		}

		return realPath;
	});

	const caseInsensitive = platform.isWindows || platform.isMacintosh;
	const distinct = arrays.distinct(result, e => e && caseInsensitive ? e.toLowerCase() : e);

	return arrays.coalesce(distinct);
}
開發者ID:StateFarmIns,項目名稱:vscode,代碼行數:42,代碼來源:paths.ts

示例8: toErrorMessage

export function toErrorMessage(error: any = null, verbose: boolean = false): string {
	if (!error) {
		return nls.localize('error.defaultMessage', "An unknown error occurred. Please consult the log for more details.");
	}

	if (Array.isArray(error)) {
		const errors: any[] = arrays.coalesce(error);
		const msg = toErrorMessage(errors[0], verbose);

		if (errors.length > 1) {
			return nls.localize('error.moreErrors', "{0} ({1} errors in total)", msg, errors.length);
		}

		return msg;
	}

	if (types.isString(error)) {
		return error;
	}

	if (error.detail) {
		const detail = error.detail;

		if (detail.error) {
			return exceptionToErrorMessage(detail.error, verbose);
		}

		if (detail.exception) {
			return exceptionToErrorMessage(detail.exception, verbose);
		}
	}

	if (error.stack) {
		return exceptionToErrorMessage(error, verbose);
	}

	if (error.message) {
		return error.message;
	}

	return nls.localize('error.defaultMessage', "An unknown error occurred. Please consult the log for more details.");
}
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:42,代碼來源:errorMessage.ts

示例9: getMultiSelectedResources

export function getMultiSelectedResources(resource: URI | object | undefined, listService: IListService, editorService: IEditorService): Array<URI> {
	const list = listService.lastFocusedList;
	if (list && list.getHTMLElement() === document.activeElement) {
		// Explorer
		if (list instanceof WorkbenchAsyncDataTree) {
			const selection = list.getSelection().map((fs: ExplorerItem) => fs.resource);
			const focusedElements = list.getFocus();
			const focus = focusedElements.length ? focusedElements[0] : undefined;
			const mainUriStr = URI.isUri(resource) ? resource.toString() : focus instanceof ExplorerItem ? focus.resource.toString() : undefined;
			// If the resource is passed it has to be a part of the returned context.
			// We only respect the selection if it contains the focused element.
			if (selection.some(s => URI.isUri(s) && s.toString() === mainUriStr)) {
				return selection;
			}
		}

		// Open editors view
		if (list instanceof List) {
			const selection = coalesce(list.getSelectedElements().filter(s => s instanceof OpenEditor).map((oe: OpenEditor) => oe.getResource()));
			const focusedElements = list.getFocusedElements();
			const focus = focusedElements.length ? focusedElements[0] : undefined;
			let mainUriStr: string | undefined = undefined;
			if (URI.isUri(resource)) {
				mainUriStr = resource.toString();
			} else if (focus instanceof OpenEditor) {
				const focusedResource = focus.getResource();
				mainUriStr = focusedResource ? focusedResource.toString() : undefined;
			}
			// We only respect the selection if it contains the main element.
			if (selection.some(s => s.toString() === mainUriStr)) {
				return selection;
			}
		}
	}

	const result = getResourceForCommand(resource, listService, editorService);
	return !!result ? [result] : [];
}
開發者ID:eamodio,項目名稱:vscode,代碼行數:38,代碼來源:files.ts

示例10: doValidatePaths

function doValidatePaths(args: string[], gotoLineMode?: boolean): string[] {
	const cwd = process.env['VSCODE_CWD'] || process.cwd();
	const result = args.map(arg => {
		let pathCandidate = String(arg);

		let parsedPath: IPathWithLineAndColumn | undefined = undefined;
		if (gotoLineMode) {
			parsedPath = parseLineAndColumnAware(pathCandidate);
			pathCandidate = parsedPath.path;
		}

		if (pathCandidate) {
			pathCandidate = preparePath(cwd, pathCandidate);
		}

		const sanitizedFilePath = sanitizeFilePath(pathCandidate, cwd);

		const basename = path.basename(sanitizedFilePath);
		if (basename /* can be empty if code is opened on root */ && !extpath.isValidBasename(basename)) {
			return null; // do not allow invalid file names
		}

		if (gotoLineMode && parsedPath) {
			parsedPath.path = sanitizedFilePath;

			return toPath(parsedPath);
		}

		return sanitizedFilePath;
	});

	const caseInsensitive = platform.isWindows || platform.isMacintosh;
	const distinct = arrays.distinct(result, e => e && caseInsensitive ? e.toLowerCase() : (e || ''));

	return arrays.coalesce(distinct);
}
開發者ID:joelday,項目名稱:vscode,代碼行數:36,代碼來源:paths.ts


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