# All files / hash selectors.js

100% Statements 15/15
100% Branches 2/2
100% Functions 6/6
100% Lines 14/14

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34

    3x
    10x

    3x
    3x
    3x

    3x
    2x
    2x

    3x
    3x

    3x
    2x

    3x
    2x

     import curry from 'lodash/curry'
    import { get } from 'dot-prop-immutable'

    const EMPTY_OBJECT = {}
    const root = state => state.hash

    /**
     * Returns a single property from a hash
     * @param {Object} state Redux state
     * @param {String} hash  Hash key
     * @param {String} key   Key string or key path (xx.yy.zzz)
     */
    export const hget = curry(function hget(hash, key, state) {
      const data = root(state)
      return get(data, [hash, key].join('.'))
    })

    export const hgetAll = curry(function(hash, state) {
      const data = root(state)
      return get(data, hash)
    })

    export const hkeys = curry(function hkeys(hash, state) {
      return Object.keys(get(root(state), hash) || EMPTY_OBJECT)
    })

    export const hlen = curry(function hlen(hash, state) {
      return hkeys(hash, state).length
    })

    export const hexists = curry(function hexists(hash, key, state) {
      return Boolean(get(root(state), [hash, key].join('.')))
    })