separate
Split an object into picked and omitted parts by the given keys, returning both in one call, ideal for separating sensitive fields.
Usage
The separate function splits an object into two parts by the specified keys.
import { separate } from '@movk/core'
const user = {
id: 1,
name: 'John',
email: 'john@example.com',
password: 'secret',
role: 'admin'
}
const { picked, omitted } = separate(user, ['id', 'name'])
console.log(picked) // { id: 1, name: 'John' }
console.log(omitted) // { email: 'john@example.com', password: 'secret', role: 'admin' }
// Separate sensitive information
const { picked: publicData, omitted: privateData } = separate(user, ['id', 'name', 'email'])
API
separate(obj, keys)
Splits an object into two parts by the specified keys.
Parameters
obj
T required
The source object.
keys
K[] required
Array of keys to separate.
Returns
returns
{ picked: PickByKey<T, K>, omitted: OmitByKey<T, K> }
An object containing both
picked and omitted sub-objects.Changelog
No recent changes