{"size": 1759, "ext": "js", "max_stars_repo_path": "frontend/selectors/addressBook.js", "max_stars_repo_name": "shopgate/ext-user", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend/selectors/addressBook.js", "max_issues_repo_name": "shopgate/ext-user", "max_issues_repo_issues_event_min_datetime": "2018-04-23T16:43:50.000Z", "max_issues_repo_issues_event_max_datetime": "2018-08-08T14:40:56.000Z", "max_forks_repo_path": "frontend/selectors/addressBook.js", "max_forks_repo_name": "shopgate/ext-user", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 27.9206349206, "max_line_length": 87, "alphanum_fraction": 0.7305287095}
import { createSelector } from 'reselect';

const statePrefix = '@shopgate/user/UserReducers';

/**
 * Gets user.data.addresses from the redux store.
 * @param {Object} state The application state.
 * @return {UserAddress[]|null}
 */
export const getUserAddresses = createSelector(
  state => state.extensions[statePrefix].addressBook.addresses,
  addresses => addresses
);

/**
 * Get count of user.data.addresses from the redux store.
 * @param {Object} state The application state.
 * @return {number}
 */
export const getUserAddressesCount = createSelector(
  state => state.extensions[statePrefix].addressBook.addresses,
  (addresses = []) => addresses.length
);

/**
 * Gets user.data.addresses.default from the redux store.
 * @param {Object} state The application state.
 * @returns {Object|null}
 */
export const getUserDefaultAddresses = createSelector(
  state => state.extensions[statePrefix].addressBook.default,
  defaults => defaults
);

/**
 * Get user address selector to fetch address by id
 * @example
 * getUserAddressIdSelector(state)(addressId)
 *
 * @param {Object} state The application state.
 * @return {function(string): UserAddress|undefined}
 */
export const getUserAddressIdSelector = createSelector(
  getUserAddresses,
  addresses => addressId => addresses.find(address => address.id === addressId)
);

/**
 * Selector for address book in progress actions
 * @param {Object} state The application state.
 * @return {boolean}
 */
export const isBusy = state => state.extensions[statePrefix].addressBook.busy || false;

/**
 * Validation errors
 * @param {Object} state The application state.
 * @return {Object[]}
 */
export const getValidationErrors = state => (
  state.extensions[statePrefix].addressBook.validationErrors
);
