From af9d77b53bb7aa75020669805bb04f8bf16525ae Mon Sep 17 00:00:00 2001 From: Francesc Busquets Date: Wed, 23 Nov 2016 14:34:07 +0100 Subject: [PATCH] adding dist folder --- dist/jclic.js | 44420 ++++++++++++++++++++++++++++++++++++++++++++ dist/jclic.js.map | 413 + dist/jclic.min.js | 27 + 3 files changed, 44860 insertions(+) create mode 100644 dist/jclic.js create mode 100644 dist/jclic.js.map create mode 100644 dist/jclic.min.js diff --git a/dist/jclic.js b/dist/jclic.js new file mode 100644 index 00000000..831a2a38 --- /dev/null +++ b/dist/jclic.js @@ -0,0 +1,44420 @@ +// JClic.js version 0.1.40 (2016-11-23) +// HTML5 player of JClic activities +// (c) 2000-2016 Catalan Educational Telematic Network (XTEC) +// This program can be freely redistributed under the terms of the European Union Public License +// WARNING: You are reading a minimized version of jclic.js. Full source code is freely available at: +// http://projectestac.github.io/jclic.js + +(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 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 +} + +function byteLength (b64) { + // base64 is 4/3 + up to two characters of the original data + return b64.length * 3 / 4 - placeHoldersCount(b64) +} + +function toByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + var len = b64.length + placeHolders = placeHoldersCount(b64) + + arr = new Arr(len * 3 / 4 - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? len - 4 : len + + var L = 0 + + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] + arr[L++] = (tmp >> 16) & 0xFF + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF + } + + if (placeHolders === 2) { + tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[L++] = tmp & 0xFF + } else if (placeHolders === 1) { + tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF + } + + return arr +} + +function tripletToBase64 (num) { + return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] +} + +function encodeChunk (uint8, start, end) { + var tmp + var output = [] + for (var i = start; i < end; i += 3) { + tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output.push(tripletToBase64(tmp)) + } + return output.join('') +} + +function fromByteArray (uint8) { + var tmp + var len = uint8.length + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes + var output = '' + var parts = [] + var maxChunkLength = 16383 // must be multiple of 3 + + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1] + output += lookup[tmp >> 2] + output += lookup[(tmp << 4) & 0x3F] + output += '==' + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) + output += lookup[tmp >> 10] + output += lookup[(tmp >> 4) & 0x3F] + output += lookup[(tmp << 2) & 0x3F] + output += '=' + } + + parts.push(output) + + return parts.join('') +} + +},{}],2:[function(require,module,exports){ + +},{}],3:[function(require,module,exports){ +(function (global){ +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +/* eslint-disable no-proto */ + +'use strict' + +var base64 = require('base64-js') +var ieee754 = require('ieee754') +var isArray = require('isarray') + +exports.Buffer = Buffer +exports.SlowBuffer = SlowBuffer +exports.INSPECT_MAX_BYTES = 50 + +/** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Use Object implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * + * Note: + * + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. + + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. + */ +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() + +/* + * Export kMaxLength after typed array support is determined. + */ +exports.kMaxLength = kMaxLength() + +function typedArraySupport () { + try { + var arr = new Uint8Array(1) + arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} + return arr.foo() === 42 && // typed array instances can be augmented + typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + } catch (e) { + return false + } +} + +function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff +} + +function createBuffer (that, length) { + if (kMaxLength() < length) { + throw new RangeError('Invalid typed array length') + } + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = new Uint8Array(length) + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + if (that === null) { + that = new Buffer(length) + } + that.length = length + } + + return that +} + +/** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ + +function Buffer (arg, encodingOrOffset, length) { + if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) { + return new Buffer(arg, encodingOrOffset, length) + } + + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') { + throw new Error( + 'If encoding is specified then the first argument must be a string' + ) + } + return allocUnsafe(this, arg) + } + return from(this, arg, encodingOrOffset, length) +} + +Buffer.poolSize = 8192 // not used by this implementation + +// TODO: Legacy, not needed anymore. Remove in next major version. +Buffer._augment = function (arr) { + arr.__proto__ = Buffer.prototype + return arr +} + +function from (that, value, encodingOrOffset, length) { + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number') + } + + if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { + return fromArrayBuffer(that, value, encodingOrOffset, length) + } + + if (typeof value === 'string') { + return fromString(that, value, encodingOrOffset) + } + + return fromObject(that, value) +} + +/** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ +Buffer.from = function (value, encodingOrOffset, length) { + return from(null, value, encodingOrOffset, length) +} + +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array + if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true + }) + } +} + +function assertSize (size) { + if (typeof size !== 'number') { + throw new TypeError('"size" argument must be a number') + } else if (size < 0) { + throw new RangeError('"size" argument must not be negative') + } +} + +function alloc (that, size, fill, encoding) { + assertSize(size) + if (size <= 0) { + return createBuffer(that, size) + } + if (fill !== undefined) { + // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpretted as a start offset. + return typeof encoding === 'string' + ? createBuffer(that, size).fill(fill, encoding) + : createBuffer(that, size).fill(fill) + } + return createBuffer(that, size) +} + +/** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ +Buffer.alloc = function (size, fill, encoding) { + return alloc(null, size, fill, encoding) +} + +function allocUnsafe (that, size) { + assertSize(size) + that = createBuffer(that, size < 0 ? 0 : checked(size) | 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < size; ++i) { + that[i] = 0 + } + } + return that +} + +/** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ +Buffer.allocUnsafe = function (size) { + return allocUnsafe(null, size) +} +/** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ +Buffer.allocUnsafeSlow = function (size) { + return allocUnsafe(null, size) +} + +function fromString (that, string, encoding) { + if (typeof encoding !== 'string' || encoding === '') { + encoding = 'utf8' + } + + if (!Buffer.isEncoding(encoding)) { + throw new TypeError('"encoding" must be a valid string encoding') + } + + var length = byteLength(string, encoding) | 0 + that = createBuffer(that, length) + + var actual = that.write(string, encoding) + + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + that = that.slice(0, actual) + } + + return that +} + +function fromArrayLike (that, array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0 + that = createBuffer(that, length) + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +function fromArrayBuffer (that, array, byteOffset, length) { + array.byteLength // this throws if `array` is not a valid ArrayBuffer + + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('\'offset\' is out of bounds') + } + + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('\'length\' is out of bounds') + } + + if (byteOffset === undefined && length === undefined) { + array = new Uint8Array(array) + } else if (length === undefined) { + array = new Uint8Array(array, byteOffset) + } else { + array = new Uint8Array(array, byteOffset, length) + } + + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = array + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + that = fromArrayLike(that, array) + } + return that +} + +function fromObject (that, obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0 + that = createBuffer(that, len) + + if (that.length === 0) { + return that + } + + obj.copy(that, 0, 0, len) + return that + } + + if (obj) { + if ((typeof ArrayBuffer !== 'undefined' && + obj.buffer instanceof ArrayBuffer) || 'length' in obj) { + if (typeof obj.length !== 'number' || isnan(obj.length)) { + return createBuffer(that, 0) + } + return fromArrayLike(that, obj) + } + + if (obj.type === 'Buffer' && isArray(obj.data)) { + return fromArrayLike(that, obj.data) + } + } + + throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') +} + +function checked (length) { + // Note: cannot use `length < kMaxLength()` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= kMaxLength()) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + kMaxLength().toString(16) + ' bytes') + } + return length | 0 +} + +function SlowBuffer (length) { + if (+length != length) { // eslint-disable-line eqeqeq + length = 0 + } + return Buffer.alloc(+length) +} + +Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) +} + +Buffer.compare = function compare (a, b) { + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError('Arguments must be Buffers') + } + + if (a === b) return 0 + + var x = a.length + var y = b.length + + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i] + y = b[i] + break + } + } + + if (x < y) return -1 + if (y < x) return 1 + return 0 +} + +Buffer.isEncoding = function isEncoding (encoding) { + switch (String(encoding).toLowerCase()) { + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'latin1': + case 'binary': + case 'base64': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true + default: + return false + } +} + +Buffer.concat = function concat (list, length) { + if (!isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + + if (list.length === 0) { + return Buffer.alloc(0) + } + + var i + if (length === undefined) { + length = 0 + for (i = 0; i < list.length; ++i) { + length += list[i].length + } + } + + var buffer = Buffer.allocUnsafe(length) + var pos = 0 + for (i = 0; i < list.length; ++i) { + var buf = list[i] + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos) + pos += buf.length + } + return buffer +} + +function byteLength (string, encoding) { + if (Buffer.isBuffer(string)) { + return string.length + } + if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' && + (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { + return string.byteLength + } + if (typeof string !== 'string') { + string = '' + string + } + + var len = string.length + if (len === 0) return 0 + + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'latin1': + case 'binary': + return len + case 'utf8': + case 'utf-8': + case undefined: + return utf8ToBytes(string).length + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2 + case 'hex': + return len >>> 1 + case 'base64': + return base64ToBytes(string).length + default: + if (loweredCase) return utf8ToBytes(string).length // assume utf8 + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } +} +Buffer.byteLength = byteLength + +function slowToString (encoding, start, end) { + var loweredCase = false + + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. + + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) { + start = 0 + } + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) { + return '' + } + + if (end === undefined || end > this.length) { + end = this.length + } + + if (end <= 0) { + return '' + } + + // Force coersion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0 + start >>>= 0 + + if (end <= start) { + return '' + } + + if (!encoding) encoding = 'utf8' + + while (true) { + switch (encoding) { + case 'hex': + return hexSlice(this, start, end) + + case 'utf8': + case 'utf-8': + return utf8Slice(this, start, end) + + case 'ascii': + return asciiSlice(this, start, end) + + case 'latin1': + case 'binary': + return latin1Slice(this, start, end) + + case 'base64': + return base64Slice(this, start, end) + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return utf16leSlice(this, start, end) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = (encoding + '').toLowerCase() + loweredCase = true + } + } +} + +// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect +// Buffer instances. +Buffer.prototype._isBuffer = true + +function swap (b, n, m) { + var i = b[n] + b[n] = b[m] + b[m] = i +} + +Buffer.prototype.swap16 = function swap16 () { + var len = this.length + if (len % 2 !== 0) { + throw new RangeError('Buffer size must be a multiple of 16-bits') + } + for (var i = 0; i < len; i += 2) { + swap(this, i, i + 1) + } + return this +} + +Buffer.prototype.swap32 = function swap32 () { + var len = this.length + if (len % 4 !== 0) { + throw new RangeError('Buffer size must be a multiple of 32-bits') + } + for (var i = 0; i < len; i += 4) { + swap(this, i, i + 3) + swap(this, i + 1, i + 2) + } + return this +} + +Buffer.prototype.swap64 = function swap64 () { + var len = this.length + if (len % 8 !== 0) { + throw new RangeError('Buffer size must be a multiple of 64-bits') + } + for (var i = 0; i < len; i += 8) { + swap(this, i, i + 7) + swap(this, i + 1, i + 6) + swap(this, i + 2, i + 5) + swap(this, i + 3, i + 4) + } + return this +} + +Buffer.prototype.toString = function toString () { + var length = this.length | 0 + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) +} + +Buffer.prototype.equals = function equals (b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') + if (this === b) return true + return Buffer.compare(this, b) === 0 +} + +Buffer.prototype.inspect = function inspect () { + var str = '' + var max = exports.INSPECT_MAX_BYTES + if (this.length > 0) { + str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') + if (this.length > max) str += ' ... ' + } + return '' +} + +Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { + if (!Buffer.isBuffer(target)) { + throw new TypeError('Argument must be a Buffer') + } + + if (start === undefined) { + start = 0 + } + if (end === undefined) { + end = target ? target.length : 0 + } + if (thisStart === undefined) { + thisStart = 0 + } + if (thisEnd === undefined) { + thisEnd = this.length + } + + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { + throw new RangeError('out of range index') + } + + if (thisStart >= thisEnd && start >= end) { + return 0 + } + if (thisStart >= thisEnd) { + return -1 + } + if (start >= end) { + return 1 + } + + start >>>= 0 + end >>>= 0 + thisStart >>>= 0 + thisEnd >>>= 0 + + if (this === target) return 0 + + var x = thisEnd - thisStart + var y = end - start + var len = Math.min(x, y) + + var thisCopy = this.slice(thisStart, thisEnd) + var targetCopy = target.slice(start, end) + + for (var i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i] + y = targetCopy[i] + break + } + } + + if (x < y) return -1 + if (y < x) return 1 + return 0 +} + +// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, +// OR the last index of `val` in `buffer` at offset <= `byteOffset`. +// +// Arguments: +// - buffer - a Buffer to search +// - val - a string, Buffer, or number +// - byteOffset - an index into `buffer`; will be clamped to an int32 +// - encoding - an optional encoding, relevant is val is a string +// - dir - true for indexOf, false for lastIndexOf +function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1 + + // Normalize byteOffset + if (typeof byteOffset === 'string') { + encoding = byteOffset + byteOffset = 0 + } else if (byteOffset > 0x7fffffff) { + byteOffset = 0x7fffffff + } else if (byteOffset < -0x80000000) { + byteOffset = -0x80000000 + } + byteOffset = +byteOffset // Coerce to Number. + if (isNaN(byteOffset)) { + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : (buffer.length - 1) + } + + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset + if (byteOffset >= buffer.length) { + if (dir) return -1 + else byteOffset = buffer.length - 1 + } else if (byteOffset < 0) { + if (dir) byteOffset = 0 + else return -1 + } + + // Normalize val + if (typeof val === 'string') { + val = Buffer.from(val, encoding) + } + + // Finally, search either indexOf (if dir is true) or lastIndexOf + if (Buffer.isBuffer(val)) { + // Special case: looking for empty string/buffer always fails + if (val.length === 0) { + return -1 + } + return arrayIndexOf(buffer, val, byteOffset, encoding, dir) + } else if (typeof val === 'number') { + val = val & 0xFF // Search for a byte value [0-255] + if (Buffer.TYPED_ARRAY_SUPPORT && + typeof Uint8Array.prototype.indexOf === 'function') { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) + } + } + return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) + } + + throw new TypeError('val must be string, number or Buffer') +} + +function arrayIndexOf (arr, val, byteOffset, encoding, dir) { + var indexSize = 1 + var arrLength = arr.length + var valLength = val.length + + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase() + if (encoding === 'ucs2' || encoding === 'ucs-2' || + encoding === 'utf16le' || encoding === 'utf-16le') { + if (arr.length < 2 || val.length < 2) { + return -1 + } + indexSize = 2 + arrLength /= 2 + valLength /= 2 + byteOffset /= 2 + } + } + + function read (buf, i) { + if (indexSize === 1) { + return buf[i] + } else { + return buf.readUInt16BE(i * indexSize) + } + } + + var i + if (dir) { + var foundIndex = -1 + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) foundIndex = i + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize + } else { + if (foundIndex !== -1) i -= i - foundIndex + foundIndex = -1 + } + } + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength + for (i = byteOffset; i >= 0; i--) { + var found = true + for (var j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false + break + } + } + if (found) return i + } + } + + return -1 +} + +Buffer.prototype.includes = function includes (val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1 +} + +Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true) +} + +Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false) +} + +function hexWrite (buf, string, offset, length) { + offset = Number(offset) || 0 + var remaining = buf.length - offset + if (!length) { + length = remaining + } else { + length = Number(length) + if (length > remaining) { + length = remaining + } + } + + // must be an even number of digits + var strLen = string.length + if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') + + if (length > strLen / 2) { + length = strLen / 2 + } + for (var i = 0; i < length; ++i) { + var parsed = parseInt(string.substr(i * 2, 2), 16) + if (isNaN(parsed)) return i + buf[offset + i] = parsed + } + return i +} + +function utf8Write (buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) +} + +function asciiWrite (buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length) +} + +function latin1Write (buf, string, offset, length) { + return asciiWrite(buf, string, offset, length) +} + +function base64Write (buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length) +} + +function ucs2Write (buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) +} + +Buffer.prototype.write = function write (string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = 'utf8' + length = this.length + offset = 0 + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + encoding = offset + length = this.length + offset = 0 + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset | 0 + if (isFinite(length)) { + length = length | 0 + if (encoding === undefined) encoding = 'utf8' + } else { + encoding = length + length = undefined + } + // legacy write(string, encoding, offset, length) - remove in v0.13 + } else { + throw new Error( + 'Buffer.write(string, encoding, offset[, length]) is no longer supported' + ) + } + + var remaining = this.length - offset + if (length === undefined || length > remaining) length = remaining + + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds') + } + + if (!encoding) encoding = 'utf8' + + var loweredCase = false + for (;;) { + switch (encoding) { + case 'hex': + return hexWrite(this, string, offset, length) + + case 'utf8': + case 'utf-8': + return utf8Write(this, string, offset, length) + + case 'ascii': + return asciiWrite(this, string, offset, length) + + case 'latin1': + case 'binary': + return latin1Write(this, string, offset, length) + + case 'base64': + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length) + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return ucs2Write(this, string, offset, length) + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } +} + +Buffer.prototype.toJSON = function toJSON () { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) + } +} + +function base64Slice (buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf) + } else { + return base64.fromByteArray(buf.slice(start, end)) + } +} + +function utf8Slice (buf, start, end) { + end = Math.min(buf.length, end) + var res = [] + + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = null + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte + } + break + case 2: + secondByte = buf[i + 1] + if ((secondByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) + if (tempCodePoint > 0x7F) { + codePoint = tempCodePoint + } + } + break + case 3: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) + if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { + codePoint = tempCodePoint + } + } + break + case 4: + secondByte = buf[i + 1] + thirdByte = buf[i + 2] + fourthByte = buf[i + 3] + if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { + tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) + if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { + codePoint = tempCodePoint + } + } + } + } + + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xFFFD + bytesPerSequence = 1 + } else if (codePoint > 0xFFFF) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000 + res.push(codePoint >>> 10 & 0x3FF | 0xD800) + codePoint = 0xDC00 | codePoint & 0x3FF + } + + res.push(codePoint) + i += bytesPerSequence + } + + return decodeCodePointsArray(res) +} + +// Based on http://stackoverflow.com/a/22747272/680742, the browser with +// the lowest limit is Chrome, with 0x10000 args. +// We go 1 magnitude less, for safety +var MAX_ARGUMENTS_LENGTH = 0x1000 + +function decodeCodePointsArray (codePoints) { + var len = codePoints.length + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints) // avoid extra slice() + } + + // Decode in chunks to avoid "call stack size exceeded". + var res = '' + var i = 0 + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) + ) + } + return res +} + +function asciiSlice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i] & 0x7F) + } + return ret +} + +function latin1Slice (buf, start, end) { + var ret = '' + end = Math.min(buf.length, end) + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i]) + } + return ret +} + +function hexSlice (buf, start, end) { + var len = buf.length + + if (!start || start < 0) start = 0 + if (!end || end < 0 || end > len) end = len + + var out = '' + for (var i = start; i < end; ++i) { + out += toHex(buf[i]) + } + return out +} + +function utf16leSlice (buf, start, end) { + var bytes = buf.slice(start, end) + var res = '' + for (var i = 0; i < bytes.length; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) + } + return res +} + +Buffer.prototype.slice = function slice (start, end) { + var len = this.length + start = ~~start + end = end === undefined ? len : ~~end + + if (start < 0) { + start += len + if (start < 0) start = 0 + } else if (start > len) { + start = len + } + + if (end < 0) { + end += len + if (end < 0) end = 0 + } else if (end > len) { + end = len + } + + if (end < start) end = start + + var newBuf + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = this.subarray(start, end) + newBuf.__proto__ = Buffer.prototype + } else { + var sliceLen = end - start + newBuf = new Buffer(sliceLen, undefined) + for (var i = 0; i < sliceLen; ++i) { + newBuf[i] = this[i + start] + } + } + + return newBuf +} + +/* + * Need to make sure that buffer isn't trying to write out of bounds. + */ +function checkOffset (offset, ext, length) { + if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') + if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') +} + +Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul + } + + return val +} + +Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + checkOffset(offset, byteLength, this.length) + } + + var val = this[offset + --byteLength] + var mul = 1 + while (byteLength > 0 && (mul *= 0x100)) { + val += this[offset + --byteLength] * mul + } + + return val +} + +Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + return this[offset] +} + +Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return this[offset] | (this[offset + 1] << 8) +} + +Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return (this[offset] << 8) | this[offset + 1] +} + +Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return ((this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16)) + + (this[offset + 3] * 0x1000000) +} + +Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset] * 0x1000000) + + ((this[offset + 1] << 16) | + (this[offset + 2] << 8) | + this[offset + 3]) +} + +Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var val = this[offset] + var mul = 1 + var i = 0 + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul + } + mul *= 0x80 + + if (val >= mul) val -= Math.pow(2, 8 * byteLength) + + return val +} + +Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) checkOffset(offset, byteLength, this.length) + + var i = byteLength + var mul = 1 + var val = this[offset + --i] + while (i > 0 && (mul *= 0x100)) { + val += this[offset + --i] * mul + } + mul *= 0x80 + + if (val >= mul) val -= Math.pow(2, 8 * byteLength) + + return val +} + +Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + if (!noAssert) checkOffset(offset, 1, this.length) + if (!(this[offset] & 0x80)) return (this[offset]) + return ((0xff - this[offset] + 1) * -1) +} + +Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset] | (this[offset + 1] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} + +Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + var val = this[offset + 1] | (this[offset] << 8) + return (val & 0x8000) ? val | 0xFFFF0000 : val +} + +Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset]) | + (this[offset + 1] << 8) | + (this[offset + 2] << 16) | + (this[offset + 3] << 24) +} + +Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + + return (this[offset] << 24) | + (this[offset + 1] << 16) | + (this[offset + 2] << 8) | + (this[offset + 3]) +} + +Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, true, 23, 4) +} + +Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, false, 23, 4) +} + +Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, true, 52, 8) +} + +Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, false, 52, 8) +} + +function checkInt (buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') + if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') + if (offset + ext > buf.length) throw new RangeError('Index out of range') +} + +Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } + + var mul = 1 + var i = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + byteLength = byteLength | 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } + + var i = byteLength - 1 + var mul = 1 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + this[offset] = (value & 0xff) + return offset + 1 +} + +function objectWriteUInt16 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) { + buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> + (littleEndian ? i : 1 - i) * 8 + } +} + +Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + return offset + 2 +} + +Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 +} + +function objectWriteUInt32 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffffffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) { + buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff + } +} + +Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, true) + } + return offset + 4 +} + +Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 +} + +Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } + + var i = 0 + var mul = 1 + var sub = 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1) + + checkInt(this, value, offset, byteLength, limit - 1, -limit) + } + + var i = byteLength - 1 + var mul = 1 + var sub = 0 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1 + } + this[offset + i] = ((value / mul) >> 0) - sub & 0xFF + } + + return offset + byteLength +} + +Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + if (value < 0) value = 0xff + value + 1 + this[offset] = (value & 0xff) + return offset + 1 +} + +Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + return offset + 2 +} + +Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 +} + +Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) + } else { + objectWriteUInt32(this, value, offset, true) + } + return offset + 4 +} + +Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) + if (value < 0) value = 0xffffffff + value + 1 + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 +} + +function checkIEEE754 (buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) throw new RangeError('Index out of range') + if (offset < 0) throw new RangeError('Index out of range') +} + +function writeFloat (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) + } + ieee754.write(buf, value, offset, littleEndian, 23, 4) + return offset + 4 +} + +Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert) +} + +Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert) +} + +function writeDouble (buf, value, offset, littleEndian, noAssert) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) + } + ieee754.write(buf, value, offset, littleEndian, 52, 8) + return offset + 8 +} + +Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert) +} + +Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert) +} + +// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) +Buffer.prototype.copy = function copy (target, targetStart, start, end) { + if (!start) start = 0 + if (!end && end !== 0) end = this.length + if (targetStart >= target.length) targetStart = target.length + if (!targetStart) targetStart = 0 + if (end > 0 && end < start) end = start + + // Copy 0 bytes; we're done + if (end === start) return 0 + if (target.length === 0 || this.length === 0) return 0 + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds') + } + if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') + if (end < 0) throw new RangeError('sourceEnd out of bounds') + + // Are we oob? + if (end > this.length) end = this.length + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start + } + + var len = end - start + var i + + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; ++i) { + target[i + targetStart] = this[i + start] + } + } else { + Uint8Array.prototype.set.call( + target, + this.subarray(start, start + len), + targetStart + ) + } + + return len +} + +// Usage: +// buffer.fill(number[, offset[, end]]) +// buffer.fill(buffer[, offset[, end]]) +// buffer.fill(string[, offset[, end]][, encoding]) +Buffer.prototype.fill = function fill (val, start, end, encoding) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + encoding = start + start = 0 + end = this.length + } else if (typeof end === 'string') { + encoding = end + end = this.length + } + if (val.length === 1) { + var code = val.charCodeAt(0) + if (code < 256) { + val = code + } + } + if (encoding !== undefined && typeof encoding !== 'string') { + throw new TypeError('encoding must be a string') + } + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding) + } + } else if (typeof val === 'number') { + val = val & 255 + } + + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') + } + + if (end <= start) { + return this + } + + start = start >>> 0 + end = end === undefined ? this.length : end >>> 0 + + if (!val) val = 0 + + var i + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val + } + } else { + var bytes = Buffer.isBuffer(val) + ? val + : utf8ToBytes(new Buffer(val, encoding).toString()) + var len = bytes.length + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len] + } + } + + return this +} + +// HELPER FUNCTIONS +// ================ + +var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g + +function base64clean (str) { + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = stringtrim(str).replace(INVALID_BASE64_RE, '') + // Node converts strings with length < 2 to '' + if (str.length < 2) return '' + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while (str.length % 4 !== 0) { + str = str + '=' + } + return str +} + +function stringtrim (str) { + if (str.trim) return str.trim() + return str.replace(/^\s+|\s+$/g, '') +} + +function toHex (n) { + if (n < 16) return '0' + n.toString(16) + return n.toString(16) +} + +function utf8ToBytes (string, units) { + units = units || Infinity + var codePoint + var length = string.length + var leadSurrogate = null + var bytes = [] + + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i) + + // is surrogate component + if (codePoint > 0xD7FF && codePoint < 0xE000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xDBFF) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + continue + } + + // valid lead + leadSurrogate = codePoint + + continue + } + + // 2 leads in a row + if (codePoint < 0xDC00) { + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + leadSurrogate = codePoint + continue + } + + // valid surrogate pair + codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) + } + + leadSurrogate = null + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break + bytes.push(codePoint) + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break + bytes.push( + codePoint >> 0x6 | 0xC0, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break + bytes.push( + codePoint >> 0xC | 0xE0, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break + bytes.push( + codePoint >> 0x12 | 0xF0, + codePoint >> 0xC & 0x3F | 0x80, + codePoint >> 0x6 & 0x3F | 0x80, + codePoint & 0x3F | 0x80 + ) + } else { + throw new Error('Invalid code point') + } + } + + return bytes +} + +function asciiToBytes (str) { + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + // Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 0xFF) + } + return byteArray +} + +function utf16leToBytes (str, units) { + var c, hi, lo + var byteArray = [] + for (var i = 0; i < str.length; ++i) { + if ((units -= 2) < 0) break + + c = str.charCodeAt(i) + hi = c >> 8 + lo = c % 256 + byteArray.push(lo) + byteArray.push(hi) + } + + return byteArray +} + +function base64ToBytes (str) { + return base64.toByteArray(base64clean(str)) +} + +function blitBuffer (src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if ((i + offset >= dst.length) || (i >= src.length)) break + dst[i + offset] = src[i] + } + return i +} + +function isnan (val) { + return val !== val // eslint-disable-line no-self-compare +} + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"base64-js":1,"ieee754":44,"isarray":48}],4:[function(require,module,exports){ +// Import support https://stackoverflow.com/questions/13673346/supporting-both-commonjs-and-amd +(function(name, definition) { + if (typeof module !== "undefined") { module.exports = definition(); } + else if (typeof define === "function" && typeof define.amd === "object") { define(definition); } + else { this[name] = definition(); } +}("clipboard", function() { + if (!document.addEventListener) { + return null; + } + + var clipboard = {}; + + clipboard.copy = (function() { + var _intercept = false; + var _data = null; // Map from data type (e.g. "text/html") to value. + var _bogusSelection = false; + + function cleanup() { + _intercept = false; + _data = null; + if (_bogusSelection) { + window.getSelection().removeAllRanges(); + } + _bogusSelection = false; + } + + document.addEventListener("copy", function(e) { + if (_intercept) { + for (var key in _data) { + e.clipboardData.setData(key, _data[key]); + } + e.preventDefault(); + } + }); + + // Workaround for Safari: https://bugs.webkit.org/show_bug.cgi?id=156529 + function bogusSelect() { + var sel = document.getSelection(); + // If "nothing" is selected... + if (!document.queryCommandEnabled("copy") && sel.isCollapsed) { + // ... temporarily select the entire body. + // + // We select the entire body because: + // - it's guaranteed to exist, + // - it works (unlike, say, document.head, or phantom element that is + // not inserted into the DOM), + // - it doesn't seem to flicker (due to the synchronous copy event), and + // - it avoids modifying the DOM (can trigger mutation observers). + // + // Because we can't do proper feature detection (we already checked + // document.queryCommandEnabled("copy") , which actually gives a false + // negative for Blink when nothing is selected) and UA sniffing is not + // reliable (a lot of UA strings contain "Safari"), this will also + // happen for some browsers other than Safari. :-() + var range = document.createRange(); + range.selectNodeContents(document.body); + sel.addRange(range); + _bogusSelection = true; + } + }; + + return function(data) { + return new Promise(function(resolve, reject) { + _intercept = true; + if (typeof data === "string") { + _data = {"text/plain": data}; + } else if (data instanceof Node) { + _data = {"text/html": new XMLSerializer().serializeToString(data)}; + } else { + _data = data; + } + try { + bogusSelect(); + if (document.execCommand("copy")) { + // document.execCommand is synchronous: http://www.w3.org/TR/2015/WD-clipboard-apis-20150421/#integration-with-rich-text-editing-apis + // So we can call resolve() back here. + cleanup(); + resolve(); + } + else { + throw new Error("Unable to copy. Perhaps it's not available in your browser?"); + } + } catch (e) { + cleanup(); + reject(e); + } + }); + }; + })(); + + clipboard.paste = (function() { + var _intercept = false; + var _resolve; + var _dataType; + + document.addEventListener("paste", function(e) { + if (_intercept) { + _intercept = false; + e.preventDefault(); + var resolve = _resolve; + _resolve = null; + resolve(e.clipboardData.getData(_dataType)); + } + }); + + return function(dataType) { + return new Promise(function(resolve, reject) { + _intercept = true; + _resolve = resolve; + _dataType = dataType || "text/plain"; + try { + if (!document.execCommand("paste")) { + _intercept = false; + reject(new Error("Unable to paste. Pasting only works in Internet Explorer at the moment.")); + } + } catch (e) { + _intercept = false; + reject(new Error(e)); + } + }); + }; + })(); + + // Handle IE behaviour. + if (typeof ClipboardEvent === "undefined" && + typeof window.clipboardData !== "undefined" && + typeof window.clipboardData.setData !== "undefined") { + + /*! promise-polyfill 2.0.1 */ + (function(a){function b(a,b){return function(){a.apply(b,arguments)}}function c(a){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof a)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],i(a,b(e,this),b(f,this))}function d(a){var b=this;return null===this._state?void this._deferreds.push(a):void j(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var d;try{d=c(b._value)}catch(e){return void a.reject(e)}a.resolve(d)})}function e(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"==typeof a||"function"==typeof a)){var c=a.then;if("function"==typeof c)return void i(b(c,a),b(e,this),b(f,this))}this._state=!0,this._value=a,g.call(this)}catch(d){f.call(this,d)}}function f(a){this._state=!1,this._value=a,g.call(this)}function g(){for(var a=0,b=this._deferreds.length;b>a;a++)d.call(this,this._deferreds[a]);this._deferreds=null}function h(a,b,c,d){this.onFulfilled="function"==typeof a?a:null,this.onRejected="function"==typeof b?b:null,this.resolve=c,this.reject=d}function i(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(e){if(d)return;d=!0,c(e)}}var j=c.immediateFn||"function"==typeof setImmediate&&setImmediate||function(a){setTimeout(a,1)},k=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};c.prototype["catch"]=function(a){return this.then(null,a)},c.prototype.then=function(a,b){var e=this;return new c(function(c,f){d.call(e,new h(a,b,c,f))})},c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&k(arguments[0])?arguments[0]:arguments);return new c(function(b,c){function d(f,g){try{if(g&&("object"==typeof g||"function"==typeof g)){var h=g.then;if("function"==typeof h)return void h.call(g,function(a){d(f,a)},c)}a[f]=g,0===--e&&b(a)}catch(i){c(i)}}if(0===a.length)return b([]);for(var e=a.length,f=0;fd;d++)a[d].then(b,c)})},"undefined"!=typeof module&&module.exports?module.exports=c:a.Promise||(a.Promise=c)})(this); + + clipboard.copy = function(data) { + return new Promise(function(resolve, reject) { + // IE supports string and URL types: https://msdn.microsoft.com/en-us/library/ms536744(v=vs.85).aspx + // We only support the string type for now. + if (typeof data !== "string" && !("text/plain" in data)) { + throw new Error("You must provide a text/plain type."); + } + + var strData = (typeof data === "string" ? data : data["text/plain"]); + var copySucceeded = window.clipboardData.setData("Text", strData); + if (copySucceeded) { + resolve(); + } else { + reject(new Error("Copying was rejected.")); + } + }); + }; + + clipboard.paste = function() { + return new Promise(function(resolve, reject) { + var strData = window.clipboardData.getData("Text"); + if (strData) { + resolve(strData); + } else { + // The user rejected the paste request. + reject(new Error("Pasting was rejected.")); + } + }); + }; + } + + return clipboard; +})); + +},{}],5:[function(require,module,exports){ +require('../modules/web.immediate'); +module.exports = require('../modules/_core').setImmediate; +},{"../modules/_core":9,"../modules/web.immediate":25}],6:[function(require,module,exports){ +module.exports = function(it){ + if(typeof it != 'function')throw TypeError(it + ' is not a function!'); + return it; +}; +},{}],7:[function(require,module,exports){ +var isObject = require('./_is-object'); +module.exports = function(it){ + if(!isObject(it))throw TypeError(it + ' is not an object!'); + return it; +}; +},{"./_is-object":20}],8:[function(require,module,exports){ +var toString = {}.toString; + +module.exports = function(it){ + return toString.call(it).slice(8, -1); +}; +},{}],9:[function(require,module,exports){ +var core = module.exports = {version: '2.3.0'}; +if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef +},{}],10:[function(require,module,exports){ +// optional / simple context binding +var aFunction = require('./_a-function'); +module.exports = function(fn, that, length){ + aFunction(fn); + if(that === undefined)return fn; + switch(length){ + case 1: return function(a){ + return fn.call(that, a); + }; + case 2: return function(a, b){ + return fn.call(that, a, b); + }; + case 3: return function(a, b, c){ + return fn.call(that, a, b, c); + }; + } + return function(/* ...args */){ + return fn.apply(that, arguments); + }; +}; +},{"./_a-function":6}],11:[function(require,module,exports){ +// Thank's IE8 for his funny defineProperty +module.exports = !require('./_fails')(function(){ + return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; +}); +},{"./_fails":14}],12:[function(require,module,exports){ +var isObject = require('./_is-object') + , document = require('./_global').document + // in old IE typeof document.createElement is 'object' + , is = isObject(document) && isObject(document.createElement); +module.exports = function(it){ + return is ? document.createElement(it) : {}; +}; +},{"./_global":15,"./_is-object":20}],13:[function(require,module,exports){ +var global = require('./_global') + , core = require('./_core') + , ctx = require('./_ctx') + , hide = require('./_hide') + , PROTOTYPE = 'prototype'; + +var $export = function(type, name, source){ + var IS_FORCED = type & $export.F + , IS_GLOBAL = type & $export.G + , IS_STATIC = type & $export.S + , IS_PROTO = type & $export.P + , IS_BIND = type & $export.B + , IS_WRAP = type & $export.W + , exports = IS_GLOBAL ? core : core[name] || (core[name] = {}) + , expProto = exports[PROTOTYPE] + , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE] + , key, own, out; + if(IS_GLOBAL)source = name; + for(key in source){ + // contains in native + own = !IS_FORCED && target && target[key] !== undefined; + if(own && key in exports)continue; + // export native or passed + out = own ? target[key] : source[key]; + // prevent global pollution for namespaces + exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] + // bind timers to global for call from export context + : IS_BIND && own ? ctx(out, global) + // wrap global constructors for prevent change them in library + : IS_WRAP && target[key] == out ? (function(C){ + var F = function(a, b, c){ + if(this instanceof C){ + switch(arguments.length){ + case 0: return new C; + case 1: return new C(a); + case 2: return new C(a, b); + } return new C(a, b, c); + } return C.apply(this, arguments); + }; + F[PROTOTYPE] = C[PROTOTYPE]; + return F; + // make static versions for prototype methods + })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; + // export proto methods to core.%CONSTRUCTOR%.methods.%NAME% + if(IS_PROTO){ + (exports.virtual || (exports.virtual = {}))[key] = out; + // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% + if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out); + } + } +}; +// type bitmap +$export.F = 1; // forced +$export.G = 2; // global +$export.S = 4; // static +$export.P = 8; // proto +$export.B = 16; // bind +$export.W = 32; // wrap +$export.U = 64; // safe +$export.R = 128; // real proto method for `library` +module.exports = $export; +},{"./_core":9,"./_ctx":10,"./_global":15,"./_hide":16}],14:[function(require,module,exports){ +module.exports = function(exec){ + try { + return !!exec(); + } catch(e){ + return true; + } +}; +},{}],15:[function(require,module,exports){ +// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 +var global = module.exports = typeof window != 'undefined' && window.Math == Math + ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); +if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef +},{}],16:[function(require,module,exports){ +var dP = require('./_object-dp') + , createDesc = require('./_property-desc'); +module.exports = require('./_descriptors') ? function(object, key, value){ + return dP.f(object, key, createDesc(1, value)); +} : function(object, key, value){ + object[key] = value; + return object; +}; +},{"./_descriptors":11,"./_object-dp":21,"./_property-desc":22}],17:[function(require,module,exports){ +module.exports = require('./_global').document && document.documentElement; +},{"./_global":15}],18:[function(require,module,exports){ +module.exports = !require('./_descriptors') && !require('./_fails')(function(){ + return Object.defineProperty(require('./_dom-create')('div'), 'a', {get: function(){ return 7; }}).a != 7; +}); +},{"./_descriptors":11,"./_dom-create":12,"./_fails":14}],19:[function(require,module,exports){ +// fast apply, http://jsperf.lnkit.com/fast-apply/5 +module.exports = function(fn, args, that){ + var un = that === undefined; + switch(args.length){ + case 0: return un ? fn() + : fn.call(that); + case 1: return un ? fn(args[0]) + : fn.call(that, args[0]); + case 2: return un ? fn(args[0], args[1]) + : fn.call(that, args[0], args[1]); + case 3: return un ? fn(args[0], args[1], args[2]) + : fn.call(that, args[0], args[1], args[2]); + case 4: return un ? fn(args[0], args[1], args[2], args[3]) + : fn.call(that, args[0], args[1], args[2], args[3]); + } return fn.apply(that, args); +}; +},{}],20:[function(require,module,exports){ +module.exports = function(it){ + return typeof it === 'object' ? it !== null : typeof it === 'function'; +}; +},{}],21:[function(require,module,exports){ +var anObject = require('./_an-object') + , IE8_DOM_DEFINE = require('./_ie8-dom-define') + , toPrimitive = require('./_to-primitive') + , dP = Object.defineProperty; + +exports.f = require('./_descriptors') ? Object.defineProperty : function defineProperty(O, P, Attributes){ + anObject(O); + P = toPrimitive(P, true); + anObject(Attributes); + if(IE8_DOM_DEFINE)try { + return dP(O, P, Attributes); + } catch(e){ /* empty */ } + if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!'); + if('value' in Attributes)O[P] = Attributes.value; + return O; +}; +},{"./_an-object":7,"./_descriptors":11,"./_ie8-dom-define":18,"./_to-primitive":24}],22:[function(require,module,exports){ +module.exports = function(bitmap, value){ + return { + enumerable : !(bitmap & 1), + configurable: !(bitmap & 2), + writable : !(bitmap & 4), + value : value + }; +}; +},{}],23:[function(require,module,exports){ +var ctx = require('./_ctx') + , invoke = require('./_invoke') + , html = require('./_html') + , cel = require('./_dom-create') + , global = require('./_global') + , process = global.process + , setTask = global.setImmediate + , clearTask = global.clearImmediate + , MessageChannel = global.MessageChannel + , counter = 0 + , queue = {} + , ONREADYSTATECHANGE = 'onreadystatechange' + , defer, channel, port; +var run = function(){ + var id = +this; + if(queue.hasOwnProperty(id)){ + var fn = queue[id]; + delete queue[id]; + fn(); + } +}; +var listener = function(event){ + run.call(event.data); +}; +// Node.js 0.9+ & IE10+ has setImmediate, otherwise: +if(!setTask || !clearTask){ + setTask = function setImmediate(fn){ + var args = [], i = 1; + while(arguments.length > i)args.push(arguments[i++]); + queue[++counter] = function(){ + invoke(typeof fn == 'function' ? fn : Function(fn), args); + }; + defer(counter); + return counter; + }; + clearTask = function clearImmediate(id){ + delete queue[id]; + }; + // Node.js 0.8- + if(require('./_cof')(process) == 'process'){ + defer = function(id){ + process.nextTick(ctx(run, id, 1)); + }; + // Browsers with MessageChannel, includes WebWorkers + } else if(MessageChannel){ + channel = new MessageChannel; + port = channel.port2; + channel.port1.onmessage = listener; + defer = ctx(port.postMessage, port, 1); + // Browsers with postMessage, skip WebWorkers + // IE8 has postMessage, but it's sync & typeof its postMessage is 'object' + } else if(global.addEventListener && typeof postMessage == 'function' && !global.importScripts){ + defer = function(id){ + global.postMessage(id + '', '*'); + }; + global.addEventListener('message', listener, false); + // IE8- + } else if(ONREADYSTATECHANGE in cel('script')){ + defer = function(id){ + html.appendChild(cel('script'))[ONREADYSTATECHANGE] = function(){ + html.removeChild(this); + run.call(id); + }; + }; + // Rest old browsers + } else { + defer = function(id){ + setTimeout(ctx(run, id, 1), 0); + }; + } +} +module.exports = { + set: setTask, + clear: clearTask +}; +},{"./_cof":8,"./_ctx":10,"./_dom-create":12,"./_global":15,"./_html":17,"./_invoke":19}],24:[function(require,module,exports){ +// 7.1.1 ToPrimitive(input [, PreferredType]) +var isObject = require('./_is-object'); +// instead of the ES6 spec version, we didn't implement @@toPrimitive case +// and the second argument - flag - preferred type is a string +module.exports = function(it, S){ + if(!isObject(it))return it; + var fn, val; + if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; + if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val; + if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; + throw TypeError("Can't convert object to primitive value"); +}; +},{"./_is-object":20}],25:[function(require,module,exports){ +var $export = require('./_export') + , $task = require('./_task'); +$export($export.G + $export.B, { + setImmediate: $task.set, + clearImmediate: $task.clear +}); +},{"./_export":13,"./_task":23}],26:[function(require,module,exports){ +(function (Buffer){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. + +function isArray(arg) { + if (Array.isArray) { + return Array.isArray(arg); + } + return objectToString(arg) === '[object Array]'; +} +exports.isArray = isArray; + +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; + +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; + +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; + +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; + +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; + +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; + +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; + +function isRegExp(re) { + return objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; + +function isDate(d) { + return objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; + +function isError(e) { + return (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; + +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; + +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; + +exports.isBuffer = Buffer.isBuffer; + +function objectToString(o) { + return Object.prototype.toString.call(o); +} + +}).call(this,{"isBuffer":require("../../is-buffer/index.js")}) + +},{"../../is-buffer/index.js":47}],27:[function(require,module,exports){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +function EventEmitter() { + this._events = this._events || {}; + this._maxListeners = this._maxListeners || undefined; +} +module.exports = EventEmitter; + +// Backwards-compat with node 0.10.x +EventEmitter.EventEmitter = EventEmitter; + +EventEmitter.prototype._events = undefined; +EventEmitter.prototype._maxListeners = undefined; + +// By default EventEmitters will print a warning if more than 10 listeners are +// added to it. This is a useful default which helps finding memory leaks. +EventEmitter.defaultMaxListeners = 10; + +// Obviously not all Emitters should be limited to 10. This function allows +// that to be increased. Set to zero for unlimited. +EventEmitter.prototype.setMaxListeners = function(n) { + if (!isNumber(n) || n < 0 || isNaN(n)) + throw TypeError('n must be a positive number'); + this._maxListeners = n; + return this; +}; + +EventEmitter.prototype.emit = function(type) { + var er, handler, len, args, i, listeners; + + if (!this._events) + this._events = {}; + + // If there is no 'error' event listener then throw. + if (type === 'error') { + if (!this._events.error || + (isObject(this._events.error) && !this._events.error.length)) { + er = arguments[1]; + if (er instanceof Error) { + throw er; // Unhandled 'error' event + } else { + // At least give some kind of context to the user + var err = new Error('Uncaught, unspecified "error" event. (' + er + ')'); + err.context = er; + throw err; + } + } + } + + handler = this._events[type]; + + if (isUndefined(handler)) + return false; + + if (isFunction(handler)) { + switch (arguments.length) { + // fast cases + case 1: + handler.call(this); + break; + case 2: + handler.call(this, arguments[1]); + break; + case 3: + handler.call(this, arguments[1], arguments[2]); + break; + // slower + default: + args = Array.prototype.slice.call(arguments, 1); + handler.apply(this, args); + } + } else if (isObject(handler)) { + args = Array.prototype.slice.call(arguments, 1); + listeners = handler.slice(); + len = listeners.length; + for (i = 0; i < len; i++) + listeners[i].apply(this, args); + } + + return true; +}; + +EventEmitter.prototype.addListener = function(type, listener) { + var m; + + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + if (!this._events) + this._events = {}; + + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (this._events.newListener) + this.emit('newListener', type, + isFunction(listener.listener) ? + listener.listener : listener); + + if (!this._events[type]) + // Optimize the case of one listener. Don't need the extra array object. + this._events[type] = listener; + else if (isObject(this._events[type])) + // If we've already got an array, just append. + this._events[type].push(listener); + else + // Adding the second element, need to change to array. + this._events[type] = [this._events[type], listener]; + + // Check for listener leak + if (isObject(this._events[type]) && !this._events[type].warned) { + if (!isUndefined(this._maxListeners)) { + m = this._maxListeners; + } else { + m = EventEmitter.defaultMaxListeners; + } + + if (m && m > 0 && this._events[type].length > m) { + this._events[type].warned = true; + console.error('(node) warning: possible EventEmitter memory ' + + 'leak detected. %d listeners added. ' + + 'Use emitter.setMaxListeners() to increase limit.', + this._events[type].length); + if (typeof console.trace === 'function') { + // not supported in IE 10 + console.trace(); + } + } + } + + return this; +}; + +EventEmitter.prototype.on = EventEmitter.prototype.addListener; + +EventEmitter.prototype.once = function(type, listener) { + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + var fired = false; + + function g() { + this.removeListener(type, g); + + if (!fired) { + fired = true; + listener.apply(this, arguments); + } + } + + g.listener = listener; + this.on(type, g); + + return this; +}; + +// emits a 'removeListener' event iff the listener was removed +EventEmitter.prototype.removeListener = function(type, listener) { + var list, position, length, i; + + if (!isFunction(listener)) + throw TypeError('listener must be a function'); + + if (!this._events || !this._events[type]) + return this; + + list = this._events[type]; + length = list.length; + position = -1; + + if (list === listener || + (isFunction(list.listener) && list.listener === listener)) { + delete this._events[type]; + if (this._events.removeListener) + this.emit('removeListener', type, listener); + + } else if (isObject(list)) { + for (i = length; i-- > 0;) { + if (list[i] === listener || + (list[i].listener && list[i].listener === listener)) { + position = i; + break; + } + } + + if (position < 0) + return this; + + if (list.length === 1) { + list.length = 0; + delete this._events[type]; + } else { + list.splice(position, 1); + } + + if (this._events.removeListener) + this.emit('removeListener', type, listener); + } + + return this; +}; + +EventEmitter.prototype.removeAllListeners = function(type) { + var key, listeners; + + if (!this._events) + return this; + + // not listening for removeListener, no need to emit + if (!this._events.removeListener) { + if (arguments.length === 0) + this._events = {}; + else if (this._events[type]) + delete this._events[type]; + return this; + } + + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + for (key in this._events) { + if (key === 'removeListener') continue; + this.removeAllListeners(key); + } + this.removeAllListeners('removeListener'); + this._events = {}; + return this; + } + + listeners = this._events[type]; + + if (isFunction(listeners)) { + this.removeListener(type, listeners); + } else if (listeners) { + // LIFO order + while (listeners.length) + this.removeListener(type, listeners[listeners.length - 1]); + } + delete this._events[type]; + + return this; +}; + +EventEmitter.prototype.listeners = function(type) { + var ret; + if (!this._events || !this._events[type]) + ret = []; + else if (isFunction(this._events[type])) + ret = [this._events[type]]; + else + ret = this._events[type].slice(); + return ret; +}; + +EventEmitter.prototype.listenerCount = function(type) { + if (this._events) { + var evlistener = this._events[type]; + + if (isFunction(evlistener)) + return 1; + else if (evlistener) + return evlistener.length; + } + return 0; +}; + +EventEmitter.listenerCount = function(emitter, type) { + return emitter.listenerCount(type); +}; + +function isFunction(arg) { + return typeof arg === 'function'; +} + +function isNumber(arg) { + return typeof arg === 'number'; +} + +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} + +function isUndefined(arg) { + return arg === void 0; +} + +},{}],28:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +var _utils = require('./utils'); + +var utils = _interopRequireWildcard(_utils); + +var _logger = require('./logger'); + +var _logger2 = _interopRequireDefault(_logger); + +var _EventEmitter2 = require('./EventEmitter'); + +var _EventEmitter3 = _interopRequireDefault(_EventEmitter2); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } + +function remove(arr, what) { + var found = arr.indexOf(what); + + while (found !== -1) { + arr.splice(found, 1); + found = arr.indexOf(what); + } +} + +var Connector = function (_EventEmitter) { + _inherits(Connector, _EventEmitter); + + function Connector(backend, store, services) { + var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + + _classCallCheck(this, Connector); + + var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); + + _this.backend = backend; + _this.store = store; + _this.services = services; + _this.options = options; + _this.logger = _logger2.default.create('backendConnector'); + + _this.state = {}; + _this.queue = []; + + _this.backend && _this.backend.init && _this.backend.init(services, options.backend, options); + return _this; + } + + Connector.prototype.queueLoad = function queueLoad(languages, namespaces, callback) { + var _this2 = this; + + // find what needs to be loaded + var toLoad = [], + pending = [], + toLoadLanguages = [], + toLoadNamespaces = []; + + languages.forEach(function (lng) { + var hasAllNamespaces = true; + + namespaces.forEach(function (ns) { + var name = lng + '|' + ns; + + if (_this2.store.hasResourceBundle(lng, ns)) { + _this2.state[name] = 2; // loaded + } else if (_this2.state[name] < 0) { + // nothing to do for err + } else if (_this2.state[name] === 1) { + if (pending.indexOf(name) < 0) pending.push(name); + } else { + _this2.state[name] = 1; // pending + + hasAllNamespaces = false; + + if (pending.indexOf(name) < 0) pending.push(name); + if (toLoad.indexOf(name) < 0) toLoad.push(name); + if (toLoadNamespaces.indexOf(ns) < 0) toLoadNamespaces.push(ns); + } + }); + + if (!hasAllNamespaces) toLoadLanguages.push(lng); + }); + + if (toLoad.length || pending.length) { + this.queue.push({ + pending: pending, + loaded: {}, + errors: [], + callback: callback + }); + } + + return { + toLoad: toLoad, + pending: pending, + toLoadLanguages: toLoadLanguages, + toLoadNamespaces: toLoadNamespaces + }; + }; + + Connector.prototype.loaded = function loaded(name, err, data) { + var _this3 = this; + + var _name$split = name.split('|'), + _name$split2 = _slicedToArray(_name$split, 2), + lng = _name$split2[0], + ns = _name$split2[1]; + + if (err) this.emit('failedLoading', lng, ns, err); + + if (data) { + this.store.addResourceBundle(lng, ns, data); + } + + // set loaded + this.state[name] = err ? -1 : 2; + // callback if ready + this.queue.forEach(function (q) { + utils.pushPath(q.loaded, [lng], ns); + remove(q.pending, name); + + if (err) q.errors.push(err); + + if (q.pending.length === 0 && !q.done) { + q.errors.length ? q.callback(q.errors) : q.callback(); + _this3.emit('loaded', q.loaded); + q.done = true; + } + }); + + // remove done load requests + this.queue = this.queue.filter(function (q) { + return !q.done; + }); + }; + + Connector.prototype.read = function read(lng, ns, fcName, tried, wait, callback) { + var _this4 = this; + + if (!tried) tried = 0; + if (!wait) wait = 250; + + if (!lng.length) return callback(null, {}); // noting to load + + this.backend[fcName](lng, ns, function (err, data) { + if (err && data /* = retryFlag */ && tried < 5) { + setTimeout(function () { + _this4.read.call(_this4, lng, ns, fcName, ++tried, wait * 2, callback); + }, wait); + return; + } + callback(err, data); + }); + }; + + Connector.prototype.load = function load(languages, namespaces, callback) { + var _this5 = this; + + if (!this.backend) { + this.logger.warn('No backend was added via i18next.use. Will not load resources.'); + return callback && callback(); + } + var options = _extends({}, this.backend.options, this.options.backend); + + if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); + if (typeof namespaces === 'string') namespaces = [namespaces]; + + var toLoad = this.queueLoad(languages, namespaces, callback); + if (!toLoad.toLoad.length) { + if (!toLoad.pending.length) callback(); // nothing to load and no pendings...callback now + return; // pendings will trigger callback + } + + // load with multi-load + if (options.allowMultiLoading && this.backend.readMulti) { + this.read(toLoad.toLoadLanguages, toLoad.toLoadNamespaces, 'readMulti', null, null, function (err, data) { + if (err) _this5.logger.warn('loading namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading failed', err); + if (!err && data) _this5.logger.log('loaded namespaces ' + toLoad.toLoadNamespaces.join(', ') + ' for languages ' + toLoad.toLoadLanguages.join(', ') + ' via multiloading', data); + + toLoad.toLoad.forEach(function (name) { + var _name$split3 = name.split('|'), + _name$split4 = _slicedToArray(_name$split3, 2), + l = _name$split4[0], + n = _name$split4[1]; + + var bundle = utils.getPath(data, [l, n]); + if (bundle) { + _this5.loaded(name, err, bundle); + } else { + var _err = 'loading namespace ' + n + ' for language ' + l + ' via multiloading failed'; + _this5.loaded(name, _err); + _this5.logger.error(_err); + } + }); + }); + } + + // load one by one + else { + (function () { + var readOne = function readOne(name) { + var _this6 = this; + + var _name$split5 = name.split('|'), + _name$split6 = _slicedToArray(_name$split5, 2), + lng = _name$split6[0], + ns = _name$split6[1]; + + this.read(lng, ns, 'read', null, null, function (err, data) { + if (err) _this6.logger.warn('loading namespace ' + ns + ' for language ' + lng + ' failed', err); + if (!err && data) _this6.logger.log('loaded namespace ' + ns + ' for language ' + lng, data); + + _this6.loaded(name, err, data); + }); + }; + + ; + + toLoad.toLoad.forEach(function (name) { + readOne.call(_this5, name); + }); + })(); + } + }; + + Connector.prototype.reload = function reload(languages, namespaces) { + var _this7 = this; + + if (!this.backend) { + this.logger.warn('No backend was added via i18next.use. Will not load resources.'); + } + var options = _extends({}, this.backend.options, this.options.backend); + + if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); + if (typeof namespaces === 'string') namespaces = [namespaces]; + + // load with multi-load + if (options.allowMultiLoading && this.backend.readMulti) { + this.read(languages, namespaces, 'readMulti', null, null, function (err, data) { + if (err) _this7.logger.warn('reloading namespaces ' + namespaces.join(', ') + ' for languages ' + languages.join(', ') + ' via multiloading failed', err); + if (!err && data) _this7.logger.log('reloaded namespaces ' + namespaces.join(', ') + ' for languages ' + languages.join(', ') + ' via multiloading', data); + + languages.forEach(function (l) { + namespaces.forEach(function (n) { + var bundle = utils.getPath(data, [l, n]); + if (bundle) { + _this7.loaded(l + '|' + n, err, bundle); + } else { + var _err2 = 'reloading namespace ' + n + ' for language ' + l + ' via multiloading failed'; + _this7.loaded(l + '|' + n, _err2); + _this7.logger.error(_err2); + } + }); + }); + }); + } + + // load one by one + else { + (function () { + var readOne = function readOne(name) { + var _this8 = this; + + var _name$split7 = name.split('|'), + _name$split8 = _slicedToArray(_name$split7, 2), + lng = _name$split8[0], + ns = _name$split8[1]; + + this.read(lng, ns, 'read', null, null, function (err, data) { + if (err) _this8.logger.warn('reloading namespace ' + ns + ' for language ' + lng + ' failed', err); + if (!err && data) _this8.logger.log('reloaded namespace ' + ns + ' for language ' + lng, data); + + _this8.loaded(name, err, data); + }); + }; + + ; + + languages.forEach(function (l) { + namespaces.forEach(function (n) { + readOne.call(_this7, l + '|' + n); + }); + }); + })(); + } + }; + + Connector.prototype.saveMissing = function saveMissing(languages, namespace, key, fallbackValue) { + if (this.backend && this.backend.create) this.backend.create(languages, namespace, key, fallbackValue); + + // write to store to avoid resending + if (!languages || !languages[0]) return; + this.store.addResource(languages[0], namespace, key, fallbackValue); + }; + + return Connector; +}(_EventEmitter3.default); + +exports.default = Connector; +},{"./EventEmitter":30,"./logger":40,"./utils":42}],29:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _utils = require('./utils'); + +var utils = _interopRequireWildcard(_utils); + +var _logger = require('./logger'); + +var _logger2 = _interopRequireDefault(_logger); + +var _EventEmitter2 = require('./EventEmitter'); + +var _EventEmitter3 = _interopRequireDefault(_EventEmitter2); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } + +var Connector = function (_EventEmitter) { + _inherits(Connector, _EventEmitter); + + function Connector(cache, store, services) { + var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + + _classCallCheck(this, Connector); + + var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); + + _this.cache = cache; + _this.store = store; + _this.services = services; + _this.options = options; + _this.logger = _logger2.default.create('cacheConnector'); + + _this.cache && _this.cache.init && _this.cache.init(services, options.cache, options); + return _this; + } + + Connector.prototype.load = function load(languages, namespaces, callback) { + var _this2 = this; + + if (!this.cache) return callback && callback(); + var options = _extends({}, this.cache.options, this.options.cache); + + if (typeof languages === 'string') languages = this.services.languageUtils.toResolveHierarchy(languages); + if (typeof namespaces === 'string') namespaces = [namespaces]; + + if (options.enabled) { + this.cache.load(languages, function (err, data) { + if (err) _this2.logger.error('loading languages ' + languages.join(', ') + ' from cache failed', err); + if (data) { + for (var l in data) { + for (var n in data[l]) { + if (n === 'i18nStamp') continue; + var bundle = data[l][n]; + if (bundle) _this2.store.addResourceBundle(l, n, bundle); + } + } + } + if (callback) callback(); + }); + } else { + if (callback) callback(); + } + }; + + Connector.prototype.save = function save() { + if (this.cache && this.options.cache && this.options.cache.enabled) this.cache.save(this.store.data); + }; + + return Connector; +}(_EventEmitter3.default); + +exports.default = Connector; +},{"./EventEmitter":30,"./logger":40,"./utils":42}],30:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var EventEmitter = function () { + function EventEmitter() { + _classCallCheck(this, EventEmitter); + + this.observers = {}; + } + + EventEmitter.prototype.on = function on(events, listener) { + var _this = this; + + events.split(' ').forEach(function (event) { + _this.observers[event] = _this.observers[event] || []; + _this.observers[event].push(listener); + }); + }; + + EventEmitter.prototype.off = function off(event, listener) { + var _this2 = this; + + if (!this.observers[event]) { + return; + } + + this.observers[event].forEach(function () { + if (!listener) { + delete _this2.observers[event]; + } else { + var index = _this2.observers[event].indexOf(listener); + if (index > -1) { + _this2.observers[event].splice(index, 1); + } + } + }); + }; + + EventEmitter.prototype.emit = function emit(event) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + if (this.observers[event]) { + this.observers[event].forEach(function (observer) { + observer.apply(undefined, args); + }); + } + + if (this.observers['*']) { + this.observers['*'].forEach(function (observer) { + var _ref; + + observer.apply(observer, (_ref = [event]).concat.apply(_ref, args)); + }); + } + }; + + return EventEmitter; +}(); + +exports.default = EventEmitter; +},{}],31:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _utils = require('./utils'); + +var utils = _interopRequireWildcard(_utils); + +var _logger = require('./logger'); + +var _logger2 = _interopRequireDefault(_logger); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Interpolator = function () { + function Interpolator() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + _classCallCheck(this, Interpolator); + + this.logger = _logger2.default.create('interpolator'); + + this.init(options, true); + } + + Interpolator.prototype.init = function init() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var reset = arguments[1]; + + if (reset) { + this.options = options; + this.format = options.interpolation && options.interpolation.format || function (value) { + return value; + }; + } + if (!options.interpolation) options.interpolation = { escapeValue: true }; + + var iOpts = options.interpolation; + + this.escapeValue = iOpts.escapeValue !== undefined ? iOpts.escapeValue : true; + + this.prefix = iOpts.prefix ? utils.regexEscape(iOpts.prefix) : iOpts.prefixEscaped || '{{'; + this.suffix = iOpts.suffix ? utils.regexEscape(iOpts.suffix) : iOpts.suffixEscaped || '}}'; + this.formatSeparator = iOpts.formatSeparator ? utils.regexEscape(iOpts.formatSeparator) : iOpts.formatSeparator || ','; + + this.unescapePrefix = iOpts.unescapeSuffix ? '' : iOpts.unescapePrefix || '-'; + this.unescapeSuffix = this.unescapePrefix ? '' : iOpts.unescapeSuffix || ''; + + this.nestingPrefix = iOpts.nestingPrefix ? utils.regexEscape(iOpts.nestingPrefix) : iOpts.nestingPrefixEscaped || utils.regexEscape('$t('); + this.nestingSuffix = iOpts.nestingSuffix ? utils.regexEscape(iOpts.nestingSuffix) : iOpts.nestingSuffixEscaped || utils.regexEscape(')'); + + // the regexp + this.resetRegExp(); + }; + + Interpolator.prototype.reset = function reset() { + if (this.options) this.init(this.options); + }; + + Interpolator.prototype.resetRegExp = function resetRegExp() { + // the regexp + var regexpStr = this.prefix + '(.+?)' + this.suffix; + this.regexp = new RegExp(regexpStr, 'g'); + + var regexpUnescapeStr = this.prefix + this.unescapePrefix + '(.+?)' + this.unescapeSuffix + this.suffix; + this.regexpUnescape = new RegExp(regexpUnescapeStr, 'g'); + + var nestingRegexpStr = this.nestingPrefix + '(.+?)' + this.nestingSuffix; + this.nestingRegexp = new RegExp(nestingRegexpStr, 'g'); + }; + + Interpolator.prototype.interpolate = function interpolate(str, data, lng) { + var _this = this; + + var match = void 0, + value = void 0; + + function regexSafe(val) { + return val.replace(/\$/g, '$$$$'); + } + + var handleFormat = function handleFormat(key) { + if (key.indexOf(_this.formatSeparator) < 0) return utils.getPath(data, key); + + var p = key.split(_this.formatSeparator); + var k = p.shift().trim(); + var f = p.join(_this.formatSeparator).trim(); + + return _this.format(utils.getPath(data, k), f, lng); + }; + + this.resetRegExp(); + + // unescape if has unescapePrefix/Suffix + while (match = this.regexpUnescape.exec(str)) { + var _value = handleFormat(match[1].trim()); + str = str.replace(match[0], _value); + this.regexpUnescape.lastIndex = 0; + } + + // regular escape on demand + while (match = this.regexp.exec(str)) { + value = handleFormat(match[1].trim()); + if (typeof value !== 'string') value = utils.makeString(value); + if (!value) { + this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); + value = ''; + } + value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); + str = str.replace(match[0], value); + this.regexp.lastIndex = 0; + } + return str; + }; + + Interpolator.prototype.nest = function nest(str, fc) { + var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; + + var match = void 0, + value = void 0; + + var clonedOptions = JSON.parse(JSON.stringify(options)); + clonedOptions.applyPostProcessor = false; // avoid post processing on nested lookup + + function regexSafe(val) { + return val.replace(/\$/g, '$$$$'); + } + + // if value is something like "myKey": "lorem $(anotherKey, { "count": {{aValueInOptions}} })" + function handleHasOptions(key) { + if (key.indexOf(',') < 0) return key; + + var p = key.split(','); + key = p.shift(); + var optionsString = p.join(','); + optionsString = this.interpolate(optionsString, clonedOptions); + + try { + clonedOptions = JSON.parse(optionsString); + } catch (e) { + this.logger.error('failed parsing options string in nesting for key ' + key, e); + } + + return key; + } + + // regular escape on demand + while (match = this.nestingRegexp.exec(str)) { + value = fc(handleHasOptions.call(this, match[1].trim()), clonedOptions); + if (typeof value !== 'string') value = utils.makeString(value); + if (!value) { + this.logger.warn('missed to pass in variable ' + match[1] + ' for interpolating ' + str); + value = ''; + } + value = this.escapeValue ? regexSafe(utils.escape(value)) : regexSafe(value); + str = str.replace(match[0], value); + this.regexp.lastIndex = 0; + } + return str; + }; + + return Interpolator; +}(); + +exports.default = Interpolator; +},{"./logger":40,"./utils":42}],32:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _logger = require('./logger'); + +var _logger2 = _interopRequireDefault(_logger); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function capitalize(string) { + return string.charAt(0).toUpperCase() + string.slice(1); +} + +var LanguageUtil = function () { + function LanguageUtil(options) { + _classCallCheck(this, LanguageUtil); + + this.options = options; + + this.whitelist = this.options.whitelist || false; + this.logger = _logger2.default.create('languageUtils'); + } + + LanguageUtil.prototype.getLanguagePartFromCode = function getLanguagePartFromCode(code) { + if (code.indexOf('-') < 0) return code; + + var specialCases = ['NB-NO', 'NN-NO', 'nb-NO', 'nn-NO', 'nb-no', 'nn-no']; + var p = code.split('-'); + return this.formatLanguageCode(specialCases.indexOf(code) > -1 ? p[1].toLowerCase() : p[0]); + }; + + LanguageUtil.prototype.getScriptPartFromCode = function getScriptPartFromCode(code) { + if (code.indexOf('-') < 0) return null; + + var p = code.split('-'); + if (p.length === 2) return null; + p.pop(); + return this.formatLanguageCode(p.join('-')); + }; + + LanguageUtil.prototype.getLanguagePartFromCode = function getLanguagePartFromCode(code) { + if (code.indexOf('-') < 0) return code; + + var specialCases = ['NB-NO', 'NN-NO', 'nb-NO', 'nn-NO', 'nb-no', 'nn-no']; + var p = code.split('-'); + return this.formatLanguageCode(specialCases.indexOf(code) > -1 ? p[1].toLowerCase() : p[0]); + }; + + LanguageUtil.prototype.formatLanguageCode = function formatLanguageCode(code) { + // http://www.iana.org/assignments/language-tags/language-tags.xhtml + if (typeof code === 'string' && code.indexOf('-') > -1) { + var specialCases = ['hans', 'hant', 'latn', 'cyrl', 'cans', 'mong', 'arab']; + var p = code.split('-'); + + if (this.options.lowerCaseLng) { + p = p.map(function (part) { + return part.toLowerCase(); + }); + } else if (p.length === 2) { + p[0] = p[0].toLowerCase(); + p[1] = p[1].toUpperCase(); + + if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase()); + } else if (p.length === 3) { + p[0] = p[0].toLowerCase(); + + // if lenght 2 guess it's a country + if (p[1].length === 2) p[1] = p[1].toUpperCase(); + if (p[0] !== 'sgn' && p[2].length === 2) p[2] = p[2].toUpperCase(); + + if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase()); + if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase()); + } + + return p.join('-'); + } else { + return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code; + } + }; + + LanguageUtil.prototype.isWhitelisted = function isWhitelisted(code, exactMatch) { + if (this.options.load === 'languageOnly' || this.options.nonExplicitWhitelist && !exactMatch) { + code = this.getLanguagePartFromCode(code); + } + return !this.whitelist || !this.whitelist.length || this.whitelist.indexOf(code) > -1 ? true : false; + }; + + LanguageUtil.prototype.getFallbackCodes = function getFallbackCodes(fallbacks, code) { + if (!fallbacks) return []; + if (typeof fallbacks === 'string') fallbacks = [fallbacks]; + if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks; + + // asume we have an object defining fallbacks + var found = fallbacks[code]; + if (!found) found = fallbacks[this.getScriptPartFromCode(code)]; + if (!found) found = fallbacks[this.formatLanguageCode(code)]; + if (!found) found = fallbacks.default; + + return found || []; + }; + + LanguageUtil.prototype.toResolveHierarchy = function toResolveHierarchy(code, fallbackCode) { + var _this = this; + + var fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code); + + var codes = []; + var addCode = function addCode(code) { + var exactMatch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + + if (!code) return; + if (_this.isWhitelisted(code, exactMatch)) { + codes.push(code); + } else { + _this.logger.warn('rejecting non-whitelisted language code: ' + code); + } + }; + + if (typeof code === 'string' && code.indexOf('-') > -1) { + if (this.options.load !== 'languageOnly') addCode(this.formatLanguageCode(code), true); + if (this.options.load !== 'languageOnly' && this.options.load !== 'currentOnly') addCode(this.getScriptPartFromCode(code), true); + if (this.options.load !== 'currentOnly') addCode(this.getLanguagePartFromCode(code)); + } else if (typeof code === 'string') { + addCode(this.formatLanguageCode(code)); + } + + fallbackCodes.forEach(function (fc) { + if (codes.indexOf(fc) < 0) addCode(_this.formatLanguageCode(fc)); + }); + + return codes; + }; + + return LanguageUtil; +}(); + +; + +exports.default = LanguageUtil; +},{"./logger":40}],33:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var _logger = require('./logger'); + +var _logger2 = _interopRequireDefault(_logger); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +// definition http://translate.sourceforge.net/wiki/l10n/pluralforms +/* eslint-disable */ +var sets = [{ lngs: ['ach', 'ak', 'am', 'arn', 'br', 'fil', 'gun', 'ln', 'mfe', 'mg', 'mi', 'oc', 'tg', 'ti', 'tr', 'uz', 'wa'], nr: [1, 2], fc: 1 }, { lngs: ['af', 'an', 'ast', 'az', 'bg', 'bn', 'ca', 'da', 'de', 'dev', 'el', 'en', 'eo', 'es', 'es_ar', 'et', 'eu', 'fi', 'fo', 'fur', 'fy', 'gl', 'gu', 'ha', 'he', 'hi', 'hu', 'hy', 'ia', 'it', 'kn', 'ku', 'lb', 'mai', 'ml', 'mn', 'mr', 'nah', 'nap', 'nb', 'ne', 'nl', 'nn', 'no', 'nso', 'pa', 'pap', 'pms', 'ps', 'pt', 'pt_br', 'rm', 'sco', 'se', 'si', 'so', 'son', 'sq', 'sv', 'sw', 'ta', 'te', 'tk', 'ur', 'yo'], nr: [1, 2], fc: 2 }, { lngs: ['ay', 'bo', 'cgg', 'fa', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky', 'lo', 'ms', 'sah', 'su', 'th', 'tt', 'ug', 'vi', 'wo', 'zh'], nr: [1], fc: 3 }, { lngs: ['be', 'bs', 'dz', 'hr', 'ru', 'sr', 'uk'], nr: [1, 2, 5], fc: 4 }, { lngs: ['ar'], nr: [0, 1, 2, 3, 11, 100], fc: 5 }, { lngs: ['cs', 'sk'], nr: [1, 2, 5], fc: 6 }, { lngs: ['csb', 'pl'], nr: [1, 2, 5], fc: 7 }, { lngs: ['cy'], nr: [1, 2, 3, 8], fc: 8 }, { lngs: ['fr'], nr: [1, 2], fc: 9 }, { lngs: ['ga'], nr: [1, 2, 3, 7, 11], fc: 10 }, { lngs: ['gd'], nr: [1, 2, 3, 20], fc: 11 }, { lngs: ['is'], nr: [1, 2], fc: 12 }, { lngs: ['jv'], nr: [0, 1], fc: 13 }, { lngs: ['kw'], nr: [1, 2, 3, 4], fc: 14 }, { lngs: ['lt'], nr: [1, 2, 10], fc: 15 }, { lngs: ['lv'], nr: [1, 2, 0], fc: 16 }, { lngs: ['mk'], nr: [1, 2], fc: 17 }, { lngs: ['mnk'], nr: [0, 1, 2], fc: 18 }, { lngs: ['mt'], nr: [1, 2, 11, 20], fc: 19 }, { lngs: ['or'], nr: [2, 1], fc: 2 }, { lngs: ['ro'], nr: [1, 2, 20], fc: 20 }, { lngs: ['sl'], nr: [5, 1, 2, 3], fc: 21 }]; + +var _rulesPluralsTypes = { + 1: function _(n) { + return Number(n > 1); + }, + 2: function _(n) { + return Number(n != 1); + }, + 3: function _(n) { + return 0; + }, + 4: function _(n) { + return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); + }, + 5: function _(n) { + return Number(n === 0 ? 0 : n == 1 ? 1 : n == 2 ? 2 : n % 100 >= 3 && n % 100 <= 10 ? 3 : n % 100 >= 11 ? 4 : 5); + }, + 6: function _(n) { + return Number(n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2); + }, + 7: function _(n) { + return Number(n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); + }, + 8: function _(n) { + return Number(n == 1 ? 0 : n == 2 ? 1 : n != 8 && n != 11 ? 2 : 3); + }, + 9: function _(n) { + return Number(n >= 2); + }, + 10: function _(n) { + return Number(n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4); + }, + 11: function _(n) { + return Number(n == 1 || n == 11 ? 0 : n == 2 || n == 12 ? 1 : n > 2 && n < 20 ? 2 : 3); + }, + 12: function _(n) { + return Number(n % 10 != 1 || n % 100 == 11); + }, + 13: function _(n) { + return Number(n !== 0); + }, + 14: function _(n) { + return Number(n == 1 ? 0 : n == 2 ? 1 : n == 3 ? 2 : 3); + }, + 15: function _(n) { + return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2); + }, + 16: function _(n) { + return Number(n % 10 == 1 && n % 100 != 11 ? 0 : n !== 0 ? 1 : 2); + }, + 17: function _(n) { + return Number(n == 1 || n % 10 == 1 ? 0 : 1); + }, + 18: function _(n) { + return Number(n == 0 ? 0 : n == 1 ? 1 : 2); + }, + 19: function _(n) { + return Number(n == 1 ? 0 : n === 0 || n % 100 > 1 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3); + }, + 20: function _(n) { + return Number(n == 1 ? 0 : n === 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2); + }, + 21: function _(n) { + return Number(n % 100 == 1 ? 1 : n % 100 == 2 ? 2 : n % 100 == 3 || n % 100 == 4 ? 3 : 0); + } +}; +/* eslint-enable */ + +function createRules() { + var l, + rules = {}; + sets.forEach(function (set) { + set.lngs.forEach(function (l) { + return rules[l] = { + numbers: set.nr, + plurals: _rulesPluralsTypes[set.fc] + }; + }); + }); + return rules; +} + +var PluralResolver = function () { + function PluralResolver(languageUtils) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, PluralResolver); + + this.languageUtils = languageUtils; + this.options = options; + + this.logger = _logger2.default.create('pluralResolver'); + + this.rules = createRules(); + } + + PluralResolver.prototype.addRule = function addRule(lng, obj) { + this.rules[lng] = obj; + }; + + PluralResolver.prototype.getRule = function getRule(code) { + return this.rules[this.languageUtils.getLanguagePartFromCode(code)]; + }; + + PluralResolver.prototype.needsPlural = function needsPlural(code) { + var rule = this.getRule(code); + + return rule && rule.numbers.length <= 1 ? false : true; + }; + + PluralResolver.prototype.getSuffix = function getSuffix(code, count) { + var _this = this; + + var rule = this.getRule(code); + + if (rule) { + var _ret = function () { + if (rule.numbers.length === 1) return { + v: '' + }; // only singular + + var idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count)); + var suffix = rule.numbers[idx]; + + // special treatment for lngs only having singular and plural + if (rule.numbers.length === 2 && rule.numbers[0] === 1) { + if (suffix === 2) { + suffix = 'plural'; + } else if (suffix === 1) { + suffix = ''; + } + } + + var returnSuffix = function returnSuffix() { + return _this.options.prepend && suffix.toString() ? _this.options.prepend + suffix.toString() : suffix.toString(); + }; + + // COMPATIBILITY JSON + // v1 + if (_this.options.compatibilityJSON === 'v1') { + if (suffix === 1) return { + v: '' + }; + if (typeof suffix === 'number') return { + v: '_plural_' + suffix.toString() + }; + return { + v: returnSuffix() + }; + } + // v2 + else if (_this.options.compatibilityJSON === 'v2' || rule.numbers.length === 2 && rule.numbers[0] === 1) { + return { + v: returnSuffix() + }; + } + // v3 - gettext index + else if (rule.numbers.length === 2 && rule.numbers[0] === 1) { + return { + v: returnSuffix() + }; + } + return { + v: _this.options.prepend && idx.toString() ? _this.options.prepend + idx.toString() : idx.toString() + }; + }(); + + if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; + } else { + this.logger.warn('no plural rule found for: ' + code); + return ''; + } + }; + + return PluralResolver; +}(); + +; + +exports.default = PluralResolver; +},{"./logger":40}],34:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _EventEmitter2 = require('./EventEmitter'); + +var _EventEmitter3 = _interopRequireDefault(_EventEmitter2); + +var _utils = require('./utils'); + +var utils = _interopRequireWildcard(_utils); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } + +var ResourceStore = function (_EventEmitter) { + _inherits(ResourceStore, _EventEmitter); + + function ResourceStore() { + var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { ns: ['translation'], defaultNS: 'translation' }; + + _classCallCheck(this, ResourceStore); + + var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); + + _this.data = data; + _this.options = options; + return _this; + } + + ResourceStore.prototype.addNamespaces = function addNamespaces(ns) { + if (this.options.ns.indexOf(ns) < 0) { + this.options.ns.push(ns); + } + }; + + ResourceStore.prototype.removeNamespaces = function removeNamespaces(ns) { + var index = this.options.ns.indexOf(ns); + if (index > -1) { + this.options.ns.splice(index, 1); + } + }; + + ResourceStore.prototype.getResource = function getResource(lng, ns, key) { + var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + + var keySeparator = options.keySeparator || this.options.keySeparator; + if (keySeparator === undefined) keySeparator = '.'; + + var path = [lng, ns]; + if (key && typeof key !== 'string') path = path.concat(key); + if (key && typeof key === 'string') path = path.concat(keySeparator ? key.split(keySeparator) : key); + + if (lng.indexOf('.') > -1) { + path = lng.split('.'); + } + + return utils.getPath(this.data, path); + }; + + ResourceStore.prototype.addResource = function addResource(lng, ns, key, value) { + var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : { silent: false }; + + var keySeparator = this.options.keySeparator; + if (keySeparator === undefined) keySeparator = '.'; + + var path = [lng, ns]; + if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key); + + if (lng.indexOf('.') > -1) { + path = lng.split('.'); + value = ns; + ns = path[1]; + } + + this.addNamespaces(ns); + + utils.setPath(this.data, path, value); + + if (!options.silent) this.emit('added', lng, ns, key, value); + }; + + ResourceStore.prototype.addResources = function addResources(lng, ns, resources) { + for (var m in resources) { + if (typeof resources[m] === 'string') this.addResource(lng, ns, m, resources[m], { silent: true }); + } + this.emit('added', lng, ns, resources); + }; + + ResourceStore.prototype.addResourceBundle = function addResourceBundle(lng, ns, resources, deep, overwrite) { + var path = [lng, ns]; + if (lng.indexOf('.') > -1) { + path = lng.split('.'); + deep = resources; + resources = ns; + ns = path[1]; + } + + this.addNamespaces(ns); + + var pack = utils.getPath(this.data, path) || {}; + + if (deep) { + utils.deepExtend(pack, resources, overwrite); + } else { + pack = _extends({}, pack, resources); + } + + utils.setPath(this.data, path, pack); + + this.emit('added', lng, ns, resources); + }; + + ResourceStore.prototype.removeResourceBundle = function removeResourceBundle(lng, ns) { + if (this.hasResourceBundle(lng, ns)) { + delete this.data[lng][ns]; + } + this.removeNamespaces(ns); + + this.emit('removed', lng, ns); + }; + + ResourceStore.prototype.hasResourceBundle = function hasResourceBundle(lng, ns) { + return this.getResource(lng, ns) !== undefined; + }; + + ResourceStore.prototype.getResourceBundle = function getResourceBundle(lng, ns) { + if (!ns) ns = this.options.defaultNS; + + // TODO: COMPATIBILITY remove extend in v2.1.0 + if (this.options.compatibilityAPI === 'v1') return _extends({}, this.getResource(lng, ns)); + + return this.getResource(lng, ns); + }; + + ResourceStore.prototype.toJSON = function toJSON() { + return this.data; + }; + + return ResourceStore; +}(_EventEmitter3.default); + +exports.default = ResourceStore; +},{"./EventEmitter":30,"./utils":42}],35:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var _logger = require('./logger'); + +var _logger2 = _interopRequireDefault(_logger); + +var _EventEmitter2 = require('./EventEmitter'); + +var _EventEmitter3 = _interopRequireDefault(_EventEmitter2); + +var _postProcessor = require('./postProcessor'); + +var _postProcessor2 = _interopRequireDefault(_postProcessor); + +var _v = require('./compatibility/v1'); + +var compat = _interopRequireWildcard(_v); + +var _utils = require('./utils'); + +var utils = _interopRequireWildcard(_utils); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } + +var Translator = function (_EventEmitter) { + _inherits(Translator, _EventEmitter); + + function Translator(services) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, Translator); + + var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); + + utils.copy(['resourceStore', 'languageUtils', 'pluralResolver', 'interpolator', 'backendConnector'], services, _this); + + _this.options = options; + _this.logger = _logger2.default.create('translator'); + return _this; + } + + Translator.prototype.changeLanguage = function changeLanguage(lng) { + if (lng) this.language = lng; + }; + + Translator.prototype.exists = function exists(key) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { interpolation: {} }; + + if (this.options.compatibilityAPI === 'v1') { + options = compat.convertTOptions(options); + } + + return this.resolve(key, options) !== undefined; + }; + + Translator.prototype.extractFromKey = function extractFromKey(key, options) { + var nsSeparator = options.nsSeparator || this.options.nsSeparator; + if (nsSeparator === undefined) nsSeparator = ':'; + + var namespaces = options.ns || this.options.defaultNS; + if (nsSeparator && key.indexOf(nsSeparator) > -1) { + var parts = key.split(nsSeparator); + namespaces = parts[0]; + key = parts[1]; + } + if (typeof namespaces === 'string') namespaces = [namespaces]; + + return { + key: key, + namespaces: namespaces + }; + }; + + Translator.prototype.translate = function translate(keys) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + if ((typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') { + options = this.options.overloadTranslationOptionHandler(arguments); + } else if (this.options.compatibilityAPI === 'v1') { + options = compat.convertTOptions(options); + } + + // non valid keys handling + if (keys === undefined || keys === null || keys === '') return ''; + if (typeof keys === 'number') keys = String(keys); + if (typeof keys === 'string') keys = [keys]; + + // return key on CIMode + var lng = options.lng || this.language; + if (lng && lng.toLowerCase() === 'cimode') return keys[keys.length - 1]; + + // separators + var keySeparator = options.keySeparator || this.options.keySeparator || '.'; + + // get namespace(s) + + var _extractFromKey = this.extractFromKey(keys[keys.length - 1], options), + key = _extractFromKey.key, + namespaces = _extractFromKey.namespaces; + + var namespace = namespaces[namespaces.length - 1]; + + // resolve from store + var res = this.resolve(keys, options); + + var resType = Object.prototype.toString.apply(res); + var noObject = ['[object Number]', '[object Function]', '[object RegExp]']; + var joinArrays = options.joinArrays !== undefined ? options.joinArrays : this.options.joinArrays; + + // object + if (res && typeof res !== 'string' && noObject.indexOf(resType) < 0 && !(joinArrays && resType === '[object Array]')) { + if (!options.returnObjects && !this.options.returnObjects) { + this.logger.warn('accessing an object - but returnObjects options is not enabled!'); + return this.options.returnedObjectHandler ? this.options.returnedObjectHandler(key, res, options) : 'key \'' + key + ' (' + this.language + ')\' returned an object instead of string.'; + } + + var copy = resType === '[object Array]' ? [] : {}; // apply child translation on a copy + + for (var m in res) { + copy[m] = this.translate('' + key + keySeparator + m, _extends({ joinArrays: false, ns: namespaces }, options)); + } + res = copy; + } + // array special treatment + else if (joinArrays && resType === '[object Array]') { + res = res.join(joinArrays); + if (res) res = this.extendTranslation(res, key, options); + } + // string, empty or null + else { + var usedDefault = false, + usedKey = false; + + // fallback value + if (!this.isValidLookup(res) && options.defaultValue !== undefined) { + usedDefault = true; + res = options.defaultValue; + } + if (!this.isValidLookup(res)) { + usedKey = true; + res = key; + } + + // save missing + if (usedKey || usedDefault) { + this.logger.log('missingKey', lng, namespace, key, res); + + var lngs = []; + var fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language); + if (this.options.saveMissingTo === 'fallback' && fallbackLngs && fallbackLngs[0]) { + for (var i = 0; i < fallbackLngs.length; i++) { + lngs.push(fallbackLngs[i]); + } + } else if (this.options.saveMissingTo === 'all') { + lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language); + } else { + //(this.options.saveMissingTo === 'current' || (this.options.saveMissingTo === 'fallback' && this.options.fallbackLng[0] === false) ) { + lngs.push(options.lng || this.language); + } + + if (this.options.saveMissing) { + if (this.options.missingKeyHandler) { + this.options.missingKeyHandler(lngs, namespace, key, res); + } else if (this.backendConnector && this.backendConnector.saveMissing) { + this.backendConnector.saveMissing(lngs, namespace, key, res); + } + } + + this.emit('missingKey', lngs, namespace, key, res); + } + + // extend + res = this.extendTranslation(res, key, options); + + // append namespace if still key + if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = namespace + ':' + key; + + // parseMissingKeyHandler + if (usedKey && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(res); + } + + // return + return res; + }; + + Translator.prototype.extendTranslation = function extendTranslation(res, key, options) { + var _this2 = this; + + if (options.interpolation) this.interpolator.init(_extends({}, options, { interpolation: _extends({}, this.options.interpolation, options.interpolation) })); + + // interpolate + var data = options.replace && typeof options.replace !== 'string' ? options.replace : options; + if (this.options.interpolation.defaultVariables) data = _extends({}, this.options.interpolation.defaultVariables, data); + res = this.interpolator.interpolate(res, data, this.language); + + // nesting + res = this.interpolator.nest(res, function () { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + return _this2.translate.apply(_this2, args); + }, options); + + if (options.interpolation) this.interpolator.reset(); + + // post process + var postProcess = options.postProcess || this.options.postProcess; + var postProcessorNames = typeof postProcess === 'string' ? [postProcess] : postProcess; + + if (res !== undefined && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) { + res = _postProcessor2.default.handle(postProcessorNames, res, key, options, this); + } + + return res; + }; + + Translator.prototype.resolve = function resolve(keys) { + var _this3 = this; + + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + var found = void 0; + + if (typeof keys === 'string') keys = [keys]; + + // forEach possible key + keys.forEach(function (k) { + if (_this3.isValidLookup(found)) return; + + var _extractFromKey2 = _this3.extractFromKey(k, options), + key = _extractFromKey2.key, + namespaces = _extractFromKey2.namespaces; + + if (_this3.options.fallbackNS) namespaces = namespaces.concat(_this3.options.fallbackNS); + + var needsPluralHandling = options.count !== undefined && typeof options.count !== 'string'; + var needsContextHandling = options.context !== undefined && typeof options.context === 'string' && options.context !== ''; + + var codes = options.lngs ? options.lngs : _this3.languageUtils.toResolveHierarchy(options.lng || _this3.language); + + namespaces.forEach(function (ns) { + if (_this3.isValidLookup(found)) return; + + codes.forEach(function (code) { + if (_this3.isValidLookup(found)) return; + + var finalKey = key; + var finalKeys = [finalKey]; + + var pluralSuffix = void 0; + if (needsPluralHandling) pluralSuffix = _this3.pluralResolver.getSuffix(code, options.count); + + // fallback for plural if context not found + if (needsPluralHandling && needsContextHandling) finalKeys.push(finalKey + pluralSuffix); + + // get key for context if needed + if (needsContextHandling) finalKeys.push(finalKey += '' + _this3.options.contextSeparator + options.context); + + // get key for plural if needed + if (needsPluralHandling) finalKeys.push(finalKey += pluralSuffix); + + // iterate over finalKeys starting with most specific pluralkey (-> contextkey only) -> singularkey only + var possibleKey = void 0; + while (possibleKey = finalKeys.pop()) { + if (_this3.isValidLookup(found)) continue; + found = _this3.getResource(code, ns, possibleKey, options); + } + }); + }); + }); + + return found; + }; + + Translator.prototype.isValidLookup = function isValidLookup(res) { + return res !== undefined && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === ''); + }; + + Translator.prototype.getResource = function getResource(code, ns, key) { + var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; + + return this.resourceStore.getResource(code, ns, key, options); + }; + + return Translator; +}(_EventEmitter3.default); + +exports.default = Translator; +},{"./EventEmitter":30,"./compatibility/v1":36,"./logger":40,"./postProcessor":41,"./utils":42}],36:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.convertAPIOptions = convertAPIOptions; +exports.convertJSONOptions = convertJSONOptions; +exports.convertTOptions = convertTOptions; +exports.appendBackwardsAPI = appendBackwardsAPI; + +var _logger = require('../logger'); + +var _logger2 = _interopRequireDefault(_logger); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function convertInterpolation(options) { + + options.interpolation = { + unescapeSuffix: 'HTML' + }; + + options.interpolation.prefix = options.interpolationPrefix || '__'; + options.interpolation.suffix = options.interpolationSuffix || '__'; + options.interpolation.escapeValue = options.escapeInterpolation || false; + + options.interpolation.nestingPrefix = options.reusePrefix || '$t('; + options.interpolation.nestingSuffix = options.reuseSuffix || ')'; + + return options; +} + +function convertAPIOptions(options) { + if (options.resStore) options.resources = options.resStore; + + if (options.ns && options.ns.defaultNs) { + options.defaultNS = options.ns.defaultNs; + options.ns = options.ns.namespaces; + } else { + options.defaultNS = options.ns || 'translation'; + } + + if (options.fallbackToDefaultNS && options.defaultNS) options.fallbackNS = options.defaultNS; + + options.saveMissing = options.sendMissing; + options.saveMissingTo = options.sendMissingTo || 'current'; + options.returnNull = options.fallbackOnNull ? false : true; + options.returnEmptyString = options.fallbackOnEmpty ? false : true; + options.returnObjects = options.returnObjectTrees; + options.joinArrays = '\n'; + + options.returnedObjectHandler = options.objectTreeKeyHandler; + options.parseMissingKeyHandler = options.parseMissingKey; + options.appendNamespaceToMissingKey = true; + + options.nsSeparator = options.nsseparator; + options.keySeparator = options.keyseparator; + + if (options.shortcutFunction === 'sprintf') { + options.overloadTranslationOptionHandler = function (args) { + var values = []; + + for (var i = 1; i < args.length; i++) { + values.push(args[i]); + } + + return { + postProcess: 'sprintf', + sprintf: values + }; + }; + } + + options.whitelist = options.lngWhitelist; + options.preload = options.preload; + if (options.load === 'current') options.load = 'currentOnly'; + if (options.load === 'unspecific') options.load = 'languageOnly'; + + // backend + options.backend = options.backend || {}; + options.backend.loadPath = options.resGetPath || 'locales/__lng__/__ns__.json'; + options.backend.addPath = options.resPostPath || 'locales/add/__lng__/__ns__'; + options.backend.allowMultiLoading = options.dynamicLoad; + + // cache + options.cache = options.cache || {}; + options.cache.prefix = 'res_'; + options.cache.expirationTime = 7 * 24 * 60 * 60 * 1000; + options.cache.enabled = options.useLocalStorage ? true : false; + + options = convertInterpolation(options); + if (options.defaultVariables) options.interpolation.defaultVariables = options.defaultVariables; + + // TODO: deprecation + // if (options.getAsync === false) throw deprecation error + + return options; +} + +function convertJSONOptions(options) { + options = convertInterpolation(options); + options.joinArrays = '\n'; + + return options; +} + +function convertTOptions(options) { + if (options.interpolationPrefix || options.interpolationSuffix || options.escapeInterpolation) { + options = convertInterpolation(options); + } + + options.nsSeparator = options.nsseparator; + options.keySeparator = options.keyseparator; + + options.returnObjects = options.returnObjectTrees; + + return options; +} + +function appendBackwardsAPI(i18n) { + i18n.lng = function () { + _logger2.default.deprecate('i18next.lng() can be replaced by i18next.language for detected language or i18next.languages for languages ordered by translation lookup.'); + return i18n.services.languageUtils.toResolveHierarchy(i18n.language)[0]; + }; + + i18n.preload = function (lngs, cb) { + _logger2.default.deprecate('i18next.preload() can be replaced with i18next.loadLanguages()'); + i18n.loadLanguages(lngs, cb); + }; + + i18n.setLng = function (lng, options, callback) { + _logger2.default.deprecate('i18next.setLng() can be replaced with i18next.changeLanguage() or i18next.getFixedT() to get a translation function with fixed language or namespace.'); + if (typeof options === 'function') { + callback = options; + options = {}; + } + if (!options) options = {}; + + if (options.fixLng === true) { + if (callback) return callback(null, i18n.getFixedT(lng)); + } + + i18n.changeLanguage(lng, callback); + }; + + i18n.addPostProcessor = function (name, fc) { + _logger2.default.deprecate('i18next.addPostProcessor() can be replaced by i18next.use({ type: \'postProcessor\', name: \'name\', process: fc })'); + i18n.use({ + type: 'postProcessor', + name: name, + process: fc + }); + }; +} +},{"../logger":40}],37:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.get = get; +exports.transformOptions = transformOptions; +function get() { + return { + debug: false, + initImmediate: true, + + ns: ['translation'], + defaultNS: ['translation'], + fallbackLng: ['dev'], + fallbackNS: false, // string or array of namespaces + + whitelist: false, // array with whitelisted languages + nonExplicitWhitelist: false, + load: 'all', // | currentOnly | languageOnly + preload: false, // array with preload languages + + keySeparator: '.', + nsSeparator: ':', + pluralSeparator: '_', + contextSeparator: '_', + + saveMissing: false, // enable to send missing values + saveMissingTo: 'fallback', // 'current' || 'all' + missingKeyHandler: false, // function(lng, ns, key, fallbackValue) -> override if prefer on handling + + postProcess: false, // string or array of postProcessor names + returnNull: true, // allows null value as valid translation + returnEmptyString: true, // allows empty string value as valid translation + returnObjects: false, + joinArrays: false, // or string to join array + returnedObjectHandler: function returnedObjectHandler() {}, // function(key, value, options) triggered if key returns object but returnObjects is set to false + parseMissingKeyHandler: false, // function(key) parsed a key that was not found in t() before returning + appendNamespaceToMissingKey: false, + overloadTranslationOptionHandler: function overloadTranslationOptionHandler(args) { + return { defaultValue: args[1] }; + }, + + interpolation: { + escapeValue: true, + format: function format(value, _format, lng) { + return value; + }, + prefix: '{{', + suffix: '}}', + formatSeparator: ',', + // prefixEscaped: '{{', + // suffixEscaped: '}}', + // unescapeSuffix: '', + unescapePrefix: '-', + + nestingPrefix: '$t(', + nestingSuffix: ')', + // nestingPrefixEscaped: '$t(', + // nestingSuffixEscaped: ')', + defaultVariables: undefined // object that can have values to interpolate on - extends passed in interpolation data + } + }; +} + +function transformOptions(options) { + // create namespace object if namespace is passed in as string + if (typeof options.ns === 'string') options.ns = [options.ns]; + if (typeof options.fallbackLng === 'string') options.fallbackLng = [options.fallbackLng]; + if (typeof options.fallbackNS === 'string') options.fallbackNS = [options.fallbackNS]; + + // extend whitelist with cimode + if (options.whitelist && options.whitelist.indexOf('cimode') < 0) options.whitelist.push('cimode'); + + return options; +} +},{}],38:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +var _logger = require('./logger'); + +var _logger2 = _interopRequireDefault(_logger); + +var _EventEmitter2 = require('./EventEmitter'); + +var _EventEmitter3 = _interopRequireDefault(_EventEmitter2); + +var _ResourceStore = require('./ResourceStore'); + +var _ResourceStore2 = _interopRequireDefault(_ResourceStore); + +var _Translator = require('./Translator'); + +var _Translator2 = _interopRequireDefault(_Translator); + +var _LanguageUtils = require('./LanguageUtils'); + +var _LanguageUtils2 = _interopRequireDefault(_LanguageUtils); + +var _PluralResolver = require('./PluralResolver'); + +var _PluralResolver2 = _interopRequireDefault(_PluralResolver); + +var _Interpolator = require('./Interpolator'); + +var _Interpolator2 = _interopRequireDefault(_Interpolator); + +var _BackendConnector = require('./BackendConnector'); + +var _BackendConnector2 = _interopRequireDefault(_BackendConnector); + +var _CacheConnector = require('./CacheConnector'); + +var _CacheConnector2 = _interopRequireDefault(_CacheConnector); + +var _defaults2 = require('./defaults'); + +var _postProcessor = require('./postProcessor'); + +var _postProcessor2 = _interopRequireDefault(_postProcessor); + +var _v = require('./compatibility/v1'); + +var compat = _interopRequireWildcard(_v); + +function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } + +var I18n = function (_EventEmitter) { + _inherits(I18n, _EventEmitter); + + function I18n() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var callback = arguments[1]; + + _classCallCheck(this, I18n); + + var _this = _possibleConstructorReturn(this, _EventEmitter.call(this)); + + _this.options = (0, _defaults2.transformOptions)(options); + _this.services = {}; + _this.logger = _logger2.default; + _this.modules = {}; + + if (callback && !_this.isInitialized) _this.init(options, callback); + return _this; + } + + I18n.prototype.init = function init(options, callback) { + var _this2 = this; + + if (typeof options === 'function') { + callback = options; + options = {}; + } + if (!options) options = {}; + + if (options.compatibilityAPI === 'v1') { + this.options = _extends({}, (0, _defaults2.get)(), (0, _defaults2.transformOptions)(compat.convertAPIOptions(options)), {}); + } else if (options.compatibilityJSON === 'v1') { + this.options = _extends({}, (0, _defaults2.get)(), (0, _defaults2.transformOptions)(compat.convertJSONOptions(options)), {}); + } else { + this.options = _extends({}, (0, _defaults2.get)(), this.options, (0, _defaults2.transformOptions)(options)); + } + if (!callback) callback = function callback() {}; + + function createClassOnDemand(ClassOrObject) { + if (!ClassOrObject) return; + if (typeof ClassOrObject === 'function') return new ClassOrObject(); + return ClassOrObject; + } + + // init services + if (!this.options.isClone) { + if (this.modules.logger) { + _logger2.default.init(createClassOnDemand(this.modules.logger), this.options); + } else { + _logger2.default.init(null, this.options); + } + + var lu = new _LanguageUtils2.default(this.options); + this.store = new _ResourceStore2.default(this.options.resources, this.options); + + var s = this.services; + s.logger = _logger2.default; + s.resourceStore = this.store; + s.resourceStore.on('added removed', function (lng, ns) { + s.cacheConnector.save(); + }); + s.languageUtils = lu; + s.pluralResolver = new _PluralResolver2.default(lu, { prepend: this.options.pluralSeparator, compatibilityJSON: this.options.compatibilityJSON }); + s.interpolator = new _Interpolator2.default(this.options); + + s.backendConnector = new _BackendConnector2.default(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options); + // pipe events from backendConnector + s.backendConnector.on('*', function (event) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + _this2.emit.apply(_this2, [event].concat(args)); + }); + + s.backendConnector.on('loaded', function (loaded) { + s.cacheConnector.save(); + }); + + s.cacheConnector = new _CacheConnector2.default(createClassOnDemand(this.modules.cache), s.resourceStore, s, this.options); + // pipe events from backendConnector + s.cacheConnector.on('*', function (event) { + for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { + args[_key2 - 1] = arguments[_key2]; + } + + _this2.emit.apply(_this2, [event].concat(args)); + }); + + if (this.modules.languageDetector) { + s.languageDetector = createClassOnDemand(this.modules.languageDetector); + s.languageDetector.init(s, this.options.detection, this.options); + } + + this.translator = new _Translator2.default(this.services, this.options); + // pipe events from translator + this.translator.on('*', function (event) { + for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { + args[_key3 - 1] = arguments[_key3]; + } + + _this2.emit.apply(_this2, [event].concat(args)); + }); + } + + // append api + var storeApi = ['getResource', 'addResource', 'addResources', 'addResourceBundle', 'removeResourceBundle', 'hasResourceBundle', 'getResourceBundle']; + storeApi.forEach(function (fcName) { + _this2[fcName] = function () { + return this.store[fcName].apply(this.store, arguments); + }; + }); + + // TODO: COMPATIBILITY remove this + if (this.options.compatibilityAPI === 'v1') compat.appendBackwardsAPI(this); + + var load = function load() { + _this2.changeLanguage(_this2.options.lng, function (err, t) { + _this2.emit('initialized', _this2.options); + _this2.logger.log('initialized', _this2.options); + + callback(err, t); + }); + }; + + if (this.options.resources || !this.options.initImmediate) { + load(); + } else { + setTimeout(load, 0); + } + + return this; + }; + + I18n.prototype.loadResources = function loadResources(callback) { + var _this3 = this; + + if (!callback) callback = function callback() {}; + + if (!this.options.resources) { + var _ret = function () { + if (_this3.language && _this3.language.toLowerCase() === 'cimode') return { + v: callback() + }; // avoid loading resources for cimode + + var toLoad = []; + + var append = function append(lng) { + var lngs = _this3.services.languageUtils.toResolveHierarchy(lng); + lngs.forEach(function (l) { + if (toLoad.indexOf(l) < 0) toLoad.push(l); + }); + }; + + append(_this3.language); + + if (_this3.options.preload) { + _this3.options.preload.forEach(function (l) { + append(l); + }); + } + + _this3.services.cacheConnector.load(toLoad, _this3.options.ns, function () { + _this3.services.backendConnector.load(toLoad, _this3.options.ns, callback); + }); + }(); + + if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; + } else { + callback(null); + } + }; + + I18n.prototype.reloadResources = function reloadResources(lngs, ns) { + if (!lngs) lngs = this.languages; + if (!ns) ns = this.options.ns; + this.services.backendConnector.reload(lngs, ns); + }; + + I18n.prototype.use = function use(module) { + if (module.type === 'backend') { + this.modules.backend = module; + } + + if (module.type === 'cache') { + this.modules.cache = module; + } + + if (module.type === 'logger' || module.log && module.warn && module.warn) { + this.modules.logger = module; + } + + if (module.type === 'languageDetector') { + this.modules.languageDetector = module; + } + + if (module.type === 'postProcessor') { + _postProcessor2.default.addPostProcessor(module); + } + + return this; + }; + + I18n.prototype.changeLanguage = function changeLanguage(lng, callback) { + var _this4 = this; + + var done = function done(err) { + if (lng) { + _this4.emit('languageChanged', lng); + _this4.logger.log('languageChanged', lng); + } + + if (callback) callback(err, function () { + for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { + args[_key4] = arguments[_key4]; + } + + return _this4.t.apply(_this4, args); + }); + }; + + if (!lng && this.services.languageDetector) lng = this.services.languageDetector.detect(); + + if (lng) { + this.language = lng; + this.languages = this.services.languageUtils.toResolveHierarchy(lng); + + this.translator.changeLanguage(lng); + + if (this.services.languageDetector) this.services.languageDetector.cacheUserLanguage(lng); + } + + this.loadResources(function (err) { + done(err); + }); + }; + + I18n.prototype.getFixedT = function getFixedT(lng, ns) { + var _this5 = this; + + var fixedT = function fixedT(key, options) { + options = options || {}; + options.lng = options.lng || fixedT.lng; + options.ns = options.ns || fixedT.ns; + return _this5.t(key, options); + }; + fixedT.lng = lng; + fixedT.ns = ns; + return fixedT; + }; + + I18n.prototype.t = function t() { + return this.translator && this.translator.translate.apply(this.translator, arguments); + }; + + I18n.prototype.exists = function exists() { + return this.translator && this.translator.exists.apply(this.translator, arguments); + }; + + I18n.prototype.setDefaultNamespace = function setDefaultNamespace(ns) { + this.options.defaultNS = ns; + }; + + I18n.prototype.loadNamespaces = function loadNamespaces(ns, callback) { + var _this6 = this; + + if (!this.options.ns) return callback && callback(); + if (typeof ns === 'string') ns = [ns]; + + ns.forEach(function (n) { + if (_this6.options.ns.indexOf(n) < 0) _this6.options.ns.push(n); + }); + + this.loadResources(callback); + }; + + I18n.prototype.loadLanguages = function loadLanguages(lngs, callback) { + if (typeof lngs === 'string') lngs = [lngs]; + var preloaded = this.options.preload || []; + + var newLngs = lngs.filter(function (lng) { + return preloaded.indexOf(lng) < 0; + }); + // Exit early if all given languages are already preloaded + if (!newLngs.length) return callback(); + + this.options.preload = preloaded.concat(newLngs); + this.loadResources(callback); + }; + + I18n.prototype.dir = function dir(lng) { + if (!lng) lng = this.language; + if (!lng) return 'rtl'; + + var rtlLngs = ['ar', 'shu', 'sqr', 'ssh', 'xaa', 'yhd', 'yud', 'aao', 'abh', 'abv', 'acm', 'acq', 'acw', 'acx', 'acy', 'adf', 'ads', 'aeb', 'aec', 'afb', 'ajp', 'apc', 'apd', 'arb', 'arq', 'ars', 'ary', 'arz', 'auz', 'avl', 'ayh', 'ayl', 'ayn', 'ayp', 'bbz', 'pga', 'he', 'iw', 'ps', 'pbt', 'pbu', 'pst', 'prp', 'prd', 'ur', 'ydd', 'yds', 'yih', 'ji', 'yi', 'hbo', 'men', 'xmn', 'fa', 'jpr', 'peo', 'pes', 'prs', 'dv', 'sam']; + + return rtlLngs.indexOf(this.services.languageUtils.getLanguagePartFromCode(lng)) >= 0 ? 'rtl' : 'ltr'; + }; + + I18n.prototype.createInstance = function createInstance() { + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var callback = arguments[1]; + + return new I18n(options, callback); + }; + + I18n.prototype.cloneInstance = function cloneInstance() { + var _this7 = this; + + var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var callback = arguments[1]; + + var clone = new I18n(_extends({}, options, this.options, { isClone: true }), callback); + var membersToCopy = ['store', 'services', 'language']; + membersToCopy.forEach(function (m) { + clone[m] = _this7[m]; + }); + clone.translator = new _Translator2.default(clone.services, clone.options); + clone.translator.on('*', function (event) { + for (var _len5 = arguments.length, args = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) { + args[_key5 - 1] = arguments[_key5]; + } + + clone.emit.apply(clone, [event].concat(args)); + }); + + return clone; + }; + + return I18n; +}(_EventEmitter3.default); + +exports.default = new I18n(); +},{"./BackendConnector":28,"./CacheConnector":29,"./EventEmitter":30,"./Interpolator":31,"./LanguageUtils":32,"./PluralResolver":33,"./ResourceStore":34,"./Translator":35,"./compatibility/v1":36,"./defaults":37,"./logger":40,"./postProcessor":41}],39:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _i18next = require('./i18next'); + +var _i18next2 = _interopRequireDefault(_i18next); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +exports.default = _i18next2.default; +},{"./i18next":38}],40:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var consoleLogger = { + type: 'logger', + + log: function log(args) { + this._output('log', args); + }, + warn: function warn(args) { + this._output('warn', args); + }, + error: function error(args) { + this._output('error', args); + }, + _output: function _output(type, args) { + if (console && console[type]) console[type].apply(console, Array.prototype.slice.call(args)); + } +}; + +var Logger = function () { + function Logger(concreteLogger) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + _classCallCheck(this, Logger); + + this.subs = []; + this.init(concreteLogger, options); + } + + Logger.prototype.init = function init(concreteLogger) { + var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; + + this.prefix = options.prefix || 'i18next:'; + this.logger = concreteLogger || consoleLogger; + this.options = options; + this.debug = options.debug === false ? false : true; + }; + + Logger.prototype.setDebug = function setDebug(bool) { + this.debug = bool; + this.subs.forEach(function (sub) { + sub.setDebug(bool); + }); + }; + + Logger.prototype.log = function log() { + this.forward(arguments, 'log', '', true); + }; + + Logger.prototype.warn = function warn() { + this.forward(arguments, 'warn', '', true); + }; + + Logger.prototype.error = function error() { + this.forward(arguments, 'error', ''); + }; + + Logger.prototype.deprecate = function deprecate() { + this.forward(arguments, 'warn', 'WARNING DEPRECATED: ', true); + }; + + Logger.prototype.forward = function forward(args, lvl, prefix, debugOnly) { + if (debugOnly && !this.debug) return; + if (typeof args[0] === 'string') args[0] = prefix + this.prefix + ' ' + args[0]; + this.logger[lvl](args); + }; + + Logger.prototype.create = function create(moduleName) { + var sub = new Logger(this.logger, _extends({ prefix: this.prefix + ':' + moduleName + ':' }, this.options)); + this.subs.push(sub); + + return sub; + }; + + // createInstance(options = {}) { + // return new Logger(options, callback); + // } + + return Logger; +}(); + +; + +exports.default = new Logger(); +},{}],41:[function(require,module,exports){ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = { + + processors: {}, + + addPostProcessor: function addPostProcessor(module) { + this.processors[module.name] = module; + }, + handle: function handle(processors, value, key, options, translator) { + var _this = this; + + processors.forEach(function (processor) { + if (_this.processors[processor]) value = _this.processors[processor].process(value, key, options, translator); + }); + + return value; + } +}; +},{}],42:[function(require,module,exports){ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.makeString = makeString; +exports.copy = copy; +exports.setPath = setPath; +exports.pushPath = pushPath; +exports.getPath = getPath; +exports.deepExtend = deepExtend; +exports.regexEscape = regexEscape; +exports.escape = escape; +function makeString(object) { + if (object == null) return ''; + return '' + object; +} + +function copy(a, s, t) { + a.forEach(function (m) { + if (s[m]) t[m] = s[m]; + }); +} + +function getLastOfPath(object, path, Empty) { + function cleanKey(key) { + return key && key.indexOf('###') > -1 ? key.replace(/###/g, '.') : key; + } + + var stack = typeof path !== 'string' ? [].concat(path) : path.split('.'); + while (stack.length > 1) { + if (!object) return {}; + + var key = cleanKey(stack.shift()); + if (!object[key] && Empty) object[key] = new Empty(); + object = object[key]; + } + + if (!object) return {}; + return { + obj: object, + k: cleanKey(stack.shift()) + }; +} + +function setPath(object, path, newValue) { + var _getLastOfPath = getLastOfPath(object, path, Object), + obj = _getLastOfPath.obj, + k = _getLastOfPath.k; + + obj[k] = newValue; +} + +function pushPath(object, path, newValue, concat) { + var _getLastOfPath2 = getLastOfPath(object, path, Object), + obj = _getLastOfPath2.obj, + k = _getLastOfPath2.k; + + obj[k] = obj[k] || []; + if (concat) obj[k] = obj[k].concat(newValue); + if (!concat) obj[k].push(newValue); +} + +function getPath(object, path) { + var _getLastOfPath3 = getLastOfPath(object, path), + obj = _getLastOfPath3.obj, + k = _getLastOfPath3.k; + + if (!obj) return undefined; + return obj[k]; +} + +function deepExtend(target, source, overwrite) { + for (var prop in source) { + if (prop in target) { + // If we reached a leaf string in target or source then replace with source or skip depending on the 'overwrite' switch + if (typeof target[prop] === 'string' || target[prop] instanceof String || typeof source[prop] === 'string' || source[prop] instanceof String) { + if (overwrite) target[prop] = source[prop]; + } else { + deepExtend(target[prop], source[prop], overwrite); + } + } else { + target[prop] = source[prop]; + } + }return target; +} + +function regexEscape(str) { + return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); +} + +/* eslint-disable */ +var _entityMap = { + "&": "&", + "<": "<", + ">": ">", + '"': '"', + "'": ''', + "/": '/' +}; +/* eslint-enable */ + +function escape(data) { + if (typeof data === 'string') { + return data.replace(/[&<>"'\/]/g, function (s) { + return _entityMap[s]; + }); + } else { + return data; + } +} +},{}],43:[function(require,module,exports){ +module.exports = require('./dist/commonjs/index.js').default; + +},{"./dist/commonjs/index.js":39}],44:[function(require,module,exports){ +exports.read = function (buffer, offset, isLE, mLen, nBytes) { + var e, m + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var nBits = -7 + var i = isLE ? (nBytes - 1) : 0 + var d = isLE ? -1 : 1 + var s = buffer[offset + i] + + i += d + + e = s & ((1 << (-nBits)) - 1) + s >>= (-nBits) + nBits += eLen + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + m = e & ((1 << (-nBits)) - 1) + e >>= (-nBits) + nBits += mLen + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + if (e === 0) { + e = 1 - eBias + } else if (e === eMax) { + return m ? NaN : ((s ? -1 : 1) * Infinity) + } else { + m = m + Math.pow(2, mLen) + e = e - eBias + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen) +} + +exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) + var i = isLE ? 0 : (nBytes - 1) + var d = isLE ? 1 : -1 + var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 + + value = Math.abs(value) + + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0 + e = eMax + } else { + e = Math.floor(Math.log(value) / Math.LN2) + if (value * (c = Math.pow(2, -e)) < 1) { + e-- + c *= 2 + } + if (e + eBias >= 1) { + value += rt / c + } else { + value += rt * Math.pow(2, 1 - eBias) + } + if (value * c >= 2) { + e++ + c /= 2 + } + + if (e + eBias >= eMax) { + m = 0 + e = eMax + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen) + e = e + eBias + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) + e = 0 + } + } + + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} + + e = (e << mLen) | m + eLen += mLen + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + + buffer[offset + i - d] |= s * 128 +} + +},{}],45:[function(require,module,exports){ +(function (global){ +'use strict'; +var Mutation = global.MutationObserver || global.WebKitMutationObserver; + +var scheduleDrain; + +{ + if (Mutation) { + var called = 0; + var observer = new Mutation(nextTick); + var element = global.document.createTextNode(''); + observer.observe(element, { + characterData: true + }); + scheduleDrain = function () { + element.data = (called = ++called % 2); + }; + } else if (!global.setImmediate && typeof global.MessageChannel !== 'undefined') { + var channel = new global.MessageChannel(); + channel.port1.onmessage = nextTick; + scheduleDrain = function () { + channel.port2.postMessage(0); + }; + } else if ('document' in global && 'onreadystatechange' in global.document.createElement('script')) { + scheduleDrain = function () { + + // Create a