/** * validators 0.3.1 - https://github.com/insin/validators * MIT Licensed */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.validators=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o bestDoublecolonLen) { // This is the longest sequence so far bestDoublecolonLen = doublecolonLen bestDoublecolonStart = doublecolonStart } } else { doublecolonLen = 0 doublecolonStart = -1 } } // Compress the most suitable hextet if (bestDoublecolonLen > 1) { var bestDoublecolonEnd = bestDoublecolonStart + bestDoublecolonLen // For zeros at the end of the address if (bestDoublecolonEnd == hextets.length) { hextets.push('') } hextets.splice(bestDoublecolonStart, bestDoublecolonLen, '') // For zeros at the beginning of the address if (bestDoublecolonStart === 0) { hextets.unshift('') } } return hextets.join(':').toLowerCase() } /** * Sanitises IPv4 mapping in a expanded IPv6 address. * * This converts ::ffff:0a0a:0a0a to ::ffff:10.10.10.10. * If there is nothing to sanitise, returns an unchanged string. */ function _sanitiseIPv4Mapping(ipStr) { if (ipStr.toLowerCase().indexOf('0000:0000:0000:0000:0000:ffff:') !== 0) { // Not an ipv4 mapping return ipStr } var hextets = ipStr.split(':') if (hextets[hextets.length - 1].indexOf('.') != -1) { // Already sanitized return ipStr } var ipv4Address = [ parseInt(hextets[6].substring(0, 2), 16) , parseInt(hextets[6].substring(2, 4), 16) , parseInt(hextets[7].substring(0, 2), 16) , parseInt(hextets[7].substring(2, 4), 16) ].join('.') return hextets.slice(0, 6).join(':') + ':' + ipv4Address } /** * Unpacks an IPv4 address that was mapped in a compressed IPv6 address. * * This converts 0000:0000:0000:0000:0000:ffff:10.10.10.10 to 10.10.10.10. * If there is nothing to sanitize, returns null. */ function _unpackIPv4(ipStr) { if (ipStr.toLowerCase().indexOf('0000:0000:0000:0000:0000:ffff:') !== 0) { return null } var hextets = ipStr.split(':') return hextets.pop() } /** * Determines if we have a valid IPv6 address. */ function isValidIPv6Address(ipStr) { var validateIPv4Address = require('./validators').validateIPv4Address // We need to have at least one ':' if (ipStr.indexOf(':') == -1) { return false } // We can only have one '::' shortener if (String_count(ipStr, '::') > 1) { return false } // '::' should be encompassed by start, digits or end if (ipStr.indexOf(':::') != -1) { return false } // A single colon can neither start nor end an address if ((ipStr.charAt(0) == ':' && ipStr.charAt(1) != ':') || (ipStr.charAt(ipStr.length - 1) == ':' && ipStr.charAt(ipStr.length - 2) != ':')) { return false } // We can never have more than 7 ':' (1::2:3:4:5:6:7:8 is invalid) if (String_count(ipStr, ':') > 7) { return false } // If we have no concatenation, we need to have 8 fields with 7 ':' if (ipStr.indexOf('::') == -1 && String_count(ipStr, ':') != 7) { // We might have an IPv4 mapped address if (String_count(ipStr, '.') != 3) { return false } } ipStr = _explodeShorthandIPstring(ipStr) // Now that we have that all squared away, let's check that each of the // hextets are between 0x0 and 0xFFFF. var hextets = ipStr.split(':') for (var i = 0, l = hextets.length, hextet; i < l; i++) { hextet = hextets[i] if (String_count(hextet, '.') == 3) { // If we have an IPv4 mapped address, the IPv4 portion has to // be at the end of the IPv6 portion. if (ipStr.split(':').pop() != hextet) { return false } try { validateIPv4Address(hextet) } catch (e) { if (!(e instanceof ValidationError)) { throw e } return false } } else { if (!hexRE.test(hextet)) { return false } var intValue = parseInt(hextet, 16) if (isNaN(intValue) || intValue < 0x0 || intValue > 0xFFFF) { return false } } } return true } /** * Expands a shortened IPv6 address. */ function _explodeShorthandIPstring(ipStr) { if (!_isShortHand(ipStr)) { // We've already got a longhand ipStr return ipStr } var newIp = [] var hextets = ipStr.split('::') // If there is a ::, we need to expand it with zeroes to get to 8 hextets - // unless there is a dot in the last hextet, meaning we're doing v4-mapping var fillTo = (ipStr.split(':').pop().indexOf('.') != -1) ? 7 : 8 if (hextets.length > 1) { var sep = hextets[0].split(':').length + hextets[1].split(':').length newIp = hextets[0].split(':') for (var i = 0, l = fillTo - sep; i < l; i++) { newIp.push('0000') } newIp = newIp.concat(hextets[1].split(':')) } else { newIp = ipStr.split(':') } // Now need to make sure every hextet is 4 lower case characters. // If a hextet is < 4 characters, we've got missing leading 0's. var retIp = [] for (i = 0, l = newIp.length; i < l; i++) { retIp.push(zeroPadding(newIp[i], 4) + newIp[i].toLowerCase()) } return retIp.join(':') } /** * Determines if the address is shortened. */ function _isShortHand(ipStr) { if (String_count(ipStr, '::') == 1) { return true } var parts = ipStr.split(':') for (var i = 0, l = parts.length; i < l; i++) { if (parts[i].length < 4) { return true } } return false } // Utilities function zeroPadding(str, length) { if (str.length >= length) { return '' } return new Array(length - str.length + 1).join('0') } function String_count(str, subStr) { return str.split(subStr).length - 1 } module.exports = { cleanIPv6Address: cleanIPv6Address , isValidIPv6Address: isValidIPv6Address } },{"./errors":2,"./validators":4,"isomorph/object":9}],4:[function(require,module,exports){ 'use strict'; var Concur = require('Concur') var is = require('isomorph/is') var object = require('isomorph/object') var punycode = require('punycode') var url = require('isomorph/url') var errors = require('./errors') var ipv6 = require('./ipv6') var ValidationError = errors.ValidationError var isValidIPv6Address = ipv6.isValidIPv6Address var EMPTY_VALUES = [null, undefined, ''] function String_rsplit(str, sep, maxsplit) { var split = str.split(sep) return maxsplit ? [split.slice(0, -maxsplit).join(sep)].concat(split.slice(-maxsplit)) : split } /** * Validates that input matches a regular expression. */ var RegexValidator = Concur.extend({ constructor: function(kwargs) { if (!(this instanceof RegexValidator)) { return new RegexValidator(kwargs) } kwargs = object.extend({ regex: null, message: null, code: null, inverseMatch: null }, kwargs) if (kwargs.regex) { this.regex = kwargs.regex } if (kwargs.message) { this.message = kwargs.message } if (kwargs.code) { this.code = kwargs.code } if (kwargs.inverseMatch) { this.inverseMatch = kwargs.inverseMatch } // Compile the regex if it was not passed pre-compiled if (is.String(this.regex)) { this.regex = new RegExp(this.regex) } return this.__call__.bind(this) } , regex: '' , message: 'Enter a valid value.' , code: 'invalid' , inverseMatch: false , __call__: function(value) { if (this.inverseMatch === this.regex.test(''+value)) { throw ValidationError(this.message, {code: this.code}) } } }) /** * Validates that input looks like a valid URL. */ var URLValidator = RegexValidator.extend({ regex: new RegExp( '^(?:[a-z0-9\\.\\-]*)://' // schema is validated separately + '(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\\.)+(?:[A-Z]{2,6}\\.?|[A-Z0-9-]{2,}\\.?)|' // Domain... + 'localhost|' // localhost... + '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|' // ...or IPv4 + '\\[?[A-F0-9]*:[A-F0-9:]+\\]?)' // ...or IPv6 + '(?::\\d+)?' // Optional port + '(?:/?|[/?]\\S+)$' , 'i' ) , message: 'Enter a valid URL.' , schemes: ['http', 'https', 'ftp', 'ftps'] , constructor:function(kwargs) { if (!(this instanceof URLValidator)) { return new URLValidator(kwargs) } kwargs = object.extend({schemes: null}, kwargs) RegexValidator.call(this, kwargs) if (kwargs.schemes !== null) { this.schemes = kwargs.schemes } return this.__call__.bind(this) } , __call__: function(value) { value = ''+value // Check if the scheme is valid first var scheme = value.split('://')[0].toLowerCase() if (this.schemes.indexOf(scheme) === -1) { throw ValidationError(this.message, {code: this.code}) } // Check the full URL try { RegexValidator.prototype.__call__.call(this, value) } catch (e) { if (!(e instanceof ValidationError)) { throw e } // Trivial case failed - try for possible IDN domain var urlFields = url.parseUri(value) try { urlFields.host = punycode.toASCII(urlFields.host) } catch (unicodeError) { throw e } value = url.makeUri(urlFields) RegexValidator.prototype.__call__.call(this, value) } } }) /** Validates that input looks like a valid e-mail address. */ var EmailValidator = Concur.extend({ message: 'Enter a valid email address.' , code: 'invalid' , userRegex: new RegExp( "(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$" // Dot-atom + '|^"([\\001-\\010\\013\\014\\016-\\037!#-\\[\\]-\\177]|\\\\[\\001-\\011\\013\\014\\016-\\177])*"$)' // Quoted-string , 'i') , domainRegex: new RegExp( '^(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\\.)+(?:[A-Z]{2,6}|[A-Z0-9-]{2,})$' // Domain + '|^\\[(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\]$' // Literal form, ipv4 address (SMTP 4.1.3) , 'i') , domainWhitelist: ['localhost'] , constructor: function(kwargs) { if (!(this instanceof EmailValidator)) { return new EmailValidator(kwargs) } kwargs = object.extend({message: null, code: null, whitelist: null}, kwargs) if (kwargs.message !== null) { this.message = kwargs.message } if (kwargs.code !== null) { this.code = kwargs.code } if (kwargs.whitelist !== null) { this.domainWhitelist = kwargs.whitelist } return this.__call__.bind(this) } , __call__ : function(value) { value = ''+value if (!value || value.indexOf('@') == -1) { throw ValidationError(this.message, {code: this.code}) } var parts = String_rsplit(value, '@', 1) var userPart = parts[0] var domainPart = parts[1] if (!this.userRegex.test(userPart)) { throw ValidationError(this.message, {code: this.code}) } if (this.domainWhitelist.indexOf(domainPart) == -1 && !this.domainRegex.test(domainPart)) { // Try for possible IDN domain-part try { domainPart = punycode.toASCII(domainPart) if (this.domainRegex.test(domainPart)) { return } } catch (unicodeError) { // Pass through to throw the ValidationError } throw ValidationError(this.message, {code: this.code}) } } }) var validateEmail = EmailValidator() var SLUG_RE = /^[-a-zA-Z0-9_]+$/ /** Validates that input is a valid slug. */ var validateSlug = RegexValidator({ regex: SLUG_RE , message: 'Enter a valid "slug" consisting of letters, numbers, underscores or hyphens.' , code: 'invalid' }) var IPV4_RE = /^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/ /** Validates that input is a valid IPv4 address. */ var validateIPv4Address = RegexValidator({ regex: IPV4_RE , message: 'Enter a valid IPv4 address.' , code: 'invalid' }) /** Validates that input is a valid IPv6 address. */ function validateIPv6Address(value) { if (!isValidIPv6Address(value)) { throw ValidationError('Enter a valid IPv6 address.', {code: 'invalid'}) } } /** Validates that input is a valid IPv4 or IPv6 address. */ function validateIPv46Address(value) { try { validateIPv4Address(value) } catch (e) { if (!(e instanceof ValidationError)) { throw e } try { validateIPv6Address(value) } catch (e) { if (!(e instanceof ValidationError)) { throw e } throw ValidationError('Enter a valid IPv4 or IPv6 address.', {code: 'invalid'}) } } } var ipAddressValidatorLookup = { both: {validators: [validateIPv46Address], message: 'Enter a valid IPv4 or IPv6 address.'} , ipv4: {validators: [validateIPv4Address], message: 'Enter a valid IPv4 address.'} , ipv6: {validators: [validateIPv6Address], message: 'Enter a valid IPv6 address.'} } /** * Depending on the given parameters returns the appropriate validators for * a GenericIPAddressField. */ function ipAddressValidators(protocol, unpackIPv4) { if (protocol != 'both' && unpackIPv4) { throw new Error('You can only use unpackIPv4 if protocol is set to "both"') } protocol = protocol.toLowerCase() if (typeof ipAddressValidatorLookup[protocol] == 'undefined') { throw new Error('The protocol "' + protocol +'" is unknown') } return ipAddressValidatorLookup[protocol] } var COMMA_SEPARATED_INT_LIST_RE = /^[\d,]+$/ /** Validates that input is a comma-separated list of integers. */ var validateCommaSeparatedIntegerList = RegexValidator({ regex: COMMA_SEPARATED_INT_LIST_RE , message: 'Enter only digits separated by commas.' , code: 'invalid' }) /** * Base for validators which compare input against a given value. */ var BaseValidator = Concur.extend({ constructor: function(limitValue) { if (!(this instanceof BaseValidator)) { return new BaseValidator(limitValue) } this.limitValue = limitValue return this.__call__.bind(this) } , compare: function(a, b) { return a !== b } , clean: function(x) { return x } , message: 'Ensure this value is {limitValue} (it is {showValue}).' , code: 'limitValue' , __call__: function(value) { var cleaned = this.clean(value) var params = {limitValue: this.limitValue, showValue: cleaned} if (this.compare(cleaned, this.limitValue)) { throw ValidationError(this.message, {code: this.code, params: params}) } } }) /** * Validates that input is less than or equal to a given value. */ var MaxValueValidator = BaseValidator.extend({ constructor: function(limitValue) { if (!(this instanceof MaxValueValidator)) { return new MaxValueValidator(limitValue) } return BaseValidator.call(this, limitValue) } , compare: function(a, b) { return a > b } , message: 'Ensure this value is less than or equal to {limitValue}.' , code: 'maxValue' }) /** * Validates that input is greater than or equal to a given value. */ var MinValueValidator = BaseValidator.extend({ constructor: function(limitValue) { if (!(this instanceof MinValueValidator)) { return new MinValueValidator(limitValue) } return BaseValidator.call(this, limitValue) } , compare: function(a, b) { return a < b } , message: 'Ensure this value is greater than or equal to {limitValue}.' , code: 'minValue' }) /** * Validates that input is at least a given length. */ var MinLengthValidator = BaseValidator.extend({ constructor: function(limitValue) { if (!(this instanceof MinLengthValidator)) { return new MinLengthValidator(limitValue) } return BaseValidator.call(this, limitValue) } , compare: function(a, b) { return a < b } , clean: function(x) { return x.length } , message: 'Ensure this value has at least {limitValue} characters (it has {showValue}).' , code: 'minLength' }) /** * Validates that input is at most a given length. */ var MaxLengthValidator = BaseValidator.extend({ constructor: function(limitValue) { if (!(this instanceof MaxLengthValidator)) { return new MaxLengthValidator(limitValue) } return BaseValidator.call(this, limitValue) } , compare: function(a, b) { return a > b } , clean: function(x) { return x.length } , message: 'Ensure this value has at most {limitValue} characters (it has {showValue}).' , code: 'maxLength' }) module.exports = { EMPTY_VALUES: EMPTY_VALUES , RegexValidator: RegexValidator , URLValidator: URLValidator , EmailValidator: EmailValidator , validateEmail: validateEmail , validateSlug: validateSlug , validateIPv4Address: validateIPv4Address , validateIPv6Address: validateIPv6Address , validateIPv46Address: validateIPv46Address , ipAddressValidators: ipAddressValidators , validateCommaSeparatedIntegerList: validateCommaSeparatedIntegerList , BaseValidator: BaseValidator , MaxValueValidator: MaxValueValidator , MinValueValidator: MinValueValidator , MaxLengthValidator: MaxLengthValidator , MinLengthValidator: MinLengthValidator , ValidationError: ValidationError , ipv6: ipv6 } },{"./errors":2,"./ipv6":3,"Concur":5,"isomorph/is":8,"isomorph/object":9,"isomorph/url":10,"punycode":6}],5:[function(require,module,exports){ 'use strict'; var hasOwn = Object.prototype.hasOwnProperty var toString = Object.prototype.toString function type(obj) { return toString.call(obj).slice(8, -1).toLowerCase() } function inherits(childConstructor, parentConstructor) { var F = function() {} F.prototype = parentConstructor.prototype childConstructor.prototype = new F() childConstructor.prototype.constructor = childConstructor return childConstructor } function extend(dest, src) { for (var prop in src) { if (hasOwn.call(src, prop)) { dest[prop] = src[prop] } } return dest } /** * Mixes in properties from one object to another. If the source object is a * Function, its prototype is mixed in instead. */ function mixin(dest, src) { if (type(src) == 'function') { extend(dest, src.prototype) } else { extend(dest, src) } } /** * Applies mixins specified as a __mixins__ property on the given properties * object, returning an object containing the mixed in properties. */ function applyMixins(properties) { var mixins = properties.__mixins__ if (type(mixins) != 'array') { mixins = [mixins] } var mixedProperties = {} for (var i = 0, l = mixins.length; i < l; i++) { mixin(mixedProperties, mixins[i]) } delete properties.__mixins__ return extend(mixedProperties, properties) } /** * Inherits another constructor's prototype and sets its prototype and * constructor properties in one fell swoop. * * If a child constructor is not provided via prototypeProps.constructor, * a new constructor will be created. */ function inheritFrom(parentConstructor, childConstructor, prototypeProps, constructorProps) { // Create a child constructor if one wasn't given if (childConstructor == null) { childConstructor = function() { parentConstructor.apply(this, arguments) } } // Make sure the new prototype has the correct constructor set up prototypeProps.constructor = childConstructor // Base constructors should only have the properties they're defined with if (parentConstructor !== Concur) { // Inherit the parent's prototype inherits(childConstructor, parentConstructor) childConstructor.__super__ = parentConstructor.prototype } // Add prototype properties - this is why we took a copy of the child // constructor reference in extend() - if a .constructor had been passed as a // __mixins__ and overitten prototypeProps.constructor, these properties would // be getting set on the mixed-in constructor's prototype. extend(childConstructor.prototype, prototypeProps) // Add constructor properties extend(childConstructor, constructorProps) return childConstructor } /** * Namespace and dummy constructor for initial extension. */ var Concur = module.exports = function() {} /** * Details of a constructor's inheritance chain - Concur just facilitates sugar * so we don't include it in the initial chain. Arguably, Object.prototype could * go here, but it's just not that interesting. */ Concur.__mro__ = [] /** * Creates or uses a child constructor to inherit from the the call * context, which is expected to be a constructor. */ Concur.extend = function(prototypeProps, constructorProps) { // Ensure we have prop objects to work with prototypeProps = prototypeProps || {} constructorProps = constructorProps || {} // If the constructor being inherited from has a __meta__ function somewhere // in its prototype chain, call it to customise prototype and constructor // properties before they're used to set up the new constructor's prototype. if (typeof this.prototype.__meta__ != 'undefined') { this.prototype.__meta__(prototypeProps, constructorProps) } // Any child constructor passed in should take precedence - grab a reference // to it befoer we apply any mixins. var childConstructor = (hasOwn.call(prototypeProps, 'constructor') ? prototypeProps.constructor : null) // If any mixins are specified, mix them into the property objects if (hasOwn.call(prototypeProps, '__mixins__')) { prototypeProps = applyMixins(prototypeProps) } if (hasOwn.call(constructorProps, '__mixins__')) { constructorProps = applyMixins(constructorProps) } // Set up the new child constructor and its prototype childConstructor = inheritFrom(this, childConstructor, prototypeProps, constructorProps) // Pass on the extend function for extension in turn childConstructor.extend = this.extend // Expose the inheritance chain for programmatic access childConstructor.__mro__ = [childConstructor].concat(this.__mro__) return childConstructor } },{}],6:[function(require,module,exports){ (function (global){ /*! http://mths.be/punycode v1.2.4 by @mathias */ ;(function(root) { /** Detect free variables */ var freeExports = typeof exports == 'object' && exports; var freeModule = typeof module == 'object' && module && module.exports == freeExports && module; var freeGlobal = typeof global == 'object' && global; if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { root = freeGlobal; } /** * The `punycode` object. * @name punycode * @type Object */ var punycode, /** Highest positive signed 32-bit float value */ maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1 /** Bootstring parameters */ base = 36, tMin = 1, tMax = 26, skew = 38, damp = 700, initialBias = 72, initialN = 128, // 0x80 delimiter = '-', // '\x2D' /** Regular expressions */ regexPunycode = /^xn--/, regexNonASCII = /[^ -~]/, // unprintable ASCII chars + non-ASCII chars regexSeparators = /\x2E|\u3002|\uFF0E|\uFF61/g, // RFC 3490 separators /** Error messages */ errors = { 'overflow': 'Overflow: input needs wider integers to process', 'not-basic': 'Illegal input >= 0x80 (not a basic code point)', 'invalid-input': 'Invalid input' }, /** Convenience shortcuts */ baseMinusTMin = base - tMin, floor = Math.floor, stringFromCharCode = String.fromCharCode, /** Temporary variable */ key; /*--------------------------------------------------------------------------*/ /** * A generic error utility function. * @private * @param {String} type The error type. * @returns {Error} Throws a `RangeError` with the applicable error message. */ function error(type) { throw RangeError(errors[type]); } /** * A generic `Array#map` utility function. * @private * @param {Array} array The array to iterate over. * @param {Function} callback The function that gets called for every array * item. * @returns {Array} A new array of values returned by the callback function. */ function map(array, fn) { var length = array.length; while (length--) { array[length] = fn(array[length]); } return array; } /** * A simple `Array#map`-like wrapper to work with domain name strings. * @private * @param {String} domain The domain name. * @param {Function} callback The function that gets called for every * character. * @returns {Array} A new string of characters returned by the callback * function. */ function mapDomain(string, fn) { return map(string.split(regexSeparators), fn).join('.'); } /** * Creates an array containing the numeric code points of each Unicode * character in the string. While JavaScript uses UCS-2 internally, * this function will convert a pair of surrogate halves (each of which * UCS-2 exposes as separate characters) into a single code point, * matching UTF-16. * @see `punycode.ucs2.encode` * @see * @memberOf punycode.ucs2 * @name decode * @param {String} string The Unicode input string (UCS-2). * @returns {Array} The new array of code points. */ function ucs2decode(string) { var output = [], counter = 0, length = string.length, value, extra; while (counter < length) { value = string.charCodeAt(counter++); if (value >= 0xD800 && value <= 0xDBFF && counter < length) { // high surrogate, and there is a next character extra = string.charCodeAt(counter++); if ((extra & 0xFC00) == 0xDC00) { // low surrogate output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); } else { // unmatched surrogate; only append this code unit, in case the next // code unit is the high surrogate of a surrogate pair output.push(value); counter--; } } else { output.push(value); } } return output; } /** * Creates a string based on an array of numeric code points. * @see `punycode.ucs2.decode` * @memberOf punycode.ucs2 * @name encode * @param {Array} codePoints The array of numeric code points. * @returns {String} The new Unicode string (UCS-2). */ function ucs2encode(array) { return map(array, function(value) { var output = ''; if (value > 0xFFFF) { value -= 0x10000; output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); value = 0xDC00 | value & 0x3FF; } output += stringFromCharCode(value); return output; }).join(''); } /** * Converts a basic code point into a digit/integer. * @see `digitToBasic()` * @private * @param {Number} codePoint The basic numeric code point value. * @returns {Number} The numeric value of a basic code point (for use in * representing integers) in the range `0` to `base - 1`, or `base` if * the code point does not represent a value. */ function basicToDigit(codePoint) { if (codePoint - 48 < 10) { return codePoint - 22; } if (codePoint - 65 < 26) { return codePoint - 65; } if (codePoint - 97 < 26) { return codePoint - 97; } return base; } /** * Converts a digit/integer into a basic code point. * @see `basicToDigit()` * @private * @param {Number} digit The numeric value of a basic code point. * @returns {Number} The basic code point whose value (when used for * representing integers) is `digit`, which needs to be in the range * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is * used; else, the lowercase form is used. The behavior is undefined * if `flag` is non-zero and `digit` has no uppercase form. */ function digitToBasic(digit, flag) { // 0..25 map to ASCII a..z or A..Z // 26..35 map to ASCII 0..9 return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); } /** * Bias adaptation function as per section 3.4 of RFC 3492. * http://tools.ietf.org/html/rfc3492#section-3.4 * @private */ function adapt(delta, numPoints, firstTime) { var k = 0; delta = firstTime ? floor(delta / damp) : delta >> 1; delta += floor(delta / numPoints); for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) { delta = floor(delta / baseMinusTMin); } return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); } /** * Converts a Punycode string of ASCII-only symbols to a string of Unicode * symbols. * @memberOf punycode * @param {String} input The Punycode string of ASCII-only symbols. * @returns {String} The resulting string of Unicode symbols. */ function decode(input) { // Don't use UCS-2 var output = [], inputLength = input.length, out, i = 0, n = initialN, bias = initialBias, basic, j, index, oldi, w, k, digit, t, /** Cached calculation results */ baseMinusT; // Handle the basic code points: let `basic` be the number of input code // points before the last delimiter, or `0` if there is none, then copy // the first basic code points to the output. basic = input.lastIndexOf(delimiter); if (basic < 0) { basic = 0; } for (j = 0; j < basic; ++j) { // if it's not a basic code point if (input.charCodeAt(j) >= 0x80) { error('not-basic'); } output.push(input.charCodeAt(j)); } // Main decoding loop: start just after the last delimiter if any basic code // points were copied; start at the beginning otherwise. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) { // `index` is the index of the next character to be consumed. // Decode a generalized variable-length integer into `delta`, // which gets added to `i`. The overflow checking is easier // if we increase `i` as we go, then subtract off its starting // value at the end to obtain `delta`. for (oldi = i, w = 1, k = base; /* no condition */; k += base) { if (index >= inputLength) { error('invalid-input'); } digit = basicToDigit(input.charCodeAt(index++)); if (digit >= base || digit > floor((maxInt - i) / w)) { error('overflow'); } i += digit * w; t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); if (digit < t) { break; } baseMinusT = base - t; if (w > floor(maxInt / baseMinusT)) { error('overflow'); } w *= baseMinusT; } out = output.length + 1; bias = adapt(i - oldi, out, oldi == 0); // `i` was supposed to wrap around from `out` to `0`, // incrementing `n` each time, so we'll fix that now: if (floor(i / out) > maxInt - n) { error('overflow'); } n += floor(i / out); i %= out; // Insert `n` at position `i` of the output output.splice(i++, 0, n); } return ucs2encode(output); } /** * Converts a string of Unicode symbols to a Punycode string of ASCII-only * symbols. * @memberOf punycode * @param {String} input The string of Unicode symbols. * @returns {String} The resulting Punycode string of ASCII-only symbols. */ function encode(input) { var n, delta, handledCPCount, basicLength, bias, j, m, q, k, t, currentValue, output = [], /** `inputLength` will hold the number of code points in `input`. */ inputLength, /** Cached calculation results */ handledCPCountPlusOne, baseMinusT, qMinusT; // Convert the input in UCS-2 to Unicode input = ucs2decode(input); // Cache the length inputLength = input.length; // Initialize the state n = initialN; delta = 0; bias = initialBias; // Handle the basic code points for (j = 0; j < inputLength; ++j) { currentValue = input[j]; if (currentValue < 0x80) { output.push(stringFromCharCode(currentValue)); } } handledCPCount = basicLength = output.length; // `handledCPCount` is the number of code points that have been handled; // `basicLength` is the number of basic code points. // Finish the basic string - if it is not empty - with a delimiter if (basicLength) { output.push(delimiter); } // Main encoding loop: while (handledCPCount < inputLength) { // All non-basic code points < n have been handled already. Find the next // larger one: for (m = maxInt, j = 0; j < inputLength; ++j) { currentValue = input[j]; if (currentValue >= n && currentValue < m) { m = currentValue; } } // Increase `delta` enough to advance the decoder's state to , // but guard against overflow handledCPCountPlusOne = handledCPCount + 1; if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { error('overflow'); } delta += (m - n) * handledCPCountPlusOne; n = m; for (j = 0; j < inputLength; ++j) { currentValue = input[j]; if (currentValue < n && ++delta > maxInt) { error('overflow'); } if (currentValue == n) { // Represent delta as a generalized variable-length integer for (q = delta, k = base; /* no condition */; k += base) { t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias); if (q < t) { break; } qMinusT = q - t; baseMinusT = base - t; output.push( stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)) ); q = floor(qMinusT / baseMinusT); } output.push(stringFromCharCode(digitToBasic(q, 0))); bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength); delta = 0; ++handledCPCount; } } ++delta; ++n; } return output.join(''); } /** * Converts a Punycode string representing a domain name to Unicode. Only the * Punycoded parts of the domain name will be converted, i.e. it doesn't * matter if you call it on a string that has already been converted to * Unicode. * @memberOf punycode * @param {String} domain The Punycode domain name to convert to Unicode. * @returns {String} The Unicode representation of the given Punycode * string. */ function toUnicode(domain) { return mapDomain(domain, function(string) { return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string; }); } /** * Converts a Unicode string representing a domain name to Punycode. Only the * non-ASCII parts of the domain name will be converted, i.e. it doesn't * matter if you call it with a domain that's already in ASCII. * @memberOf punycode * @param {String} domain The domain name to convert, as a Unicode string. * @returns {String} The Punycode representation of the given domain name. */ function toASCII(domain) { return mapDomain(domain, function(string) { return regexNonASCII.test(string) ? 'xn--' + encode(string) : string; }); } /*--------------------------------------------------------------------------*/ /** Define the public API */ punycode = { /** * A string representing the current Punycode.js version number. * @memberOf punycode * @type String */ 'version': '1.2.4', /** * An object of methods to convert from JavaScript's internal character * representation (UCS-2) to Unicode code points, and back. * @see * @memberOf punycode * @type Object */ 'ucs2': { 'decode': ucs2decode, 'encode': ucs2encode }, 'decode': decode, 'encode': encode, 'toASCII': toASCII, 'toUnicode': toUnicode }; /** Expose `punycode` */ // Some AMD build optimizers, like r.js, check for specific condition patterns // like the following: if ( typeof define == 'function' && typeof define.amd == 'object' && define.amd ) { define('punycode', function() { return punycode; }); } else if (freeExports && !freeExports.nodeType) { if (freeModule) { // in Node.js or RingoJS v0.8.0+ freeModule.exports = punycode; } else { // in Narwhal or RingoJS v0.7.0- for (key in punycode) { punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]); } } } else { // in Rhino or a web browser root.punycode = punycode; } }(this)); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],7:[function(require,module,exports){ 'use strict'; var slice = Array.prototype.slice , formatRegExp = /%[%s]/g , formatObjRegExp = /({{?)(\w+)}/g /** * Replaces %s placeholders in a string with positional arguments. */ function format(s) { return formatArr(s, slice.call(arguments, 1)) } /** * Replaces %s placeholders in a string with array contents. */ function formatArr(s, a) { var i = 0 return s.replace(formatRegExp, function(m) { return m == '%%' ? '%' : a[i++] }) } /** * Replaces {propertyName} placeholders in a string with object properties. */ function formatObj(s, o) { return s.replace(formatObjRegExp, function(m, b, p) { return b.length == 2 ? m.slice(1) : o[p] }) } var units = 'kMGTPEZY' , stripDecimals = /\.00$|0$/ /** * Formats bytes as a file size with the appropriately scaled units. */ function fileSize(bytes, threshold) { threshold = Math.min(threshold || 768, 1024) var i = -1 , unit = 'bytes' , size = bytes while (size > threshold && i < units.length) { size = size / 1024 i++ } if (i > -1) { unit = units.charAt(i) + 'B' } return size.toFixed(2).replace(stripDecimals, '') + ' ' + unit } module.exports = { format: format , formatArr: formatArr , formatObj: formatObj , fileSize: fileSize } },{}],8:[function(require,module,exports){ 'use strict'; var toString = Object.prototype.toString // Type checks function isArray(o) { return toString.call(o) == '[object Array]' } function isBoolean(o) { return toString.call(o) == '[object Boolean]' } function isDate(o) { return toString.call(o) == '[object Date]' } function isError(o) { return toString.call(o) == '[object Error]' } function isFunction(o) { return toString.call(o) == '[object Function]' } function isNumber(o) { return toString.call(o) == '[object Number]' } function isObject(o) { return toString.call(o) == '[object Object]' } function isRegExp(o) { return toString.call(o) == '[object RegExp]' } function isString(o) { return toString.call(o) == '[object String]' } // Content checks function isEmpty(o) { /* jshint ignore:start */ for (var prop in o) { return false } /* jshint ignore:end */ return true } module.exports = { Array: isArray , Boolean: isBoolean , Date: isDate , Empty: isEmpty , Error: isError , Function: isFunction , NaN: isNaN , Number: isNumber , Object: isObject , RegExp: isRegExp , String: isString } },{}],9:[function(require,module,exports){ 'use strict'; /** * Wraps Object.prototype.hasOwnProperty() so it can be called with an object * and property name. */ var hasOwn = (function() { var hasOwnProperty = Object.prototype.hasOwnProperty return function(obj, prop) { return hasOwnProperty.call(obj, prop) } })() /** * Returns the type of an object as a lowercase string. */ var type = (function() { var toString = Object.prototype.toString return function(obj) { return toString.call(obj).slice(8, -1).toLowerCase() } })() /** * Copies own properties from any given objects to a destination object. */ function extend(dest) { for (var i = 1, l = arguments.length, src; i < l; i++) { src = arguments[i] if (src) { for (var prop in src) { if (hasOwn(src, prop)) { dest[prop] = src[prop] } } } } return dest } /** * Makes a constructor inherit another constructor's prototype without * having to actually use the constructor. */ function inherits(childConstructor, parentConstructor) { var F = function() {} F.prototype = parentConstructor.prototype childConstructor.prototype = new F() childConstructor.prototype.constructor = childConstructor return childConstructor } /** * Creates an Array of [property, value] pairs from an Object. */ function items(obj) { var items_ = [] for (var prop in obj) { if (hasOwn(obj, prop)) { items_.push([prop, obj[prop]]) } } return items_ } /** * Creates an Object from an Array of [property, value] pairs. */ function fromItems(items) { var obj = {} for (var i = 0, l = items.length, item; i < l; i++) { item = items[i] obj[item[0]] = item[1] } return obj } /** * Creates a lookup Object from an Array, coercing each item to a String. */ function lookup(arr) { var obj = {} for (var i = 0, l = arr.length; i < l; i++) { obj[''+arr[i]] = true } return obj } /** * If the given object has the given property, returns its value, otherwise * returns the given default value. */ function get(obj, prop, defaultValue) { return (hasOwn(obj, prop) ? obj[prop] : defaultValue) } /** * Deletes and returns an own property from an object, optionally returning a * default value if the object didn't have theproperty. * @throws if given an object which is null (or undefined), or if the property * doesn't exist and there was no defaultValue given. */ function pop(obj, prop, defaultValue) { if (obj == null) { throw new Error('pop was given ' + obj) } if (hasOwn(obj, prop)) { var value = obj[prop] delete obj[prop] return value } else if (arguments.length == 2) { throw new Error("pop was given an object which didn't have an own '" + prop + "' property, without a default value to return") } return defaultValue } /** * If the prop is in the object, return its value. If not, set the prop to * defaultValue and return defaultValue. */ function setDefault(obj, prop, defaultValue) { if (obj == null) { throw new Error('setDefault was given ' + obj) } defaultValue = defaultValue || null if (hasOwn(obj, prop)) { return obj[prop] } else { obj[prop] = defaultValue return defaultValue } } module.exports = { hasOwn: hasOwn , type: type , extend: extend , inherits: inherits , items: items , fromItems: fromItems , lookup: lookup , get: get , pop: pop , setDefault: setDefault } },{}],10:[function(require,module,exports){ 'use strict'; // parseUri 1.2.2 // (c) Steven Levithan // MIT License function parseUri (str) { var o = parseUri.options , m = o.parser[o.strictMode ? "strict" : "loose"].exec(str) , uri = {} , i = 14 while (i--) { uri[o.key[i]] = m[i] || "" } uri[o.q.name] = {}; uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { if ($1) { uri[o.q.name][$1] = $2 } }) return uri } parseUri.options = { strictMode: false , key: ['source','protocol','authority','userInfo','user','password','host','port','relative','path','directory','file','query','anchor'] , q: { name: 'queryKey' , parser: /(?:^|&)([^&=]*)=?([^&]*)/g } , parser: { strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/ , loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ } } // makeURI 1.2.2 - create a URI from an object specification; compatible with // parseURI (http://blog.stevenlevithan.com/archives/parseuri) // (c) Niall Smart // MIT License function makeUri(u) { var uri = '' if (u.protocol) { uri += u.protocol + '://' } if (u.user) { uri += u.user } if (u.password) { uri += ':' + u.password } if (u.user || u.password) { uri += '@' } if (u.host) { uri += u.host } if (u.port) { uri += ':' + u.port } if (u.path) { uri += u.path } var qk = u.queryKey var qs = [] for (var k in qk) { if (!qk.hasOwnProperty(k)) { continue } var v = encodeURIComponent(qk[k]) k = encodeURIComponent(k) if (v) { qs.push(k + '=' + v) } else { qs.push(k) } } if (qs.length > 0) { uri += '?' + qs.join('&') } if (u.anchor) { uri += '#' + u.anchor } return uri } module.exports = { parseUri: parseUri , makeUri: makeUri } },{}]},{},[1])(1) });