/* global jQuery, HTMLElement */

/**
 * @module input/other
 */

import * as empty from './empty'
import * as url from './url'
import * as json from './json'
import * as jquery from './jquery'
import * as html from './html'

export const ref = '@else'
export const parsers = {empty, url, json, jquery, html}
export const formats = {
  '@empty/text': {
    parse: empty.parse,
    parseType: {
      dataType: 'String',
      predicate: input => input === ''
    }
  },
  '@empty/whitespace+text': {
    parse: empty.parse,
    parseType: {
      dataType: 'String',
      predicate: /^\s+$/
    }
  },
  '@empty': {
    parse: empty.parse,
    parseType: {
      dataType: 'Primitive',
      predicate: input => input == null
    }
  },
  '@else/json': {
    parse: json.parse,
    parseType: {
      dataType: 'String',
      predicate: /^\s*(\{[\S\s]+\}|\[[\S\s]*\])\s*$/
    }
  },
  '@else/url': {
    parse: url.parse,
    parseAsync: url.parseAsync,
    parseType: {
      dataType: 'String',
      predicate: /^(https?:\/\/)?((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3})|localhost)(:\d+)?(\/[-a-z\d%_.~+:]*)*(\?[;&a-z\d%_.~+=-]*)?(#[-a-z\d_]*)?$/i
    }
  },
  '@else/jquery': {
    parse: jquery.parse,
    parseType: {
      dataType: 'ComplexObject',
      predicate: input => typeof jQuery !== 'undefined' && input instanceof jQuery
    }
  },
  '@else/html': {
    parse: html.parse,
    parseType: {
      dataType: 'ComplexObject',
      predicate: input => typeof HTMLElement !== 'undefined' && input instanceof HTMLElement
    }
  }
}

@@ -846,17 +846,17 @@
 %5C%7B%5B%5CS%5Cs%5D
-+
+*
 %5C%7D%7C%5C%5B%5B%5CS

Fix type predicate for empty objects