用法
separateMany 函数用于将对象按多分组键集合进行分离。
import { separateMany } from '@movk/core'
const options = { id: 1, name: 'John', email: 'a@b.com', role: 'admin' }
const { a, b, others } = separateMany(options, { a: ['id'], b: ['name'] as const })
// a: { id: 1 }
// b: { name: 'John' }
// others: { email: 'a@b.com', role: 'admin' }
API
separateMany(obj, groups)
将对象按多分组键集合进行分离。
参数
obj
T required
源对象。
groups
M required
分组映射,如
{ a: ['x', 'y'], b: ['z'] }。返回值
返回值
{ [P in keyof M]: PickByKey<T, M[P][number]> } & { others: OmitByKey<T, M[keyof M][number]> }
包含每个分组的子对象以及
others(其余未被分组捕获的键)。Changelog
No recent changes