All files / react-dom index.js

100% Statements 9/9
100% Branches 2/2
100% Functions 3/3
100% Lines 8/8
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 35 36 37 38 39 40 41 42 43 441x 1x 1x   1x                                         3x                           1x 3x 3x    
const _ = require('lodash/fp');
const validAttributes = require('./validAttributes');
const mapToObject = require('./map-to-object');
 
exports.createComponentPath = require.resolve('./dist/create-css-component');
 
/**
 * @typedef {Object} PreprocessOptions
 * @property {Object} options
 * @property {string} options.selector
 * @property {string} options.className
 * @property {Attribute[]} options.attributes
 * @property {Attr[]} options.attrs
 * @property {string} base
 */
 
/**
 * @typedef {PreprocessOptions} CreateComponentOptions
 * @property {Object<boolean>} invalidProps
 */
 
/**
 * @param {PreprocessOptions} options
 * @return {CreateComponentOptions}
 */
exports.preprocess = ({ selector, className, attributes = [], attrs = [], base }) => ({
  selector,
  className,
  attributes,
  attrs,
  base,
  invalidProps: flagInvalidProps(attributes, attrs),
});
 
/**
 * @param {Attributes[]} attributes
 * @param {Attr[]} attrs
 * @returns {Object<boolean>}
 */
const flagInvalidProps = _.flow([
  (attributes, attrs) => _.flattenDeep([_.map('name', attributes), _.map('attributes', attrs)]),
  mapToObject(prop => !validAttributes(prop)),
]);