當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript underscore.isObject函數代碼示例

本文整理匯總了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);
 },
開發者ID:do5,項目名稱:mcgen,代碼行數:27,代碼來源:global-handler-hbs.ts

示例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;
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:27,代碼來源:factories_schema_helpers.ts

示例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;
    }
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:15,代碼來源:message_chunker.ts

示例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");
    }
開發者ID:lafe,項目名稱:VSCode-json2ts,代碼行數:49,代碼來源:Json2Ts.ts

示例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;
}
開發者ID:node-opcua,項目名稱:node-opcua,代碼行數:34,代碼來源:factories_schema_helpers.ts

示例6: function

 _.each(data, function (value, name) {
   if (_.isObject(value)) {
     self.replaceHiddenFields(record[name], value);
   } else {
     record[name] = value;
   }
 });
開發者ID:zettacristiano,項目名稱:forms-angular,代碼行數:7,代碼來源:data_form.ts

示例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);
   }
 });
開發者ID:coveo,項目名稱:search-ui,代碼行數:7,代碼來源:GenericValueOutput.ts

示例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;
		}

	};
開發者ID:molekilla,項目名稱:menio,代碼行數:59,代碼來源:menio.ts

示例9: serializeParameter

    private static serializeParameter(val: any): string {
        if (_.isObject(val) ||
            _.isArray(val))
        {
            return JSON.stringify(val);
        }

        return val;
    }
開發者ID:pumlhorse,項目名稱:pumlhorse,代碼行數:9,代碼來源:assert.ts

示例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);
  }
開發者ID:coveo,項目名稱:search-ui,代碼行數:10,代碼來源:GenericValueOutput.ts


注:本文中的underscore.isObject函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。