本文整理匯總了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
})