本文整理汇总了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;
}
示例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]
}
}
}
示例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'
}
示例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
}
示例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;
}
示例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 });
}
示例7:
let unsetIgnoredSubProperties = (obj: any) => {
if (_.isPlainObject(obj)) {
for (var prop of this.options.ignoreSubProperties) {
_.unset(obj, prop);
}
}
};
示例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))
}
示例9: function
return function(optionText) {
var item = _.isPlainObject(optionText) ?
createOptgroup(optionText) :
createOption(optionText);
domElement.appendChild(item);
};
示例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)
}
}