本文整理汇总了TypeScript中core/util/types.isPlainObject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isPlainObject函数的具体用法?TypeScript isPlainObject怎么用?TypeScript isPlainObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isPlainObject函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: strip_ids
function strip_ids(value: any): void {
if (isArray(value)) {
for (const v of value) {
strip_ids(v)
}
} else if (isPlainObject(value)) {
if ('id' in value) {
delete value.id
}
for (const k in value) {
strip_ids(value[k])
}
}
}
示例2: deep_value_to_json
function deep_value_to_json(_key: string, value: any, _optional_parent_object: any): any {
if (value instanceof HasProps) {
return {type: value.type, attributes: value.attributes_as_json()}
} else if (isArray(value)) {
const ref_array: any[] = []
for (let i = 0; i < value.length; i++) {
ref_array.push(deep_value_to_json(i.toString(), value[i], value))
}
return ref_array
} else if (isPlainObject(value)) {
const ref_obj: {[key: string]: any} = {}
for (const subkey in value) {
if (value.hasOwnProperty(subkey))
ref_obj[subkey] = deep_value_to_json(subkey, value[subkey], value)
}
return ref_obj
} else
return value
}
示例3: _value_to_json
static _value_to_json(key: string, value: any, optional_parent_object: any): any {
if (isPlainObject(value) && key === 'data')
return encode_column_data(value as any, optional_parent_object._shapes) // XXX: unknown vs. any
else
return HasProps._value_to_json(key, value, optional_parent_object)
}
示例4: check_matching_defaults
function check_matching_defaults(name: string, python_defaults: KV, bokehjs_defaults: KV): boolean {
const different: string[] = []
const python_missing: string[] = []
const bokehjs_missing: string[] = []
for (const k in bokehjs_defaults) {
const js_v = bokehjs_defaults[k]
// special case for graph renderer node_renderer
if (name === "GraphRenderer" && k === "node_renderer")
continue
// special case for graph renderer node_renderer
if (name === "GraphRenderer" && k === "edge_renderer")
continue
// special case for date picker, default is "now"
if (name === 'DatePicker' && k === 'value')
continue
// special case for date time tickers, class hierarchy and attributes are handled differently
if (name === "DatetimeTicker" && k === "tickers")
continue
// special case for Title derived text properties
if (name === "Title" && (k === "text_align" || k === "text_baseline"))
continue
if (k === 'id')
continue
if (k in python_defaults) {
let py_v = python_defaults[k]
strip_ids(py_v)
if (!isEqual(py_v, js_v)) {
// these two conditionals compare 'foo' and {value: 'foo'}
if (isPlainObject(js_v) && 'value' in js_v && isEqual(py_v, js_v.value))
continue
if (isPlainObject(py_v) && 'value' in py_v && isEqual(py_v.value, js_v))
continue
if (isPlainObject(js_v) && 'attributes' in js_v && isPlainObject(py_v) && 'attributes' in py_v) {
if (js_v.type === py_v.type) {
check_matching_defaults(`${name}.${k}`, py_v.attributes as KV, js_v.attributes as KV)
continue
}
}
// compare arrays of objects
if (isArray(js_v) && isArray(py_v)) {
let equal = true
// palettes in JS are stored as int color values
if (k === 'palette')
py_v = py_v.map((x: string) => parseInt(x.slice(1), 16))
if (js_v.length !== py_v.length)
equal = false
else {
for (let i = 0; i < js_v.length; i++) {
delete (js_v[i] as any).id
delete (py_v[i] as any).id
if (!isEqual(js_v[i], py_v[i])) {
equal = false
break
}
}
}
if (equal)
continue
}
different.push(`${name}.${k}: bokehjs defaults to ${safe_stringify(js_v)} but python defaults to ${safe_stringify(py_v)}`)
}
} else {
python_missing.push(`${name}.${k}: bokehjs defaults to ${safe_stringify(js_v)} but python has no such property`)
}
}
for (const k in python_defaults) {
if (!(k in bokehjs_defaults)) {
const v = python_defaults[k]
bokehjs_missing.push(`${name}.${k}: python defaults to ${safe_stringify(v)} but bokehjs has no such property`)
}
}
function complain(failures: string[], message: string): void {
if (failures.length > 0) {
console.error(message)
for (const f of failures)
console.error(` ${f}`)
}
}
complain(different, `${name}: defaults are out of sync between Python and bokehjs`)
complain(python_missing, `${name}: python is missing some properties found in bokehjs`)
complain(bokehjs_missing, `${name}: bokehjs is missing some properties found in Python`)
//.........这里部分代码省略.........