all files / utils/ prepareProps.js

100% Statements 6/6
100% Branches 2/2
100% Functions 2/2
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22                                
// TODO: write tests/flow annotations
import R from 'ramda';
 
import { INPUT_PROPS, META_PROPS, IGNORE_PROPS } from './consts';
 
const maybeCheckProps = all => {
  if (typeof all.value === 'boolean') {
    return R.merge(all, { checked: all.value });
  }
  return all;
};
 
const separateProps = all => ({
  input: R.pick(INPUT_PROPS, all),
  meta: R.pick(META_PROPS, all),
  custom: R.omit(IGNORE_PROPS, all),
});
 
// Order matters!
// Separate always last
export default R.compose(separateProps, maybeCheckProps);