-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
26 lines (23 loc) · 759 Bytes
/
utils.js
File metadata and controls
26 lines (23 loc) · 759 Bytes
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
import get from 'lodash.get';
/**
* Returns an object with a state slice if exist and a prop indicating whether
* the state is sliced or not.
* @param {object} state The contextseed state
* @param {string|array} key The state slice key to return
*/
export const getStateSlice = (state, key) => {
const hasStateKey = key || key === '';
return {
isSliced: hasStateKey,
// If there's a key that's the slice, otherwise it's the whole state.
// Empty array or string will look at the root
stateSlice: hasStateKey && key.length ? get(state, key) : state
};
};
/**
* Checks if the given input is a function.
*
* @param {function} fn The function to check
* @returns Boolean
*/
export const isFn = (fn) => typeof fn === 'function';