all files / src/ mapChildren.js

100% Statements 13/13
100% Branches 4/4
100% Functions 4/4
100% Lines 13/13
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      22×             15×     22×                
'use strict'
 
var React = require('react')
 
function mapChild (child, i, depth) {
  if (child.tagName) {
    return React.createElement(
      child.tagName,
      assign({key: 'lo-' + depth + '-' + i}, child.properties),
      child.children && child.children.map(mapWithDepth(depth + 1))
    )
  }
 
  return child.value
}
 
function mapWithDepth (depth) {
  return function mapChildrenWithDepth (child, i) {
    return mapChild(child, i, depth)
  }
}
 
function assign (dst, src) {
  for (var key in src) {
    dst[key] = src[key]
  }
 
  return dst
}
 
exports.depth = mapWithDepth