当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.isPlainObject函数代码示例

本文整理汇总了TypeScript中lodash.isPlainObject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isPlainObject函数的具体用法?TypeScript isPlainObject怎么用?TypeScript isPlainObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了isPlainObject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: deepDiff

 deepDiff(one: Object, two: Object, path: string = ''): IDeepDiff[] {
     let result: IDeepDiff[] = [];
     for (var key of _.keys(one)) {
         let concatPath: string = path ? path + '.' + key : key;
         if (_.isPlainObject(one[key])) {
             if (!_.has(two, key)) {
                 result.push(new DeepDiff('deleted', concatPath, one[key], null));
             } else {
                 result = _.concat(result, this.deepDiff(one[key], two[key], path ? path + '.' + key : key));
             }
         } else if (_.isBoolean(one[key]) || _.isDate(one[key]) || _.isNumber(one[key])
             || _.isNull(one[key]) || _.isRegExp(one[key]) || _.isString(one[key])) {
             if (!_.has(two, key)) {
                 result.push(new DeepDiff('deleted', concatPath, one[key], null));
             } else if (_.get(one, key) !== _.get(two, key)) {
                 result.push(new DeepDiff('edited', concatPath, one[key], two[key]));
             }
         } else if (_.isArray(one[key]) && _.isArray(two[key]) && !_.isEqual(one[key], two[key])) {
             result.push(new DeepDiff('array', concatPath, one[key], two[key]));
         } else if (!_.has(two, key)) {
             result.push(new DeepDiff('deleted', concatPath, one[key], null));
         }
     }
     for (var key of _.keys(two)) {
         let concatPath: string = path ? path + '.' + key : key;
         if (!_.has(one, key)) {
             if (_.isPlainObject(two[key]) || _.isBoolean(two[key]) || _.isDate(two[key]) || _.isNumber(two[key])
                 || _.isNull(two[key]) || _.isRegExp(two[key]) || _.isString(two[key]) || _.isArray(two[key])) {
                 result.push(new DeepDiff('created', concatPath, null, two[key]));
             }
         }
     }
     return result;
 }
开发者ID:fyyyyy,项目名称:chrobject,代码行数:34,代码来源:EntryAppService.ts

示例2: moveAssociationReferences

  private moveAssociationReferences(object: any): void {
    if (!object.$associations) object.$associations = {}

    var key
    for (key in object) {
      if (!object.hasOwnProperty(key)) continue

      var value = object[key]

      if (key === '$associations') continue

      if (isArray(value)) {
        var el = first(value)
        if (isPlainObject(el) && el['@id']) {
          // HABTM
          object.$associations[key] = clone(value)
          delete object[key]
        }
      }
      else if (isPlainObject(value) && value['@id']) {
        object.$associations[key] = clone(value)
        delete object[key]
      }
    }
  }
开发者ID:mediapeers,项目名称:chinchilla,代码行数:25,代码来源:subject.ts

示例3: typeOfSchema

export function typeOfSchema(schema: JSONSchema): SCHEMA_TYPE {
  if (schema.tsType) return 'CUSTOM_TYPE'
  if (schema.allOf) return 'ALL_OF'
  if (schema.anyOf) return 'ANY_OF'
  if (schema.oneOf) return 'ONE_OF'
  if (schema.items) return 'TYPED_ARRAY'
  if (schema.enum && schema.tsEnumNames) return 'NAMED_ENUM'
  if (schema.enum) return 'UNNAMED_ENUM'
  if (schema.$ref) return 'REFERENCE'
  if (Array.isArray(schema.type)) return 'UNION'
  switch (schema.type) {
    case 'string': return 'STRING'
    case 'number': return 'NUMBER'
    case 'integer': return 'NUMBER'
    case 'boolean': return 'BOOLEAN'
    case 'object':
      if (!schema.properties && !isPlainObject(schema)) {
        return 'OBJECT'
      }
      break
    case 'array': return 'UNTYPED_ARRAY'
    case 'null': return 'NULL'
    case 'any': return 'ANY'
  }

  switch (typeof schema.default) {
    case 'boolean': return 'BOOLEAN'
    case 'number': return 'NUMBER'
    case 'string': return 'STRING'
  }
  if (schema.id) return 'NAMED_SCHEMA'
  if (isPlainObject(schema) && Object.keys(schema).length) return 'UNNAMED_SCHEMA'
  return 'ANY'
}
开发者ID:bcherny,项目名称:json-schema-to-typescript,代码行数:34,代码来源:typeOfSchema.ts

示例4: normalize

    function normalize(value, key) {
        if (!value) return value

        if (isPlainObject(value)) {
            return mapValues(value, normalize)
        }

        if (isArray(value) && isPlainObject(value[0])) {
            return map(value, normalize)
        }

        if (key.includes('_at') || key.includes('_on')) {
            return '2017-10-10T16:00:00Z'
        }

        if (key.includes('_count')) {
            return 42
        }

        if (key.includes('id')) {
            return 1000 + id++
        }

        if (key.includes('node_id')) {
            return 'MDA6RW50aXR5MQ=='
        }

        if (key.includes('url')) {
            return value.replace(/[1-9][0-9]{2,10}/, '000000001')
        }

        return value
    }
开发者ID:node-gh,项目名称:gh,代码行数:33,代码来源:test-utils.ts

示例5: createDOMElement

export function createDOMElement(tagName, style, attributes) {
  /* eslint complexity:0 */
  assert(_.isString(tagName), 'createDOMElement expects the first argument, tagName, to be a DOM element');
  if (style) assert(_.isPlainObject(style), 'createDOMElement expects the second argument, style, to be a hash');
  if (attributes) assert(_.isPlainObject(attributes), 'createDOMElement expects the third argument, attributes, to be a hash');

  var domElement = document.createElement(tagName);

  if (style) addStyle(domElement, style);
  if (attributes) _.each(attributes, setAttribute(domElement));

  return domElement;
}
开发者ID:gurdiga,项目名称:xo,代码行数:13,代码来源:createDOMElement.ts

示例6: init

export default function init(options: Options = {}): Init {
  if (!isPlainObject(options)) {
    throw new TypeError("@cachemap/reaper expected options to be a plain object.");
  }

  return (callbacks: Callbacks) => new Reaper({ ...options, ...callbacks });
}
开发者ID:badbatch,项目名称:cachemap,代码行数:7,代码来源:index.ts

示例7:

 let unsetIgnoredSubProperties = (obj: any) => {
     if (_.isPlainObject(obj)) {
         for (var prop of this.options.ignoreSubProperties) {
             _.unset(obj, prop);
         }
     }
 };
开发者ID:hydra-newmedia,项目名称:chrobject,代码行数:7,代码来源:EntryAppService.ts

示例8: from

 public static from (value, args = []) {
   if (value instanceof Criteria) return value
   
   if (isPlainObject(value)) return this.fromObject(value)
   
   return new Criteria(Literal.from(value, args))
 }
开发者ID:vitaminjs,项目名称:query,代码行数:7,代码来源:criteria.ts

示例9: function

  return function(optionText) {
    var item = _.isPlainObject(optionText) ?
      createOptgroup(optionText) :
      createOption(optionText);

    domElement.appendChild(item);
  };
开发者ID:gurdiga,项目名称:xo,代码行数:7,代码来源:LabeledSelectField.ts

示例10: cb

export function dft<T, U>(object: { [k: string]: any }, cb: (value: U, key: string) => T): void {
  for (let key in object) {
    if (!object.hasOwnProperty(key)) continue
    if (isPlainObject(object[key])) dft(object[key], cb)
    cb(object[key], key)
  }
}
开发者ID:bcherny,项目名称:json-schema-to-typescript,代码行数:7,代码来源:utils.ts


注:本文中的lodash.isPlainObject函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。