jz-tool-lib
Version:
项目常用公共方法集合
54 lines (53 loc) • 2.06 kB
TypeScript
type DifferentList = List<Array<BaseType>>;
type DifferentListType = List<'complex' | 'single'>;
type IdStr = List<string>;
/**
* @description 获取两个数组相同的值
* @param sourceList 源数组
* @param targetList 目标数组
* @param listType 源数组和目标数组类型 complex/single
* @param idStr 数组id字段
* @returns 返回相同的值
* */
export declare function arraySomeValue(sourceList: DifferentList, targetList: DifferentList, listType?: DifferentListType, idStr?: IdStr): DifferentList;
/**
* @description 获取两个数组不同的值
* @param sourceList 源数组
* @param targetList 目标数组
* @param listType 源数组和目标数组类型 complex/single
* @param idStr 数组id字段
* @returns 返回不同的值
* */
export declare function arrayDiffValue(sourceList: DifferentList, targetList: DifferentList, listType?: DifferentListType, idStr?: IdStr): DifferentList;
/**
* @description 数组长度是否为空
* @param list
* @returns boolean
* @example arrayHasValue([]) => false
*/
export declare function arrayHasValue(list: unknown[]): boolean;
/**
* @description 数组去除重复
* @param list
* @param propKey 对象匹配的属性
* @returns T[]
* @example arrayUnique([{a:1,b:2},{a:1,b:2},{a:2,b:2}]) => [{a:1,b:2},{a:2,b:2}]
* */
export declare function arrayUnique<T extends string | number | boolean | object | symbol>(list: T[], propKey?: keyof T): T[];
/**
* @description 匹配数组中的某个值
* @param list 数组:简单数组、对象数组
* @param matchData 匹配的值
* @param propKey 对象匹配的属性
*/
export declare function arrayMatchValue<T>(list: T[], matchData: Partial<{
[propName in keyof T]: any;
}>, propKey?: keyof T): T | undefined;
/**
* @description 数组排序
* @param list
* @param sortKey
*/
type SortKeyType<T> = T extends number | string ? never : Extract<keyof T, string>;
export declare function arraySort<T extends number | string | Record<string, any>>(list: Array<T>, sortKey?: SortKeyType<T>): T[];
export {};