本文整理汇总了TypeScript中underscore.isObject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isObject函数的具体用法?TypeScript isObject怎么用?TypeScript isObject使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isObject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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);
},
示例2: initialize_field
export function initialize_field(field: StructuredTypeField, value: any) {
const _t = field.schema;
if (!_.isObject(_t)) {
throw new Error("initialize_field: expecting field.schema to be set " + field.name + " type = " + field.fieldType);
}
assert(_.isObject(field));
assert(!field.isArray);
if (field.category === FieldCategory.complex) {
if (field.fieldTypeConstructor) {
return new field.fieldTypeConstructor(value);
} else {
debugLog("xxxx => missing constructor for field type", field.fieldType);
}
}
const defaultValue = _t.computer_default_value(field.defaultValue);
value = _t.initialize_value(value, defaultValue);
if (field.validate) {
if (!field.validate(value)) {
throw Error(" invalid value " + value + " for field " + field.name + " of type " + field.fieldType);
}
}
return value;
}
示例3: update
/***
* update security information
*/
public update(options?: MessageChunkerOptions) {
options = options || {};
options.securityHeader = options.securityHeader ||
new AsymmetricAlgorithmSecurityHeader({securityPolicyUri: "http://opcfoundation.org/UA/SecurityPolicy#None"});
assert(_.isObject(options));
assert(_.isObject(options.securityHeader));
this.securityHeader = options.securityHeader;
this.derivedKeys = options.derivedKeys || undefined;
}
示例4: convertObjectToTsInterfaces
private convertObjectToTsInterfaces(jsonContent: any, objectName: string = "RootObject"): string {
let optionalKeys: string[] = [];
let objectResult: string[] = [];
for (let key in jsonContent) {
let value = jsonContent[key];
if (_.isObject(value) && !_.isArray(value)) {
let childObjectName = this.toUpperFirstLetter(key);
objectResult.push(this.convertObjectToTsInterfaces(value, childObjectName));
jsonContent[key] = this.removeMajority(childObjectName) + ";";
} else if (_.isArray(value)) {
let arrayTypes: any = this.detectMultiArrayTypes(value);
if (this.isMultiArray(arrayTypes)) {
let multiArrayBrackets = this.getMultiArrayBrackets(value);
if (this.isAllEqual(arrayTypes)) {
jsonContent[key] = arrayTypes[0].replace("[]", multiArrayBrackets);
} else {
jsonContent[key] = "any" + multiArrayBrackets + ";";
}
} else if (value.length > 0 && _.isObject(value[0])) {
let childObjectName = this.toUpperFirstLetter(key);
objectResult.push(this.convertObjectToTsInterfaces(value[0], childObjectName));
jsonContent[key] = this.removeMajority(childObjectName) + "[];";
} else {
jsonContent[key] = arrayTypes[0];
}
} else if (_.isDate(value)) {
jsonContent[key] = "Date;";
} else if (_.isString(value)) {
jsonContent[key] = "string;";
} else if (_.isBoolean(value)) {
jsonContent[key] = "boolean;";
} else if (_.isNumber(value)) {
jsonContent[key] = "number;";
} else {
jsonContent[key] = "any;";
optionalKeys.push(key);
}
}
let result = this.formatCharsToTypeScript(jsonContent, objectName, optionalKeys);
objectResult.push(result);
return objectResult.join("\n\n");
}
示例5: initialize_field_array
export function initialize_field_array(field: FieldType, valueArray: any) {
const _t = field.schema;
let value;
let i;
assert(_.isObject(field));
assert(field.isArray);
if (!valueArray && field.defaultValue === null) {
return null;
}
valueArray = valueArray || [];
let defaultValue: any = undefined;
if (_t.computer_default_value) {
defaultValue = _t.computer_default_value(field.defaultValue);
}
const arr = [];
for (i = 0; i < valueArray.length; i++) {
value = _t.initialize_value(valueArray[i], defaultValue);
arr.push(value);
}
if (field.validate) {
for (i = 0; i < arr.length; i++) {
if (!field.validate(arr[i])) {
throw Error(" invalid value " + arr[i] + " for field " + field.name + " of type " + field.fieldType);
}
}
}
return arr;
}
示例6: function
_.each(data, function (value, name) {
if (_.isObject(value)) {
self.replaceHiddenFields(record[name], value);
} else {
record[name] = value;
}
});
示例7:
section.forEach(sectionValue => {
if (isObject(sectionValue)) {
list.append($$('li', undefined, this.objectJoined(sectionValue as any).content).el);
} else {
list.append($$('li', undefined, this.valueOrNullOutput(sectionValue)).el);
}
});
示例8: __render
// TODO: Function overloading?
__render(html, callback: RenderCallback) {
var $scope = null;
var $cheerio = $;
if (_.isString(html)) {
$scope = $.load(html)(this._documentSelector);
} else if (_.isObject(html)) {
$scope = $(html).find(this._documentSelector); // must be DOM
} else {
return callback(new Error('Must be Cheerio DOM object'), null, null);
}
if (this._documentSelectorIndex) {
try {
$scope = $($scope[this._documentSelectorIndex]);
} catch (e) {
throw new Error('No selector index at "' + this._documentSelectorIndex + '"');
}
}
// monkey patch $scope
$scope.$find = MenioModel.__find($scope);
let self = {
model: {}
};
_.extend(self, this._props);
for (let i = 0; i < this._keys.length; i++) {
let name = this._keys[i];
try {
// DI - scope, cheerio and _
let opts = this._mappings[i].call(self, $($scope), $cheerio, _);
// only call next if callback and next
if (callback && opts && opts.next) {
callback(null, opts.$scope, self.model);
return;
} else {
if (!self.model[name]) {
self.model[name] = opts;
}
}
} catch (e) {
throw e;
}
}
if (callback) {
return callback(null, null, self.model);
} else {
return self.model;
}
};
示例9: serializeParameter
private static serializeParameter(val: any): string {
if (_.isObject(val) ||
_.isArray(val))
{
return JSON.stringify(val);
}
return val;
}
示例10: output
public output(section: GenericValueOutputType): ITableDataSource {
if (isArray(section)) {
return this.arrayJoined(section);
}
if (isObject(section)) {
return this.objectJoined(section as Record<string, any>);
}
return this.simpleValue(section as string | number | undefined);
}