本文整理汇总了TypeScript中underscore.isNumber函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isNumber函数的具体用法?TypeScript isNumber怎么用?TypeScript isNumber使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isNumber函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: coerceUInt64
export function coerceUInt64(value: any): UInt64 {
let high;
let low;
let v;
if (value === null || value === undefined) {
return value;
}
if (value instanceof Array) {
assert(_.isNumber(value[0]));
assert(_.isNumber(value[1]));
return value;
}
if (typeof(value) === "string") {
v = value.split(",");
high = parseInt(v[0], 10);
low = parseInt(v[1], 10);
return constructInt64(high, low);
}
if (value > 0xffffffff) {
// beware : as per javascript, value is a double here !
// our conversion will suffer from some inacuracy
high = Math.floor(value / 0x100000000);
low = value - high * 0x100000000;
return constructInt64(high, low);
}
return constructInt64(0, value);
}
示例2: _differenceScalar
function _differenceScalar(
value1: NumberType,
value2: NumberType,
dataType: DataType,
absoluteDeadband: number
): boolean {
let diff;
if (dataType === DataType.UInt64 || dataType === DataType.Int64) {
if (!(value1 instanceof Array && value2 instanceof Array)) {
throw new Error("Invalid");
}
const h1 = value1[0]; // high
const h2 = value2[0];
if (h1 !== h2) {
diff = (h1 - h2) * 4294967295;
if (Math.abs(diff) > absoluteDeadband) {
return true;
}
}
diff = value1[1] - value2[1];
assert(_.isNumber(diff) && _.isFinite(diff));
return Math.abs(diff) > absoluteDeadband;
}
if (!(typeof value1 === "number" && typeof value2 === "number")) {
throw new Error("Invalid");
}
diff = value2 - value1;
assert(_.isNumber(diff) && _.isFinite(diff));
return Math.abs(diff) > absoluteDeadband;
}
示例3: push
/* public */
public push(newDataValue: DataValue): any {
this._timeline.push(newDataValue);
const sourceTime = newDataValue.sourceTimestamp || new Date();
const sourcePicoSeconds = newDataValue.sourcePicoseconds || 0;
// ensure that values are set with date increasing
if (sourceTime.getTime() <= this.lastDate.getTime()) {
if (!(sourceTime.getTime() === this.lastDate.getTime() && sourcePicoSeconds > this.lastDatePicoSeconds)) {
console.log(chalk.red("Warning date not increasing "),
newDataValue.toString(), " last known date = ", this.lastDate);
}
}
this.lastDate = sourceTime;
this.lastDatePicoSeconds = newDataValue.sourcePicoseconds || 0;
// we keep only a limited amount in main memory
if (this._timeline.length > this._maxOnlineValues) {
assert(_.isNumber(this._maxOnlineValues) && this._maxOnlineValues > 0);
while (this._timeline.length > this._maxOnlineValues) {
this._timeline.shift();
}
}
if (this._timeline.length >= this._maxOnlineValues || this._timeline.length === 1) {
const first = this._timeline.first();
this.node._update_startOfOnlineArchive(first.sourceTimestamp);
// we update the node startOnlineDate
}
}
示例4: if
format: (key: string, ...args: any[]) => {
let value = key.toLocaleString();
// Try to find a soft match
// These conditions check if there was a change in the string (meaning toLocaleString found a match). If there was no
// match, try another format.
if (value == key) {
const tryTranslationInUpperCase = key.toUpperCase().toLocaleString();
const tryTranslationInLowerCase = key.toLowerCase().toLocaleString();
const tryTranslationAfterCapitalization = (key.charAt(0).toUpperCase() + key.toLowerCase().slice(1)).toLocaleString();
if (tryTranslationInUpperCase != key.toUpperCase().toLocaleString()) {
value = tryTranslationInUpperCase;
} else if (tryTranslationInLowerCase != key.toLowerCase().toLocaleString()) {
value = tryTranslationInLowerCase;
} else if (tryTranslationAfterCapitalization != key.charAt(0).toUpperCase() + key.toLowerCase().slice(1)) {
value = tryTranslationAfterCapitalization;
}
}
if (args.length > 0) {
let last = _.last(args);
// Last argument is either the count or a boolean forcing plural (true) or singular (false)
if (_.isBoolean(last) || _.isNumber(last)) {
args.pop();
value = L10N.formatPlSn(value, last);
}
_.each(args, (arg, i) => (value = value.replace(`{${i}}`, arg)));
} else {
// If there was no parameters passed, we try to cleanup the possible parameters in the translated string.
value = value.replace(/{[0-9]}|<pl>[a-zA-Z]+<\/pl>|<sn>|<\/sn>/g, '').trim();
}
return value;
},
示例5: _announceServerOnMulticastSubnet
export async function _announceServerOnMulticastSubnet(
multicastDNS: bonjour.Bonjour,
options: Announcement
): Promise<bonjour.Service> {
const port = options.port;
assert(_.isNumber(port));
assert(multicastDNS, "bonjour must have been initialized?");
const params: bonjour.ServiceOptions = {
name: options.name,
port,
protocol: "tcp",
txt: {
caps: options.capabilities.join(","),
path: options.path
},
type: "opcua-tcp"
};
const service: bonjour.Service = multicastDNS.publish(params);
service.on("error", (err: Error) => {
debugLog("bonjour ERROR received ! ", err.message);
debugLog("params = ", params);
});
// istanbul ignore next
if (doDebug) {
debugLog("Announcing ", params.name , "on port ", port , " txt ", JSON.stringify(params.txt));
}
service.start();
return service;
}
示例6: function
'iftype': function (val: any, type: 'array' | 'object' | 'boolean' | 'number' | 'string' | 'simple', options) {
let condition = false;
switch (type) {
case 'array':
condition = _.isArray(val)
break;
case 'object':
condition = _.isObject(val)
break;
case 'boolean':
condition = _.isBoolean(val)
break;
case 'number':
condition = _.isNumber(val)
break;
case 'string':
condition = _.isString(val)
break;
case 'simple':
condition = !(_.isObject(val) || _.isArray(val) || _.isUndefined(val));
break;
default:
condition = false;
break;
}
return Handlebars.helpers['if'].call(this, condition, options);
},
示例7: addSubscriber
/**
* add a subscriber to the WatchDog.
* @method addSubscriber
*
* add a subscriber to the WatchDog.
*
* This method modifies the subscriber be adding a
* new method to it called 'keepAlive'
* The subscriber must also provide a "watchdogReset". watchdogReset will be called
* if the subscriber failed to call keepAlive withing the timeout period.
* @param subscriber
* @param timeout
* @return the numerical key associated with this subscriber
*/
public addSubscriber(subscriber: ISubscriber, timeout: number): number {
const self = this;
self._currentTime = Date.now();
timeout = timeout || 1000;
assert(_.isNumber(timeout), " invalid timeout ");
assert(_.isFunction(subscriber.watchdogReset), " the subscriber must provide a watchdogReset method ");
assert(!_.isFunction(subscriber.keepAlive));
self._counter += 1;
const key = self._counter;
subscriber._watchDog = self;
subscriber._watchDogData = {
key,
lastSeen: self._currentTime,
subscriber,
timeout,
visitCount: 0
} as IWatchdogData2;
self._watchdogDataMap[key] = subscriber._watchDogData;
if (subscriber.onClientSeen) {
subscriber.onClientSeen(new Date(subscriber._watchDogData.lastSeen));
}
subscriber.keepAlive = keepAliveFunc.bind(subscriber);
// start timer when the first subscriber comes in
if (self.subscriberCount === 1) {
assert(self._timer === null);
this._start_timer();
}
return key;
}
示例8: encodeUInt64
export function encodeUInt64(value: UInt64 | number, stream: OutputBinaryStream) {
if (_.isNumber(value)) {
const arr = coerceUInt64(value);
stream.writeUInt32(arr[1]);
stream.writeUInt32(arr[0]);
} else {
stream.writeUInt32((value as number[])[1]);
stream.writeUInt32((value as number[])[0]);
}
}
示例9: checkDeadBand
export function checkDeadBand(
variant1: Variant,
variant2: Variant,
deadbandType: DeadbandType,
deadbandValue?: number,
valueRange?: number
): boolean {
switch (deadbandType) {
case DeadbandType.None:
// No Deadband calculation should be applied.
return difference(variant1, variant2, 0);
case DeadbandType.Absolute:
if (deadbandValue === undefined) {
throw new Error("Invalid deadbandValue");
}
// AbsoluteDeadband
return difference(variant1, variant2, deadbandValue);
default:
if (deadbandValue === undefined) {
throw new Error("Invalid deadbandValue");
}
// Percent_2 PercentDeadband (This type is specified in Part 8).
assert(deadbandType === DeadbandType.Percent);
// The range of the deadbandValue is from 0.0 to 100.0 Percent.
assert(deadbandValue >= 0 && deadbandValue <= 100);
// DeadbandType = PercentDeadband
// For this type of deadband the deadbandValue is defined as the percentage of the EURange. That is,
// it applies only to AnalogItems with an EURange Property that defines the typical value range for the
// item. This range shall be multiplied with the deadbandValue and then compared to the actual value change
// to determine the need for a data change notification. The following pseudo code shows how the deadband
// is calculated:
// DataChange if (absolute value of (last cached value - current value) >
// (deadbandValue/100.0) * ((high-low) of EURange)))
//
// Specifying a deadbandValue outside of this range will be rejected and reported with the
// StatusCode BadDeadbandFilterInvalid (see Table 27).
// If the Value of the MonitoredItem is an array, then the deadband calculation logic shall be applied to
// each element of the array. If an element that requires a DataChange is found, then no further
// deadband checking is necessary and the entire array shall be returned.
// assert(false, "Not implemented yet");
assert(_.isNumber(valueRange));
if (valueRange === undefined) {
throw new Error("Internal Error");
}
return checkDeadBand(variant1, variant2, DeadbandType.Absolute, valueRange * deadbandValue / 100);
}
}
示例10: keepAliveFunc
function keepAliveFunc(this: ISubscriber) {
const self: ISubscriber = this as ISubscriber;
assert(self._watchDog instanceof WatchDog);
if (!self._watchDogData) {
throw new Error("Internal error");
}
assert(_.isNumber(self._watchDogData.key));
self._watchDogData.lastSeen = Date.now();
if (self.onClientSeen) {
self.onClientSeen(new Date(self._watchDogData.lastSeen));
}
}