0.0.2 • Published 5 years ago

@bryandbor/selector-utils v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@bryandbor/selector-utils

Utilities for selectors

NPM JavaScript Style Guide Package Size Weekly downloads

Install

npm install --save @bryandbor/selector-utils

Usage

The use of the reselect library is suggested, but not required.

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