-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Conan edited this page Oct 4, 2022
·
13 revisions
import { sift, byPattern } from 'sift-r'
pattern
means either a predicate
function, or something that the match-iz when()
method supports, because sift
uses match-iz
internally.
-
When working with pojos, the pattern is applied to each key/value pair.
-
When working with arrays, the pattern is applied to each item in the array.
-
When working with
Map
's, the pattern is applied to the value only, not the key.
- sift({ key: [pattern, value], key: [pattern, value], ... })
- sift({ key: value }, { key: pattern })
- sift({ key: value }, pattern)
- sift({ key: value }, [pattern, pattern, ...])
- sift([[pattern, value], [pattern, value], ...])
- sift([value, value], [pattern, pattern])
- sift([value, value], pattern)
- sift([value, value], ...patterns)
- sift(Set | Map | iterable, ...patterns)
You can find more examples in the test suite.
$ pnpm i sift-r
Supports import
/require
for ESM/CJS:
// ESM
import { sift, byPattern } from 'sift-r'
// CJS
const { sift, byPattern } = require('sift-r')
Browser/UMD version here:
<script src="https://unpkg.com/sift-r/dist/browser/sift-r.browser.js"></script>
<script>
const { sift, byPattern } = siftr
</script>
sift-r
📥 | on npm | docs home | top of page