当前位置: 首页>>代码示例>>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;未经允许,请勿转载。