function addDirective (type) {
  return function (name, directive) {
    if (typeof name === 'function') {
      directive = name
    }

    if (typeof directive !== 'function') {
      throw new TypeError('Directive must be a function')
    }

    name = typeof name === 'string'
      ? name
      : directive.name

    if (!name) {
      throw new TypeError('Directive function must have a name')
    }

    directive.$name = name
    Toxy[type][name] = directive

    return Toxy
  }
}