Generic selector library in Typescript
Using npm:
npm i --save selector
Using yarn:
yarn add --dev selector
Here are examples of how you can use selector
.
Return a selector helper
const data = ['John']
const getFirstItemSelector = createSelector(0)
const item = getFirstItemSelector(data)
console.log(item) // It'll display 'John'
const data = { item: { name: 'Television', isActive: true } }
const selector = createSelector('item', 'name')
const itemName = selector(data)
console.log(itemName) // It'll display 'Television'
const data = {
items: [
{
name: 'Television',
isActive: false,
},
{
name: 'Sofa',
isActive: true,
},
{
name: 'Door',
isActive: true,
},
],
}
const firstActiveItemSelector = createSelector('items', (items: IItem[]) =>
items.find((item: IItem) => item.isActive)
)
const item = firstActiveItemSelector(data)
console.log(item) // It'll display '{ "isActive": true, "name": "Sofa" }'
const path = 'items.0.name'
const data = { items: [{ name: 'Television', isActive: true }] }
const selector = createSelector(...path.split('.'))
const itemName = selector(data)
console.log(itemName) // It'll display 'Television'
Tests are written with jest
Using jest:
yarn run test
Deployment is done with Travis.
- TSDX - TSDX
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Arnaud Zheng - Initial work - arnaud-zg
See also the list of contributors who participated in this project.
Give a ⭐️ if this project helped you!
This project is licensed under the MIT License - see the LICENSE.md file for details