UNPKG

@cainiaofe/cn-ui-m

Version:
167 lines (166 loc) 4.96 kB
import React from 'react'; /** * 获取对象的类型 * @param {*} obj * @return {String} * * @example * typeOf([]) === 'Array' * typeOf() === 'Undefined' * typeOf(1) === 'Number' */ export declare function typeOf(obj: any): any; /** * 判断对象是否是一个promise,即是否可以用.then */ export declare function isPromise(obj: unknown | Promise<unknown>): boolean; /** * 是否是一个纯净的对象 * @param {*} obj * @return {Boolean} * @reference https://github.com/jonschlinkert/is-plain-object */ export declare function isPlainObject(obj: { constructor: any; }): boolean; /** * 对象浅比较 * @param {Object} objA * @param {Object} objB * @param {Function} [compare] 手动调用方法比较 * @return {Boolean} 对象浅比较是否相等 * * @example * object.shallowEqual({a: 100}, {a: 100}); // true */ export declare function shallowEqual(objA: { [x: string]: any; }, objB: { [x: string]: any; }, compare: (arg0: any, arg1: any, arg2: string) => any): boolean; /** * 遍历对象或数组,或者类数组,例如React中的children对象、arguments等 * @param {Object|Array} obj * @param {Function} callback fn(n, i) or fn(val, key) * @param {Number} [direction = 1] 是否倒序遍历,只对数组有效 * @return {Object|Array} * * @example * // 遍历数组 * object.each([100, 200, 300], (n, i) => console.log(n, i)); * // 遍历json对象 * object.each({a: 100, b: 200}, (value, key) => console.log(key, value)); * // 遍历React子节点 * object.each(this.props.children, (child, index) => console.log(child)); * // 遍历arguments * object.each(arguments, (arg, i) => console.log(arg)); */ export declare function each(obj: string | any[], callback: { call: (arg0: any, arg1: any, arg2: number) => any; }, direction: number): string | any[]; /** * 过滤出其它属性 * @param {Object|Array} holdProps 过滤的参照对象,最终的结果只保留不在参照对象中的key * @param {Object} props 被过滤的对象 * @return {Object} others * * @example * object.pickOthers(FooComponent.propTypes, this.props); * object.pickOthers(['className', 'onChange'], this.props); */ export declare function pickOthers(holdProps: string[], props: Readonly<any> & Readonly<{ children?: React.ReactNode; }>): any; /** * 过滤出需要的属性 * @param {Object|Array} holdProps 过滤的参照对象,最终的结果只保留在参照对象中的key * @param {Object} props 被过滤的对象 * @return {Object} others * * @example * object.pickProps(FooComponent.propTypes, this.props); * object.pickProps(['className', 'onChange'], this.props); */ export declare function pickProps(holdProps: any, props: { [x: string]: any; }): any; /** * 过滤出带prefix的属性 * @param {Object} holdProps 过滤的参照对象,最终的结果只保留不在参照对象中的key * @param {string} prefix 包含的字符串 * @return {Object} others * * @example * object.pickAttrsWith(FooComponent.propTypes, 'data-'); */ export declare function pickAttrsWith(holdProps: { [x: string]: any; }, prefix: { [Symbol.match](string: string): RegExpMatchArray | null; }): any; /** * Checks if value is `null` or `undefined`. * @param {*} value * @return {Boolean} */ export declare function isNil(value: null): boolean; /** * Deep merge two objects. * @param target * @param ...sources * @reference https://stackoverflow.com/questions/27936772/how-to-deep-merge-instead-of-shallow-merge?page=1&tab=votes#tab-top */ export declare function deepMerge(target: { [x: string]: any; }, ...sources: any[]): any; /** * 组件是否为 Fucntion Component * @param {*} component 传入的组件 */ export declare function isFunctionComponent(component: { prototype: { isReactComponent: undefined; }; }): boolean; /** * 组件是否为 Class Component * @param {*} component 传入的组件 */ export declare function isClassComponent(component: { prototype: { isReactComponent: undefined; }; }): boolean; /** * 判断是否为 ReactFragment * @param {*} component 传入的组件 */ export declare function isReactFragment(component: React.ExoticComponent<{ children?: React.ReactNode; }> | any): boolean; /** * Creates an array of the own enumerable string keyed property values of object. * * @param {Object} obj * @returns {Array} * * @example * // returns [1, 2] * values({a: 1, b: 2}) */ export declare function values(obj: { [s: string]: unknown; } | ArrayLike<unknown> | any): any[]; /** * 过滤 undefined 类型的值 * @param {*} obj * @return {Object} */ export declare function filterUndefinedValue(object: any): any; /** * 从 obj 中去除 subObj * @param {*} obj * @param {*} subObj * @return {Object} */ export declare function stripObject(obj: any, subObj: any): any;