本文整理汇总了TypeScript中util.isNumber函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNumber函数的具体用法?TypeScript isNumber怎么用?TypeScript isNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isNumber函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
export default function(receivedMap: Map, map: Map): any {
if (isNumber(receivedMap.id) && isNumber(map.id)) {
expect(receivedMap.id).to.equal(map.id);
}
expect(receivedMap.dimensions).to.deep.equal(map.dimensions);
if (isString(receivedMap.creator) && isString(map.creator)) {
expect(receivedMap.creator).to.equal(map.creator);
}
expect(receivedMap.category).to.equal(map.category);
expect(receivedMap.name).to.equal(map.name);
expect(receivedMap.maximumAmountOfPlayers).to.equal(map.maximumAmountOfPlayers);
checkIfMapElementsAreEqual(receivedMap.buildings, map.buildings);
checkIfMapElementsAreEqual(receivedMap.units, map.units);
checkIfMapElementsAreEqual(receivedMap.terrain, map.terrain);
}
示例2: updateAsync
async updateAsync(favoriteIndex: number, favorite: Favorite, issuerId: ObjectID): Promise<Favorite> {
if (!isNumber(favoriteIndex)) {
throw new Error('favorite index must be a number');
}
if (!favorite) {
throw new Error('favorite must be set');
}
if (!issuerId) {
throw new Error('issuer must be set');
}
let updateDbReq = { $set: {} };
updateDbReq.$set[`favorites.${favoriteIndex}`] = favorite;
const result = await this.dbContext
.users
.findOneAndUpdate(
{ _id: issuerId },
updateDbReq,
{ projection: { favorites: 1 }, returnOriginal: false }
);
const favorites = result.value.favorites as Favorite[];
return favorites[favoriteIndex];
}
示例3: toInt
export function toInt(raw: any): number {
if (isNaN(raw)) return 0
if (isNumber(raw)) return Math.floor(raw)
if (!raw && !isString(raw)) return 0
const n = Number.parseInt(raw, 10)
if (isNaN(n)) return 0
return n
}
示例4: assertAndGetFavoriteIndex
static assertAndGetFavoriteIndex(rawParams: any): number {
if (!rawParams || !rawParams.favIndex) {
throw new Error('Index must be set.');
}
if (utils.isNumber(rawParams.favIndex)) {
throw new Error('Index must be a number.');
}
return +rawParams.favIndex;
}
示例5: transform
transform(value: any, args?: any): any {
console.log(value);
if (value) {
let sum = 0.0;
for (const s of value) {
if (isNumber(s['price'])) {
sum += s['price'];
}
}
return sum;
}
}
示例6: assertValidRequest
private static assertValidRequest(rawRequest: any) {
if (rawRequest === undefined) {
throw new Error('No rawRequest has been provided for userState');
}
if (rawRequest.playedPosition && !utils.isNumber(rawRequest.playedPosition)) {
throw new Error('playedPosition must be of type Number');
}
if (rawRequest.mediaQueue && !utils.isArray(rawRequest.mediaQueue)) {
throw new Error('mediaQueue must be of type Array');
}
if (rawRequest.browsingFolderPath && !utils.isString(rawRequest.browsingFolderPath)) {
throw new Error('browsingFolderPath must be of type String');
}
if (rawRequest.openedPlaylistPosition && !utils.isNumber(rawRequest.openedPlaylistPosition)) {
throw new Error('openedPlaylistPosition must be of type String');
}
if (rawRequest.playingMediumInQueueIndex && !utils.isNumber(rawRequest.playingMediumInQueueIndex)) {
throw new Error('playingMediumInQueueIndex must be of type Number');
}
}
示例7: dump
function dump(out: any): void {
let outText = "";
if (isBoolean(out)) {
outText = "| Boolean: ";
}
if (isNumber(out)) {
outText = "| Number: ";
}
if (isString(out)) {
outText = "| String: ";
}
if (isArray(out)) {
outText = "| Array: ";
}
console.log(outText, out);
}
示例8: isDecimal
export function isDecimal(value: number): boolean {
if (!isNumber(value))
return false;
else
return true;
}
示例9: it
it('is false if it is not a number', () => {
expect(isNumber('1')).to.be.false
expect(isNumber(null)).to.be.false
})