@bryandbor/selector-utils
Version:
Utilities for selectors
74 lines (57 loc) • 1.91 kB
Markdown
# @bryandbor/selector-utils
> Utilities for selectors
[](https://www.npmjs.com/package/@bryandbor/selector-utils) [](https://standardjs.com) [](https://packagephobia.now.sh/result?p=%40bryandbor%2Fselector-utils) [](https://www.npmjs.com/package/@bryandbor/selector-utils)
## Install
```bash
npm install --save @bryandbor/selector-utils
```
## Usage
_The use of the [reselect](https://github.com/reduxjs/reselect) library is suggested, but not required._
```js
import {createSelector} from 'reselect';
import {
trueIfAllAreTrue,
trueIfAnyAreTrue,
not,
sum,
getIsGreaterThanOrEqual,
getIsEqual,
joinStrings,
// There are many more utils exported from this library, this is just a subset used for demo purposes
} from '@bryandbor/selector-utils';
export const getNumberOfFriends = createSelector(
getFriendsFromSchool,
getFriendsFromWork,
getFamilyFriends,
sum,
);
export const getHasLotsOfFriends = createSelector(
getNumberOfFriends,
getIsGreaterThanOrEqual(25)
);
export const getIsFirstNameSilly = createSelector(
getFirstName,
getIsEqual('Bozo')
);
export const getIsLastNameGreat = createSelector(
getLastName,
getIsEqual('Powers')
);
export const getIsNameCool = createSelector(
not(getIsFirstNameSilly),
getIsLastNameGreat,
trueIfAnyAreTrue
);
export const getIsCoolPerson = createSelector(
getHasLotsOfFriends,
getIsNameCool,
trueIfAllAreTrue
);
export const getCoolPersonGreeting = createSelector(
'Hello,'
getFirstName,
'you are officially cool!'
);
```
## License
MIT © [bryandbor](https://github.com/bryandbor)