Skip to content

Commit

Permalink
docs: improve the shake documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Dec 19, 2024
1 parent 1581801 commit 8048797
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions docs/object/shake.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,35 @@ since: 12.1.0

### Usage

A bit like `_.sift` but for objects. By default, it will return a new object with all the undefined attributes removed. You can pass a second function argument to remove any attributes by a custom condition.
Returns a new object without the properties that are `undefined`. Note that non-enumerable keys are never shaken out.

```ts
import * as _ from 'radashi'

const ra = {
mode: 'god',
greek: false,
limit: undefined,
}
const options = _.shake({
mode: 'party',
volume: undefined,
dancing: false,
snacks: null,
})
// => { mode: 'party', dancing: false, snacks: null }
```

#### Custom Condition

If you pass a function as the second argument, only the properties that return `false` will be included in the result.

```ts
import * as _ from 'radashi'

_.shake(ra) // => { mode, greek }
_.shake(ra, a => !a) // => { mode }
const options = _.shake(
{
mode: 'party',
volume: undefined,
dancing: false,
snacks: null,
},
value => !value,
)
// => { mode: 'party' }
```

0 comments on commit 8048797

Please sign in to comment.