separateManyseparateMany 是一个更强大的分离函数,它可以根据多个分组规则将对象分离成多个部分,以及一个包含所有未分组属性的 others 对象。
import { separateMany } from '@movk/core'
const options = {
id: 1,
name: 'Product',
price: 99.9,
inStock: true,
style: 'modern',
color: 'blue'
}
const { meta, data, others } = separateMany(options, {
meta: ['id', 'inStock'],
data: ['name', 'price']
})
// meta => { id: 1, inStock: true }
// data => { name: 'Product', price: 99.9 }
// others => { style: 'modern', color: 'blue' }
separateMany<T extends object, M extends Record<string, readonly (keyof T)[]>>(obj: T, groups: M): { [P in keyof M]: Pick<T, M[P][number]> } & { others: Omit<T, M[keyof M][number]> }
others 对象的聚合对象。