本文整理汇总了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;
}
};
示例2:
retries: iteration => {
t.true(is.number(iteration));
return iteration < 2;
}
示例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;
};
示例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`);
}
};