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


TypeScript is.number函數代碼示例

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


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

示例1:

const checkEvents = (t, events, bodySize = undefined) => {
	t.true(events.length >= 2);

	const hasBodySize = is.number(bodySize);
	let lastEvent = events.shift();

	if (!hasBodySize) {
		t.is(lastEvent.percent, 0);
	}

	for (const [index, event] of events.entries()) {
		if (hasBodySize) {
			t.is(event.percent, event.transferred / bodySize);
			t.true(event.percent > lastEvent.percent);
		} else {
			const isLastEvent = index === events.length - 1;
			t.is(event.percent, isLastEvent ? 1 : 0);
		}

		t.true(event.transferred >= lastEvent.transferred);
		t.is(event.total, bodySize);

		lastEvent = event;
	}
};
開發者ID:sindresorhus,項目名稱:got,代碼行數:25,代碼來源:progress.ts

示例2:

			retries: iteration => {
				t.true(is.number(iteration));
				return iteration < 2;
			}
開發者ID:sindresorhus,項目名稱:got,代碼行數:4,代碼來源:retry.ts

示例3: lowercaseKeys

export const preNormalizeArguments = (options: any, defaults?: any) => {
	if (is.nullOrUndefined(options.headers)) {
		options.headers = {};
	} else {
		options.headers = lowercaseKeys(options.headers);
	}

	if (options.baseUrl && !options.baseUrl.toString().endsWith('/')) {
		options.baseUrl += '/';
	}

	if (is.nullOrUndefined(options.hooks)) {
		options.hooks = {};
	} else if (!is.object(options.hooks)) {
		throw new TypeError(`Parameter \`hooks\` must be an object, not ${is(options.hooks)}`);
	}

	for (const event of knownHookEvents) {
		if (is.nullOrUndefined(options.hooks[event])) {
			if (defaults) {
				options.hooks[event] = [...defaults.hooks[event]];
			} else {
				options.hooks[event] = [];
			}
		}
	}

	if (is.number(options.timeout)) {
		options.gotTimeout = {request: options.timeout};
	} else if (is.object(options.timeout)) {
		options.gotTimeout = options.timeout;
	}

	delete options.timeout;

	const {retry} = options;
	options.retry = {
		retries: () => 0,
		methods: new Set(),
		statusCodes: new Set(),
		errorCodes: new Set(),
		maxRetryAfter: undefined
	};

	if (is.nonEmptyObject(defaults) && retry !== false) {
		options.retry = {...defaults.retry};
	}

	if (retry !== false) {
		if (is.number(retry)) {
			options.retry.retries = retry;
		} else {
			options.retry = {...options.retry, ...retry};
		}
	}

	if (!options.retry.maxRetryAfter && options.gotTimeout) {
		options.retry.maxRetryAfter = Math.min(...[options.gotTimeout.request, options.gotTimeout.connection].filter(n => !is.nullOrUndefined(n)));
	}

	if (is.array(options.retry.methods)) {
		options.retry.methods = new Set(options.retry.methods.map(method => method.toUpperCase()));
	}

	if (is.array(options.retry.statusCodes)) {
		options.retry.statusCodes = new Set(options.retry.statusCodes);
	}

	if (is.array(options.retry.errorCodes)) {
		options.retry.errorCodes = new Set(options.retry.errorCodes);
	}

	if (options.dnsCache) {
		const cacheableLookup = new CacheableLookup({cacheAdapter: options.dnsCache});
		options.lookup = cacheableLookup.lookup;
		delete options.dnsCache;
	}

	return options;
};
開發者ID:sindresorhus,項目名稱:got,代碼行數:80,代碼來源:normalize-arguments.ts

示例4: TypeError

const verify = (value: unknown, type: string) => {
	if (!is.string(value) && !is.number(value) && !is.boolean(value) && !is.null_(value)) {
		throw new TypeError(`The \`searchParams\` ${type} '${value}' must be a string, number, boolean or null`);
	}
};
開發者ID:sindresorhus,項目名稱:got,代碼行數:5,代碼來源:validate-search-params.ts


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