diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6247d1a --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +sandbox.js +test/create_data.js + diff --git a/README.md b/README.md index d547962..0ccc11a 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,18 @@ var pathData = converter.convert( **Options for each geojson:** **output, exlpode, attributes, pointAsCircle, r** if passed in **convert** function along with each geojson overrides the main options - +## Developing +Once you run + +```npm isntall``` + +then for running test + +```npm run test``` + +to create build + +```npm run build``` + ##License This project is licensed under the terms of the MIT license. diff --git a/dist/geojson2svg.js b/dist/geojson2svg.js index 14a449e..6d43397 100644 --- a/dist/geojson2svg.js +++ b/dist/geojson2svg.js @@ -1,167 +1,4 @@ !function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.geojson2svg=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o - * License: MIT - * - * `npm install buffer` - */ - -var base64 = _dereq_('base64-js') -var ieee754 = _dereq_('ieee754') - -exports.Buffer = Buffer -exports.SlowBuffer = Buffer -exports.INSPECT_MAX_BYTES = 50 -Buffer.poolSize = 8192 - -/** - * If `Buffer._useTypedArrays`: - * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (compatible down to IE6) - */ -Buffer._useTypedArrays = (function () { - // Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+, - // Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding - // properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support - // because we need to be able to add all the node Buffer API methods. This is an issue - // in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438 - try { - var buf = new ArrayBuffer(0) - var arr = new Uint8Array(buf) - arr.foo = function () { return 42 } - return 42 === arr.foo() && - typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray` - } catch (e) { - return false - } -})() - -/** - * Class: Buffer - * ============= - * - * The Buffer constructor returns instances of `Uint8Array` that are augmented - * with function properties for all the node `Buffer` API functions. We use - * `Uint8Array` so that square bracket notation works as expected -- it returns - * a single octet. - * - * By augmenting the instances, we can avoid modifying the `Uint8Array` - * prototype. - */ -function Buffer (subject, encoding, noZero) { - if (!(this instanceof Buffer)) - return new Buffer(subject, encoding, noZero) - - var type = typeof subject - - // Workaround: node's base64 implementation allows for non-padded strings - // while base64-js does not. - if (encoding === 'base64' && type === 'string') { - subject = stringtrim(subject) - while (subject.length % 4 !== 0) { - subject = subject + '=' - } - } - - // Find the length - var length - if (type === 'number') - length = coerce(subject) - else if (type === 'string') - length = Buffer.byteLength(subject, encoding) - else if (type === 'object') - length = coerce(subject.length) // assume that object is array-like - else - throw new Error('First argument needs to be a number, array or string.') - - var buf - if (Buffer._useTypedArrays) { - // Preferred: Return an augmented `Uint8Array` instance for best performance - buf = Buffer._augment(new Uint8Array(length)) - } else { - // Fallback: Return THIS instance of Buffer (created by `new`) - buf = this - buf.length = length - buf._isBuffer = true - } - - var i - if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') { - // Speed optimization -- use set if we're copying from a typed array - buf._set(subject) - } else if (isArrayish(subject)) { - // Treat array-ish objects as a byte array - for (i = 0; i < length; i++) { - if (Buffer.isBuffer(subject)) - buf[i] = subject.readUInt8(i) - else - buf[i] = subject[i] - } - } else if (type === 'string') { - buf.write(subject, 0, encoding) - } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) { - for (i = 0; i < length; i++) { - buf[i] = 0 - } - } - - return buf -} - -// STATIC METHODS -// ============== - -Buffer.isEncoding = function (encoding) { - switch (String(encoding).toLowerCase()) { - case 'hex': - case 'utf8': - case 'utf-8': - case 'ascii': - case 'binary': - case 'base64': - case 'raw': - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - return true - default: - return false - } -} - -Buffer.isBuffer = function (b) { - return !!(b !== null && b !== undefined && b._isBuffer) -} - -Buffer.byteLength = function (str, encoding) { - var ret - str = str + '' - switch (encoding || 'utf8') { - case 'hex': - ret = str.length / 2 - break - case 'utf8': - case 'utf-8': - ret = utf8ToBytes(str).length - break - case 'ascii': - case 'binary': - case 'raw': - ret = str.length - break - case 'base64': - ret = base64ToBytes(str).length - break - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - ret = str.length * 2 - break - default: - throw new Error('Unknown encoding') - } - return ret -} - -Buffer.concat = function (list, totalLength) { - assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\n' + - 'list should be an Array.') - - if (list.length === 0) { - return new Buffer(0) - } else if (list.length === 1) { - return list[0] - } - - var i - if (typeof totalLength !== 'number') { - totalLength = 0 - for (i = 0; i < list.length; i++) { - totalLength += list[i].length - } - } - - var buf = new Buffer(totalLength) - var pos = 0 - for (i = 0; i < list.length; i++) { - var item = list[i] - item.copy(buf, pos) - pos += item.length - } - return buf -} - -// BUFFER INSTANCE METHODS -// ======================= - -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 - assert(strLen % 2 === 0, 'Invalid hex string') - - if (length > strLen / 2) { - length = strLen / 2 - } - for (var i = 0; i < length; i++) { - var byte = parseInt(string.substr(i * 2, 2), 16) - assert(!isNaN(byte), 'Invalid hex string') - buf[offset + i] = byte - } - Buffer._charsWritten = i * 2 - return i -} - -function _utf8Write (buf, string, offset, length) { - var charsWritten = Buffer._charsWritten = - blitBuffer(utf8ToBytes(string), buf, offset, length) - return charsWritten -} - -function _asciiWrite (buf, string, offset, length) { - var charsWritten = Buffer._charsWritten = - blitBuffer(asciiToBytes(string), buf, offset, length) - return charsWritten -} - -function _binaryWrite (buf, string, offset, length) { - return _asciiWrite(buf, string, offset, length) -} - -function _base64Write (buf, string, offset, length) { - var charsWritten = Buffer._charsWritten = - blitBuffer(base64ToBytes(string), buf, offset, length) - return charsWritten -} - -function _utf16leWrite (buf, string, offset, length) { - var charsWritten = Buffer._charsWritten = - blitBuffer(utf16leToBytes(string), buf, offset, length) - return charsWritten -} - -Buffer.prototype.write = function (string, offset, length, encoding) { - // Support both (string, offset, length, encoding) - // and the legacy (string, encoding, offset, length) - if (isFinite(offset)) { - if (!isFinite(length)) { - encoding = length - length = undefined - } - } else { // legacy - var swap = encoding - encoding = offset - offset = length - length = swap - } - - offset = Number(offset) || 0 - var remaining = this.length - offset - if (!length) { - length = remaining - } else { - length = Number(length) - if (length > remaining) { - length = remaining - } - } - encoding = String(encoding || 'utf8').toLowerCase() - - var ret - switch (encoding) { - case 'hex': - ret = _hexWrite(this, string, offset, length) - break - case 'utf8': - case 'utf-8': - ret = _utf8Write(this, string, offset, length) - break - case 'ascii': - ret = _asciiWrite(this, string, offset, length) - break - case 'binary': - ret = _binaryWrite(this, string, offset, length) - break - case 'base64': - ret = _base64Write(this, string, offset, length) - break - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - ret = _utf16leWrite(this, string, offset, length) - break - default: - throw new Error('Unknown encoding') - } - return ret -} - -Buffer.prototype.toString = function (encoding, start, end) { - var self = this - - encoding = String(encoding || 'utf8').toLowerCase() - start = Number(start) || 0 - end = (end !== undefined) - ? Number(end) - : end = self.length - - // Fastpath empty strings - if (end === start) - return '' - - var ret - switch (encoding) { - case 'hex': - ret = _hexSlice(self, start, end) - break - case 'utf8': - case 'utf-8': - ret = _utf8Slice(self, start, end) - break - case 'ascii': - ret = _asciiSlice(self, start, end) - break - case 'binary': - ret = _binarySlice(self, start, end) - break - case 'base64': - ret = _base64Slice(self, start, end) - break - case 'ucs2': - case 'ucs-2': - case 'utf16le': - case 'utf-16le': - ret = _utf16leSlice(self, start, end) - break - default: - throw new Error('Unknown encoding') - } - return ret -} - -Buffer.prototype.toJSON = function () { - return { - type: 'Buffer', - data: Array.prototype.slice.call(this._arr || this, 0) - } -} - -// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) -Buffer.prototype.copy = function (target, target_start, start, end) { - var source = this - - if (!start) start = 0 - if (!end && end !== 0) end = this.length - if (!target_start) target_start = 0 - - // Copy 0 bytes; we're done - if (end === start) return - if (target.length === 0 || source.length === 0) return - - // Fatal error conditions - assert(end >= start, 'sourceEnd < sourceStart') - assert(target_start >= 0 && target_start < target.length, - 'targetStart out of bounds') - assert(start >= 0 && start < source.length, 'sourceStart out of bounds') - assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds') - - // Are we oob? - if (end > this.length) - end = this.length - if (target.length - target_start < end - start) - end = target.length - target_start + start - - var len = end - start - - if (len < 100 || !Buffer._useTypedArrays) { - for (var i = 0; i < len; i++) - target[i + target_start] = this[i + start] - } else { - target._set(this.subarray(start, start + len), target_start) - } -} - -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) { - var res = '' - var tmp = '' - end = Math.min(buf.length, end) - - for (var i = start; i < end; i++) { - if (buf[i] <= 0x7F) { - res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i]) - tmp = '' - } else { - tmp += '%' + buf[i].toString(16) - } - } - - return res + decodeUtf8Char(tmp) -} - -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]) - return ret -} - -function _binarySlice (buf, start, end) { - return _asciiSlice(buf, start, end) -} - -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 (start, end) { - var len = this.length - start = clamp(start, len, 0) - end = clamp(end, len, len) - - if (Buffer._useTypedArrays) { - return Buffer._augment(this.subarray(start, end)) - } else { - var sliceLen = end - start - var newBuf = new Buffer(sliceLen, undefined, true) - for (var i = 0; i < sliceLen; i++) { - newBuf[i] = this[i + start] - } - return newBuf - } -} - -// `get` will be removed in Node 0.13+ -Buffer.prototype.get = function (offset) { - console.log('.get() is deprecated. Access using array indexes instead.') - return this.readUInt8(offset) -} - -// `set` will be removed in Node 0.13+ -Buffer.prototype.set = function (v, offset) { - console.log('.set() is deprecated. Access using array indexes instead.') - return this.writeUInt8(v, offset) -} - -Buffer.prototype.readUInt8 = function (offset, noAssert) { - if (!noAssert) { - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset < this.length, 'Trying to read beyond buffer length') - } - - if (offset >= this.length) - return - - return this[offset] -} - -function _readUInt16 (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 1 < buf.length, 'Trying to read beyond buffer length') - } - - var len = buf.length - if (offset >= len) - return - - var val - if (littleEndian) { - val = buf[offset] - if (offset + 1 < len) - val |= buf[offset + 1] << 8 - } else { - val = buf[offset] << 8 - if (offset + 1 < len) - val |= buf[offset + 1] - } - return val -} - -Buffer.prototype.readUInt16LE = function (offset, noAssert) { - return _readUInt16(this, offset, true, noAssert) -} - -Buffer.prototype.readUInt16BE = function (offset, noAssert) { - return _readUInt16(this, offset, false, noAssert) -} - -function _readUInt32 (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') - } - - var len = buf.length - if (offset >= len) - return - - var val - if (littleEndian) { - if (offset + 2 < len) - val = buf[offset + 2] << 16 - if (offset + 1 < len) - val |= buf[offset + 1] << 8 - val |= buf[offset] - if (offset + 3 < len) - val = val + (buf[offset + 3] << 24 >>> 0) - } else { - if (offset + 1 < len) - val = buf[offset + 1] << 16 - if (offset + 2 < len) - val |= buf[offset + 2] << 8 - if (offset + 3 < len) - val |= buf[offset + 3] - val = val + (buf[offset] << 24 >>> 0) - } - return val -} - -Buffer.prototype.readUInt32LE = function (offset, noAssert) { - return _readUInt32(this, offset, true, noAssert) -} - -Buffer.prototype.readUInt32BE = function (offset, noAssert) { - return _readUInt32(this, offset, false, noAssert) -} - -Buffer.prototype.readInt8 = function (offset, noAssert) { - if (!noAssert) { - assert(offset !== undefined && offset !== null, - 'missing offset') - assert(offset < this.length, 'Trying to read beyond buffer length') - } - - if (offset >= this.length) - return - - var neg = this[offset] & 0x80 - if (neg) - return (0xff - this[offset] + 1) * -1 - else - return this[offset] -} - -function _readInt16 (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 1 < buf.length, 'Trying to read beyond buffer length') - } - - var len = buf.length - if (offset >= len) - return - - var val = _readUInt16(buf, offset, littleEndian, true) - var neg = val & 0x8000 - if (neg) - return (0xffff - val + 1) * -1 - else - return val -} - -Buffer.prototype.readInt16LE = function (offset, noAssert) { - return _readInt16(this, offset, true, noAssert) -} - -Buffer.prototype.readInt16BE = function (offset, noAssert) { - return _readInt16(this, offset, false, noAssert) -} - -function _readInt32 (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') - } - - var len = buf.length - if (offset >= len) - return - - var val = _readUInt32(buf, offset, littleEndian, true) - var neg = val & 0x80000000 - if (neg) - return (0xffffffff - val + 1) * -1 - else - return val -} - -Buffer.prototype.readInt32LE = function (offset, noAssert) { - return _readInt32(this, offset, true, noAssert) -} - -Buffer.prototype.readInt32BE = function (offset, noAssert) { - return _readInt32(this, offset, false, noAssert) -} - -function _readFloat (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset + 3 < buf.length, 'Trying to read beyond buffer length') - } - - return ieee754.read(buf, offset, littleEndian, 23, 4) -} - -Buffer.prototype.readFloatLE = function (offset, noAssert) { - return _readFloat(this, offset, true, noAssert) -} - -Buffer.prototype.readFloatBE = function (offset, noAssert) { - return _readFloat(this, offset, false, noAssert) -} - -function _readDouble (buf, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset + 7 < buf.length, 'Trying to read beyond buffer length') - } - - return ieee754.read(buf, offset, littleEndian, 52, 8) -} - -Buffer.prototype.readDoubleLE = function (offset, noAssert) { - return _readDouble(this, offset, true, noAssert) -} - -Buffer.prototype.readDoubleBE = function (offset, noAssert) { - return _readDouble(this, offset, false, noAssert) -} - -Buffer.prototype.writeUInt8 = function (value, offset, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset < this.length, 'trying to write beyond buffer length') - verifuint(value, 0xff) - } - - if (offset >= this.length) return - - this[offset] = value -} - -function _writeUInt16 (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 1 < buf.length, 'trying to write beyond buffer length') - verifuint(value, 0xffff) - } - - var len = buf.length - if (offset >= len) - return - - for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) { - buf[offset + i] = - (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } -} - -Buffer.prototype.writeUInt16LE = function (value, offset, noAssert) { - _writeUInt16(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeUInt16BE = function (value, offset, noAssert) { - _writeUInt16(this, value, offset, false, noAssert) -} - -function _writeUInt32 (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'trying to write beyond buffer length') - verifuint(value, 0xffffffff) - } - - var len = buf.length - if (offset >= len) - return - - for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) { - buf[offset + i] = - (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } -} - -Buffer.prototype.writeUInt32LE = function (value, offset, noAssert) { - _writeUInt32(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeUInt32BE = function (value, offset, noAssert) { - _writeUInt32(this, value, offset, false, noAssert) -} - -Buffer.prototype.writeInt8 = function (value, offset, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset < this.length, 'Trying to write beyond buffer length') - verifsint(value, 0x7f, -0x80) - } - - if (offset >= this.length) - return - - if (value >= 0) - this.writeUInt8(value, offset, noAssert) - else - this.writeUInt8(0xff + value + 1, offset, noAssert) -} - -function _writeInt16 (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 1 < buf.length, 'Trying to write beyond buffer length') - verifsint(value, 0x7fff, -0x8000) - } - - var len = buf.length - if (offset >= len) - return - - if (value >= 0) - _writeUInt16(buf, value, offset, littleEndian, noAssert) - else - _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert) -} - -Buffer.prototype.writeInt16LE = function (value, offset, noAssert) { - _writeInt16(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeInt16BE = function (value, offset, noAssert) { - _writeInt16(this, value, offset, false, noAssert) -} - -function _writeInt32 (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'Trying to write beyond buffer length') - verifsint(value, 0x7fffffff, -0x80000000) - } - - var len = buf.length - if (offset >= len) - return - - if (value >= 0) - _writeUInt32(buf, value, offset, littleEndian, noAssert) - else - _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert) -} - -Buffer.prototype.writeInt32LE = function (value, offset, noAssert) { - _writeInt32(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeInt32BE = function (value, offset, noAssert) { - _writeInt32(this, value, offset, false, noAssert) -} - -function _writeFloat (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 3 < buf.length, 'Trying to write beyond buffer length') - verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38) - } - - var len = buf.length - if (offset >= len) - return - - ieee754.write(buf, value, offset, littleEndian, 23, 4) -} - -Buffer.prototype.writeFloatLE = function (value, offset, noAssert) { - _writeFloat(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeFloatBE = function (value, offset, noAssert) { - _writeFloat(this, value, offset, false, noAssert) -} - -function _writeDouble (buf, value, offset, littleEndian, noAssert) { - if (!noAssert) { - assert(value !== undefined && value !== null, 'missing value') - assert(typeof littleEndian === 'boolean', 'missing or invalid endian') - assert(offset !== undefined && offset !== null, 'missing offset') - assert(offset + 7 < buf.length, - 'Trying to write beyond buffer length') - verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308) - } - - var len = buf.length - if (offset >= len) - return - - ieee754.write(buf, value, offset, littleEndian, 52, 8) -} - -Buffer.prototype.writeDoubleLE = function (value, offset, noAssert) { - _writeDouble(this, value, offset, true, noAssert) -} - -Buffer.prototype.writeDoubleBE = function (value, offset, noAssert) { - _writeDouble(this, value, offset, false, noAssert) -} - -// fill(value, start=0, end=buffer.length) -Buffer.prototype.fill = function (value, start, end) { - if (!value) value = 0 - if (!start) start = 0 - if (!end) end = this.length - - if (typeof value === 'string') { - value = value.charCodeAt(0) - } - - assert(typeof value === 'number' && !isNaN(value), 'value is not a number') - assert(end >= start, 'end < start') - - // Fill 0 bytes; we're done - if (end === start) return - if (this.length === 0) return - - assert(start >= 0 && start < this.length, 'start out of bounds') - assert(end >= 0 && end <= this.length, 'end out of bounds') - - for (var i = start; i < end; i++) { - this[i] = value - } -} - -Buffer.prototype.inspect = function () { - var out = [] - var len = this.length - for (var i = 0; i < len; i++) { - out[i] = toHex(this[i]) - if (i === exports.INSPECT_MAX_BYTES) { - out[i + 1] = '...' - break - } - } - return '' -} - -/** - * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. - * Added in Node 0.12. Only available in browsers that support ArrayBuffer. - */ -Buffer.prototype.toArrayBuffer = function () { - if (typeof Uint8Array !== 'undefined') { - if (Buffer._useTypedArrays) { - return (new Buffer(this)).buffer - } else { - var buf = new Uint8Array(this.length) - for (var i = 0, len = buf.length; i < len; i += 1) - buf[i] = this[i] - return buf.buffer - } - } else { - throw new Error('Buffer.toArrayBuffer not supported in this browser') - } -} - -// HELPER FUNCTIONS -// ================ - -function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') -} - -var BP = Buffer.prototype - -/** - * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods - */ -Buffer._augment = function (arr) { - arr._isBuffer = true - - // save reference to original Uint8Array get/set methods before overwriting - arr._get = arr.get - arr._set = arr.set - - // deprecated, will be removed in node 0.13+ - arr.get = BP.get - arr.set = BP.set - - arr.write = BP.write - arr.toString = BP.toString - arr.toLocaleString = BP.toString - arr.toJSON = BP.toJSON - arr.copy = BP.copy - arr.slice = BP.slice - arr.readUInt8 = BP.readUInt8 - arr.readUInt16LE = BP.readUInt16LE - arr.readUInt16BE = BP.readUInt16BE - arr.readUInt32LE = BP.readUInt32LE - arr.readUInt32BE = BP.readUInt32BE - arr.readInt8 = BP.readInt8 - arr.readInt16LE = BP.readInt16LE - arr.readInt16BE = BP.readInt16BE - arr.readInt32LE = BP.readInt32LE - arr.readInt32BE = BP.readInt32BE - arr.readFloatLE = BP.readFloatLE - arr.readFloatBE = BP.readFloatBE - arr.readDoubleLE = BP.readDoubleLE - arr.readDoubleBE = BP.readDoubleBE - arr.writeUInt8 = BP.writeUInt8 - arr.writeUInt16LE = BP.writeUInt16LE - arr.writeUInt16BE = BP.writeUInt16BE - arr.writeUInt32LE = BP.writeUInt32LE - arr.writeUInt32BE = BP.writeUInt32BE - arr.writeInt8 = BP.writeInt8 - arr.writeInt16LE = BP.writeInt16LE - arr.writeInt16BE = BP.writeInt16BE - arr.writeInt32LE = BP.writeInt32LE - arr.writeInt32BE = BP.writeInt32BE - arr.writeFloatLE = BP.writeFloatLE - arr.writeFloatBE = BP.writeFloatBE - arr.writeDoubleLE = BP.writeDoubleLE - arr.writeDoubleBE = BP.writeDoubleBE - arr.fill = BP.fill - arr.inspect = BP.inspect - arr.toArrayBuffer = BP.toArrayBuffer - - return arr -} - -// slice(start, end) -function clamp (index, len, defaultValue) { - if (typeof index !== 'number') return defaultValue - index = ~~index; // Coerce to integer. - if (index >= len) return len - if (index >= 0) return index - index += len - if (index >= 0) return index - return 0 -} - -function coerce (length) { - // Coerce length to a number (possibly NaN), round up - // in case it's fractional (e.g. 123.456) then do a - // double negate to coerce a NaN to 0. Easy, right? - length = ~~Math.ceil(+length) - return length < 0 ? 0 : length -} - -function isArray (subject) { - return (Array.isArray || function (subject) { - return Object.prototype.toString.call(subject) === '[object Array]' - })(subject) -} - -function isArrayish (subject) { - return isArray(subject) || Buffer.isBuffer(subject) || - subject && typeof subject === 'object' && - typeof subject.length === 'number' -} - -function toHex (n) { - if (n < 16) return '0' + n.toString(16) - return n.toString(16) -} - -function utf8ToBytes (str) { - var byteArray = [] - for (var i = 0; i < str.length; i++) { - var b = str.charCodeAt(i) - if (b <= 0x7F) - byteArray.push(str.charCodeAt(i)) - else { - var start = i - if (b >= 0xD800 && b <= 0xDFFF) i++ - var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%') - for (var j = 0; j < h.length; j++) - byteArray.push(parseInt(h[j], 16)) - } - } - return byteArray -} - -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) { - var c, hi, lo - var byteArray = [] - for (var i = 0; i < str.length; i++) { - c = str.charCodeAt(i) - hi = c >> 8 - lo = c % 256 - byteArray.push(lo) - byteArray.push(hi) - } - - return byteArray -} - -function base64ToBytes (str) { - return base64.toByteArray(str) -} - -function blitBuffer (src, dst, offset, length) { - var pos - for (var i = 0; i < length; i++) { - if ((i + offset >= dst.length) || (i >= src.length)) - break - dst[i + offset] = src[i] - } - return i -} - -function decodeUtf8Char (str) { - try { - return decodeURIComponent(str) - } catch (err) { - return String.fromCharCode(0xFFFD) // UTF 8 invalid char - } -} - -/* - * We have to make sure that the value is a valid integer. This means that it - * is non-negative. It has no fractional component and that it does not - * exceed the maximum allowed value. - */ -function verifuint (value, max) { - assert(typeof value === 'number', 'cannot write a non-number as a number') - assert(value >= 0, 'specified a negative value for writing an unsigned value') - assert(value <= max, 'value is larger than maximum value for type') - assert(Math.floor(value) === value, 'value has a fractional component') -} - -function verifsint (value, max, min) { - assert(typeof value === 'number', 'cannot write a non-number as a number') - assert(value <= max, 'value larger than maximum allowed value') - assert(value >= min, 'value smaller than minimum allowed value') - assert(Math.floor(value) === value, 'value has a fractional component') -} - -function verifIEEE754 (value, max, min) { - assert(typeof value === 'number', 'cannot write a non-number as a number') - assert(value <= max, 'value larger than maximum allowed value') - assert(value >= min, 'value smaller than minimum allowed value') -} - -function assert (test, message) { - if (!test) throw new Error(message || 'Failed assertion') -} - -},{"base64-js":8,"ieee754":9}],8:[function(_dereq_,module,exports){ -var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - -;(function (exports) { - 'use strict'; - - var Arr = (typeof Uint8Array !== 'undefined') - ? Uint8Array - : Array - - var ZERO = '0'.charCodeAt(0) - var PLUS = '+'.charCodeAt(0) - var SLASH = '/'.charCodeAt(0) - var NUMBER = '0'.charCodeAt(0) - var LOWER = 'a'.charCodeAt(0) - var UPPER = 'A'.charCodeAt(0) - - function decode (elt) { - var code = elt.charCodeAt(0) - if (code === PLUS) - return 62 // '+' - if (code === SLASH) - return 63 // '/' - if (code < NUMBER) - return -1 //no match - if (code < NUMBER + 10) - return code - NUMBER + 26 + 26 - if (code < UPPER + 26) - return code - UPPER - if (code < LOWER + 26) - return code - LOWER + 26 - } - - function b64ToByteArray (b64) { - var i, j, l, tmp, placeHolders, arr - - if (b64.length % 4 > 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 - var len = b64.length - placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 - - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(b64.length * 3 / 4 - placeHolders) - - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? b64.length - 4 : b64.length - - var L = 0 - - function push (v) { - arr[L++] = v - } - - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) - push((tmp & 0xFF0000) >> 16) - push((tmp & 0xFF00) >> 8) - push(tmp & 0xFF) - } - - if (placeHolders === 2) { - tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) - push(tmp & 0xFF) - } else if (placeHolders === 1) { - tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) - push((tmp >> 8) & 0xFF) - push(tmp & 0xFF) - } - - return arr - } - - function uint8ToBase64 (uint8) { - var i, - extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes - output = "", - temp, length - - function encode (num) { - return lookup.charAt(num) - } - - function tripletToBase64 (num) { - return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) - } - - // go through the array every three bytes, we'll deal with trailing stuff later - for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { - temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output += tripletToBase64(temp) - } - - // pad the end with zeros, but make sure to not forget the extra bytes - switch (extraBytes) { - case 1: - temp = uint8[uint8.length - 1] - output += encode(temp >> 2) - output += encode((temp << 4) & 0x3F) - output += '==' - break - case 2: - temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) - output += encode(temp >> 10) - output += encode((temp >> 4) & 0x3F) - output += encode((temp << 2) & 0x3F) - output += '=' - break - } - - return output - } - - module.exports.toByteArray = b64ToByteArray - module.exports.fromByteArray = uint8ToBase64 -}()) - -},{}],9:[function(_dereq_,module,exports){ -exports.read = function(buffer, offset, isLE, mLen, nBytes) { - var e, m, - eLen = nBytes * 8 - mLen - 1, - eMax = (1 << eLen) - 1, - eBias = eMax >> 1, - nBits = -7, - i = isLE ? (nBytes - 1) : 0, - d = isLE ? -1 : 1, - 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, - eLen = nBytes * 8 - mLen - 1, - eMax = (1 << eLen) - 1, - eBias = eMax >> 1, - rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0), - i = isLE ? 0 : (nBytes - 1), - d = isLE ? 1 : -1, - 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; -}; - -},{}]},{},[6]) +},{"./instance.js":4}]},{},[5]) -(6) +(5) }); //# sourceMappingURL=geojson2svg.js.map \ No newline at end of file diff --git a/dist/geojson2svg.js.map b/dist/geojson2svg.js.map index 44519f6..3969db7 100644 --- a/dist/geojson2svg.js.map +++ b/dist/geojson2svg.js.map @@ -3,29 +3,21 @@ "file": "generated.js", "sources": [ "/usr/local/lib/node_modules/browserify/node_modules/browser-pack/_prelude.js", - "/home/ubuntu/projects/geojson2svg/node_modules/clone/clone.js", "/home/ubuntu/projects/geojson2svg/node_modules/deep-extend/index.js", "/home/ubuntu/projects/geojson2svg/node_modules/multigeojson/index.js", "/home/ubuntu/projects/geojson2svg/src/converter.js", "/home/ubuntu/projects/geojson2svg/src/instance.js", - "/home/ubuntu/projects/geojson2svg/src/main.js", - "/usr/local/lib/node_modules/browserify/node_modules/buffer/index.js", - "/usr/local/lib/node_modules/browserify/node_modules/buffer/node_modules/base64-js/lib/b64.js", - "/usr/local/lib/node_modules/browserify/node_modules/buffer/node_modules/ieee754/index.js" + "/home/ubuntu/projects/geojson2svg/src/main.js" ], "names": [], - "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvlCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", + "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC5GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", "sourcesContent": [ "(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);throw new Error(\"Cannot find module '\"+o+\"'\")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o\n * @license MIT\n *\n * The MIT License (MIT)\n *\n * Copyright (c) 2013 Viacheslav Lotsmanov\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of\n * this software and associated documentation files (the \"Software\"), to deal in\n * the Software without restriction, including without limitation the rights to\n * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\n * the Software, and to permit persons to whom the Software is furnished to do so,\n * subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\n * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * Extening object that entered in first argument.\n * Returns extended object or false if have no target object or incorrect type.\n * If you wish to clone object, simply use that:\n * deepExtend({}, yourObj_1, [yourObj_N]) - first arg is new empty object\n */\nvar deepExtend = module.exports = function (/*obj_1, [obj_2], [obj_N]*/) {\n if (arguments.length < 1 || typeof arguments[0] !== 'object') {\n return false;\n }\n\n if (arguments.length < 2) return arguments[0];\n\n var target = arguments[0];\n\n // convert arguments to array and cut off target object\n var args = Array.prototype.slice.call(arguments, 1);\n\n var key, val, src, clone;\n\n args.forEach(function (obj) {\n if (typeof obj !== 'object') return;\n\n for (key in obj) {\n if ( ! (key in obj)) continue;\n\n src = target[key];\n val = obj[key];\n\n if (val === target) continue;\n\n if (typeof val !== 'object' || val === null) {\n target[key] = val;\n continue;\n }\n\n if (typeof src !== 'object' || src === null) {\n clone = (Array.isArray(val)) ? [] : {};\n target[key] = deepExtend(clone, val);\n continue;\n }\n\n if (Array.isArray(val)) {\n clone = (Array.isArray(src)) ? src : [];\n } else {\n clone = (!Array.isArray(src)) ? src : {};\n }\n\n target[key] = deepExtend(clone, val);\n }\n });\n\n return target;\n}\n", "//index.js \n(function() { \n\tvar singles = ['Point', 'LineString', 'Polygon'];\n\tvar multies = ['MultiPoint', 'MultiLineString', 'MultiPolygon'];\n\tfunction explode(g) {\n\t if( multies.indexOf(g.type) > -1) {\n\t return g.coordinates.map(function(part) {\n\t var single = {};\n\t single.type = g.type.replace('Multi','');\n\t single.coordinates = part;\n if(g.crs) single.crs = g.crs;\n\t return single;\n\t }); \n\t } else {\n\t return false;\n\t }\n\t}\n\tfunction implode(gs) {\n\t var sameType = gs.every(function(g) { \n\t return singles.indexOf(g.type) > -1;\n\t })\n var crs = gs[0].crs || 0;\n var sameCrs = gs.every(function(g) {\n var gcrs = g.crs || 0;\n return gcrs == crs;\n });\n\t if(sameType && sameCrs) {\n\t var multi = {};\n\t multi.type = 'Multi' + gs[0].type;\n\t multi.coordinates = [];\n if(crs != 0) multi.crs = crs;\n\t gs.forEach(function(g) {\n\t multi.coordinates.push(g.coordinates);\n\t });\n\t return multi;\n\t } else {\n\t return false;\n\t }\n\t};\n\tvar multigeojson = {\n\t explode: explode,\n\t implode: implode\n\t};\n\tif(typeof module !== 'undefined' && module.exports) {\n\t module.exports = multigeojson;\n\t} else if(window) {\n\t window.multigeojson = multigeojson;\n\t}\n})();\n", "//converter.js\nvar multi = require('multigeojson');\nfunction getCoordString(coords,res,origin) {\n //origin - svg image origin \n var coordStr = coords.map(function(coord) {\n return (coord[0] - origin.x)/res + ',' + (origin.y - coord[1])/res;\n });\n return coordStr.join(' ');\n}\nfunction addAttributes(ele,attributes) {\n var part = ele.split('/>')[0];\n for(var key in attributes) {\n if(attributes[key]) {\n part += ' ' + key + '=\"' + attributes[key] + '\"';\n }\n }\n return part + ' />';\n}\n\nfunction point(geom,res,origin,opt) {\n var r = opt && opt.r ? opt.r : 1;\n var path = 'M' + getCoordString([geom.coordinates],res,origin)\n +' m'+ -r+ ',0'+ ' a'+r+','+ r + ' 0 1,1 '+ 2*r + ','+0\n +' a'+r+','+ r + ' 0 1,1 '+ -2*r + ','+0;\n return [path];\n}\nfunction multiPoint(geom,res,origin,opt) {\n var explode = opt && opt.hasOwnProperty('explode') ? opt.explode : false;\n var paths = multi.explode(geom).map(function(single) {\n return point(single,res,origin,opt)[0];\n });\n if(!explode) return [paths.join(' ')];\n return paths;\n\n}\nfunction lineString(geom,res,origin,otp) {\n var coords = getCoordString(geom.coordinates,res,origin);\n var path = 'M'+ coords; \n return [path];\n}\nfunction multiLineString(geom,res,origin,opt) {\n var explode = opt && opt.hasOwnProperty('explode') ? opt.explode : false;\n var paths = multi.explode(geom).map(function(single) {\n return lineString(single,res,origin,opt)[0];\n });\n if(!explode) return [paths.join(' ')];\n return paths;\n}\nfunction polygon(geom,res,origin,opt) {\n var mainStr,holes,holeStr;\n mainStr = getCoordString(geom.coordinates[0],res,origin);\n if (geom.coordinates.length > 1) {\n holes = geom.coordinates.slice(1,geom.coordinates.length);\n }\n var path = 'M'+ mainStr;\n if(holes) {\n for(var i=0;i \n * License: MIT\n *\n * `npm install buffer`\n */\n\nvar base64 = require('base64-js')\nvar ieee754 = require('ieee754')\n\nexports.Buffer = Buffer\nexports.SlowBuffer = Buffer\nexports.INSPECT_MAX_BYTES = 50\nBuffer.poolSize = 8192\n\n/**\n * If `Buffer._useTypedArrays`:\n * === true Use Uint8Array implementation (fastest)\n * === false Use Object implementation (compatible down to IE6)\n */\nBuffer._useTypedArrays = (function () {\n // Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+,\n // Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding\n // properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support\n // because we need to be able to add all the node Buffer API methods. This is an issue\n // in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438\n try {\n var buf = new ArrayBuffer(0)\n var arr = new Uint8Array(buf)\n arr.foo = function () { return 42 }\n return 42 === arr.foo() &&\n typeof arr.subarray === 'function' // Chrome 9-10 lack `subarray`\n } catch (e) {\n return false\n }\n})()\n\n/**\n * Class: Buffer\n * =============\n *\n * The Buffer constructor returns instances of `Uint8Array` that are augmented\n * with function properties for all the node `Buffer` API functions. We use\n * `Uint8Array` so that square bracket notation works as expected -- it returns\n * a single octet.\n *\n * By augmenting the instances, we can avoid modifying the `Uint8Array`\n * prototype.\n */\nfunction Buffer (subject, encoding, noZero) {\n if (!(this instanceof Buffer))\n return new Buffer(subject, encoding, noZero)\n\n var type = typeof subject\n\n // Workaround: node's base64 implementation allows for non-padded strings\n // while base64-js does not.\n if (encoding === 'base64' && type === 'string') {\n subject = stringtrim(subject)\n while (subject.length % 4 !== 0) {\n subject = subject + '='\n }\n }\n\n // Find the length\n var length\n if (type === 'number')\n length = coerce(subject)\n else if (type === 'string')\n length = Buffer.byteLength(subject, encoding)\n else if (type === 'object')\n length = coerce(subject.length) // assume that object is array-like\n else\n throw new Error('First argument needs to be a number, array or string.')\n\n var buf\n if (Buffer._useTypedArrays) {\n // Preferred: Return an augmented `Uint8Array` instance for best performance\n buf = Buffer._augment(new Uint8Array(length))\n } else {\n // Fallback: Return THIS instance of Buffer (created by `new`)\n buf = this\n buf.length = length\n buf._isBuffer = true\n }\n\n var i\n if (Buffer._useTypedArrays && typeof subject.byteLength === 'number') {\n // Speed optimization -- use set if we're copying from a typed array\n buf._set(subject)\n } else if (isArrayish(subject)) {\n // Treat array-ish objects as a byte array\n for (i = 0; i < length; i++) {\n if (Buffer.isBuffer(subject))\n buf[i] = subject.readUInt8(i)\n else\n buf[i] = subject[i]\n }\n } else if (type === 'string') {\n buf.write(subject, 0, encoding)\n } else if (type === 'number' && !Buffer._useTypedArrays && !noZero) {\n for (i = 0; i < length; i++) {\n buf[i] = 0\n }\n }\n\n return buf\n}\n\n// STATIC METHODS\n// ==============\n\nBuffer.isEncoding = function (encoding) {\n switch (String(encoding).toLowerCase()) {\n case 'hex':\n case 'utf8':\n case 'utf-8':\n case 'ascii':\n case 'binary':\n case 'base64':\n case 'raw':\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n return true\n default:\n return false\n }\n}\n\nBuffer.isBuffer = function (b) {\n return !!(b !== null && b !== undefined && b._isBuffer)\n}\n\nBuffer.byteLength = function (str, encoding) {\n var ret\n str = str + ''\n switch (encoding || 'utf8') {\n case 'hex':\n ret = str.length / 2\n break\n case 'utf8':\n case 'utf-8':\n ret = utf8ToBytes(str).length\n break\n case 'ascii':\n case 'binary':\n case 'raw':\n ret = str.length\n break\n case 'base64':\n ret = base64ToBytes(str).length\n break\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n ret = str.length * 2\n break\n default:\n throw new Error('Unknown encoding')\n }\n return ret\n}\n\nBuffer.concat = function (list, totalLength) {\n assert(isArray(list), 'Usage: Buffer.concat(list, [totalLength])\\n' +\n 'list should be an Array.')\n\n if (list.length === 0) {\n return new Buffer(0)\n } else if (list.length === 1) {\n return list[0]\n }\n\n var i\n if (typeof totalLength !== 'number') {\n totalLength = 0\n for (i = 0; i < list.length; i++) {\n totalLength += list[i].length\n }\n }\n\n var buf = new Buffer(totalLength)\n var pos = 0\n for (i = 0; i < list.length; i++) {\n var item = list[i]\n item.copy(buf, pos)\n pos += item.length\n }\n return buf\n}\n\n// BUFFER INSTANCE METHODS\n// =======================\n\nfunction _hexWrite (buf, string, offset, length) {\n offset = Number(offset) || 0\n var remaining = buf.length - offset\n if (!length) {\n length = remaining\n } else {\n length = Number(length)\n if (length > remaining) {\n length = remaining\n }\n }\n\n // must be an even number of digits\n var strLen = string.length\n assert(strLen % 2 === 0, 'Invalid hex string')\n\n if (length > strLen / 2) {\n length = strLen / 2\n }\n for (var i = 0; i < length; i++) {\n var byte = parseInt(string.substr(i * 2, 2), 16)\n assert(!isNaN(byte), 'Invalid hex string')\n buf[offset + i] = byte\n }\n Buffer._charsWritten = i * 2\n return i\n}\n\nfunction _utf8Write (buf, string, offset, length) {\n var charsWritten = Buffer._charsWritten =\n blitBuffer(utf8ToBytes(string), buf, offset, length)\n return charsWritten\n}\n\nfunction _asciiWrite (buf, string, offset, length) {\n var charsWritten = Buffer._charsWritten =\n blitBuffer(asciiToBytes(string), buf, offset, length)\n return charsWritten\n}\n\nfunction _binaryWrite (buf, string, offset, length) {\n return _asciiWrite(buf, string, offset, length)\n}\n\nfunction _base64Write (buf, string, offset, length) {\n var charsWritten = Buffer._charsWritten =\n blitBuffer(base64ToBytes(string), buf, offset, length)\n return charsWritten\n}\n\nfunction _utf16leWrite (buf, string, offset, length) {\n var charsWritten = Buffer._charsWritten =\n blitBuffer(utf16leToBytes(string), buf, offset, length)\n return charsWritten\n}\n\nBuffer.prototype.write = function (string, offset, length, encoding) {\n // Support both (string, offset, length, encoding)\n // and the legacy (string, encoding, offset, length)\n if (isFinite(offset)) {\n if (!isFinite(length)) {\n encoding = length\n length = undefined\n }\n } else { // legacy\n var swap = encoding\n encoding = offset\n offset = length\n length = swap\n }\n\n offset = Number(offset) || 0\n var remaining = this.length - offset\n if (!length) {\n length = remaining\n } else {\n length = Number(length)\n if (length > remaining) {\n length = remaining\n }\n }\n encoding = String(encoding || 'utf8').toLowerCase()\n\n var ret\n switch (encoding) {\n case 'hex':\n ret = _hexWrite(this, string, offset, length)\n break\n case 'utf8':\n case 'utf-8':\n ret = _utf8Write(this, string, offset, length)\n break\n case 'ascii':\n ret = _asciiWrite(this, string, offset, length)\n break\n case 'binary':\n ret = _binaryWrite(this, string, offset, length)\n break\n case 'base64':\n ret = _base64Write(this, string, offset, length)\n break\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n ret = _utf16leWrite(this, string, offset, length)\n break\n default:\n throw new Error('Unknown encoding')\n }\n return ret\n}\n\nBuffer.prototype.toString = function (encoding, start, end) {\n var self = this\n\n encoding = String(encoding || 'utf8').toLowerCase()\n start = Number(start) || 0\n end = (end !== undefined)\n ? Number(end)\n : end = self.length\n\n // Fastpath empty strings\n if (end === start)\n return ''\n\n var ret\n switch (encoding) {\n case 'hex':\n ret = _hexSlice(self, start, end)\n break\n case 'utf8':\n case 'utf-8':\n ret = _utf8Slice(self, start, end)\n break\n case 'ascii':\n ret = _asciiSlice(self, start, end)\n break\n case 'binary':\n ret = _binarySlice(self, start, end)\n break\n case 'base64':\n ret = _base64Slice(self, start, end)\n break\n case 'ucs2':\n case 'ucs-2':\n case 'utf16le':\n case 'utf-16le':\n ret = _utf16leSlice(self, start, end)\n break\n default:\n throw new Error('Unknown encoding')\n }\n return ret\n}\n\nBuffer.prototype.toJSON = function () {\n return {\n type: 'Buffer',\n data: Array.prototype.slice.call(this._arr || this, 0)\n }\n}\n\n// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)\nBuffer.prototype.copy = function (target, target_start, start, end) {\n var source = this\n\n if (!start) start = 0\n if (!end && end !== 0) end = this.length\n if (!target_start) target_start = 0\n\n // Copy 0 bytes; we're done\n if (end === start) return\n if (target.length === 0 || source.length === 0) return\n\n // Fatal error conditions\n assert(end >= start, 'sourceEnd < sourceStart')\n assert(target_start >= 0 && target_start < target.length,\n 'targetStart out of bounds')\n assert(start >= 0 && start < source.length, 'sourceStart out of bounds')\n assert(end >= 0 && end <= source.length, 'sourceEnd out of bounds')\n\n // Are we oob?\n if (end > this.length)\n end = this.length\n if (target.length - target_start < end - start)\n end = target.length - target_start + start\n\n var len = end - start\n\n if (len < 100 || !Buffer._useTypedArrays) {\n for (var i = 0; i < len; i++)\n target[i + target_start] = this[i + start]\n } else {\n target._set(this.subarray(start, start + len), target_start)\n }\n}\n\nfunction _base64Slice (buf, start, end) {\n if (start === 0 && end === buf.length) {\n return base64.fromByteArray(buf)\n } else {\n return base64.fromByteArray(buf.slice(start, end))\n }\n}\n\nfunction _utf8Slice (buf, start, end) {\n var res = ''\n var tmp = ''\n end = Math.min(buf.length, end)\n\n for (var i = start; i < end; i++) {\n if (buf[i] <= 0x7F) {\n res += decodeUtf8Char(tmp) + String.fromCharCode(buf[i])\n tmp = ''\n } else {\n tmp += '%' + buf[i].toString(16)\n }\n }\n\n return res + decodeUtf8Char(tmp)\n}\n\nfunction _asciiSlice (buf, start, end) {\n var ret = ''\n end = Math.min(buf.length, end)\n\n for (var i = start; i < end; i++)\n ret += String.fromCharCode(buf[i])\n return ret\n}\n\nfunction _binarySlice (buf, start, end) {\n return _asciiSlice(buf, start, end)\n}\n\nfunction _hexSlice (buf, start, end) {\n var len = buf.length\n\n if (!start || start < 0) start = 0\n if (!end || end < 0 || end > len) end = len\n\n var out = ''\n for (var i = start; i < end; i++) {\n out += toHex(buf[i])\n }\n return out\n}\n\nfunction _utf16leSlice (buf, start, end) {\n var bytes = buf.slice(start, end)\n var res = ''\n for (var i = 0; i < bytes.length; i += 2) {\n res += String.fromCharCode(bytes[i] + bytes[i+1] * 256)\n }\n return res\n}\n\nBuffer.prototype.slice = function (start, end) {\n var len = this.length\n start = clamp(start, len, 0)\n end = clamp(end, len, len)\n\n if (Buffer._useTypedArrays) {\n return Buffer._augment(this.subarray(start, end))\n } else {\n var sliceLen = end - start\n var newBuf = new Buffer(sliceLen, undefined, true)\n for (var i = 0; i < sliceLen; i++) {\n newBuf[i] = this[i + start]\n }\n return newBuf\n }\n}\n\n// `get` will be removed in Node 0.13+\nBuffer.prototype.get = function (offset) {\n console.log('.get() is deprecated. Access using array indexes instead.')\n return this.readUInt8(offset)\n}\n\n// `set` will be removed in Node 0.13+\nBuffer.prototype.set = function (v, offset) {\n console.log('.set() is deprecated. Access using array indexes instead.')\n return this.writeUInt8(v, offset)\n}\n\nBuffer.prototype.readUInt8 = function (offset, noAssert) {\n if (!noAssert) {\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset < this.length, 'Trying to read beyond buffer length')\n }\n\n if (offset >= this.length)\n return\n\n return this[offset]\n}\n\nfunction _readUInt16 (buf, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n var val\n if (littleEndian) {\n val = buf[offset]\n if (offset + 1 < len)\n val |= buf[offset + 1] << 8\n } else {\n val = buf[offset] << 8\n if (offset + 1 < len)\n val |= buf[offset + 1]\n }\n return val\n}\n\nBuffer.prototype.readUInt16LE = function (offset, noAssert) {\n return _readUInt16(this, offset, true, noAssert)\n}\n\nBuffer.prototype.readUInt16BE = function (offset, noAssert) {\n return _readUInt16(this, offset, false, noAssert)\n}\n\nfunction _readUInt32 (buf, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n var val\n if (littleEndian) {\n if (offset + 2 < len)\n val = buf[offset + 2] << 16\n if (offset + 1 < len)\n val |= buf[offset + 1] << 8\n val |= buf[offset]\n if (offset + 3 < len)\n val = val + (buf[offset + 3] << 24 >>> 0)\n } else {\n if (offset + 1 < len)\n val = buf[offset + 1] << 16\n if (offset + 2 < len)\n val |= buf[offset + 2] << 8\n if (offset + 3 < len)\n val |= buf[offset + 3]\n val = val + (buf[offset] << 24 >>> 0)\n }\n return val\n}\n\nBuffer.prototype.readUInt32LE = function (offset, noAssert) {\n return _readUInt32(this, offset, true, noAssert)\n}\n\nBuffer.prototype.readUInt32BE = function (offset, noAssert) {\n return _readUInt32(this, offset, false, noAssert)\n}\n\nBuffer.prototype.readInt8 = function (offset, noAssert) {\n if (!noAssert) {\n assert(offset !== undefined && offset !== null,\n 'missing offset')\n assert(offset < this.length, 'Trying to read beyond buffer length')\n }\n\n if (offset >= this.length)\n return\n\n var neg = this[offset] & 0x80\n if (neg)\n return (0xff - this[offset] + 1) * -1\n else\n return this[offset]\n}\n\nfunction _readInt16 (buf, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n var val = _readUInt16(buf, offset, littleEndian, true)\n var neg = val & 0x8000\n if (neg)\n return (0xffff - val + 1) * -1\n else\n return val\n}\n\nBuffer.prototype.readInt16LE = function (offset, noAssert) {\n return _readInt16(this, offset, true, noAssert)\n}\n\nBuffer.prototype.readInt16BE = function (offset, noAssert) {\n return _readInt16(this, offset, false, noAssert)\n}\n\nfunction _readInt32 (buf, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n var val = _readUInt32(buf, offset, littleEndian, true)\n var neg = val & 0x80000000\n if (neg)\n return (0xffffffff - val + 1) * -1\n else\n return val\n}\n\nBuffer.prototype.readInt32LE = function (offset, noAssert) {\n return _readInt32(this, offset, true, noAssert)\n}\n\nBuffer.prototype.readInt32BE = function (offset, noAssert) {\n return _readInt32(this, offset, false, noAssert)\n}\n\nfunction _readFloat (buf, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')\n }\n\n return ieee754.read(buf, offset, littleEndian, 23, 4)\n}\n\nBuffer.prototype.readFloatLE = function (offset, noAssert) {\n return _readFloat(this, offset, true, noAssert)\n}\n\nBuffer.prototype.readFloatBE = function (offset, noAssert) {\n return _readFloat(this, offset, false, noAssert)\n}\n\nfunction _readDouble (buf, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')\n }\n\n return ieee754.read(buf, offset, littleEndian, 52, 8)\n}\n\nBuffer.prototype.readDoubleLE = function (offset, noAssert) {\n return _readDouble(this, offset, true, noAssert)\n}\n\nBuffer.prototype.readDoubleBE = function (offset, noAssert) {\n return _readDouble(this, offset, false, noAssert)\n}\n\nBuffer.prototype.writeUInt8 = function (value, offset, noAssert) {\n if (!noAssert) {\n assert(value !== undefined && value !== null, 'missing value')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset < this.length, 'trying to write beyond buffer length')\n verifuint(value, 0xff)\n }\n\n if (offset >= this.length) return\n\n this[offset] = value\n}\n\nfunction _writeUInt16 (buf, value, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(value !== undefined && value !== null, 'missing value')\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 1 < buf.length, 'trying to write beyond buffer length')\n verifuint(value, 0xffff)\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n for (var i = 0, j = Math.min(len - offset, 2); i < j; i++) {\n buf[offset + i] =\n (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>\n (littleEndian ? i : 1 - i) * 8\n }\n}\n\nBuffer.prototype.writeUInt16LE = function (value, offset, noAssert) {\n _writeUInt16(this, value, offset, true, noAssert)\n}\n\nBuffer.prototype.writeUInt16BE = function (value, offset, noAssert) {\n _writeUInt16(this, value, offset, false, noAssert)\n}\n\nfunction _writeUInt32 (buf, value, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(value !== undefined && value !== null, 'missing value')\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 3 < buf.length, 'trying to write beyond buffer length')\n verifuint(value, 0xffffffff)\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n for (var i = 0, j = Math.min(len - offset, 4); i < j; i++) {\n buf[offset + i] =\n (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff\n }\n}\n\nBuffer.prototype.writeUInt32LE = function (value, offset, noAssert) {\n _writeUInt32(this, value, offset, true, noAssert)\n}\n\nBuffer.prototype.writeUInt32BE = function (value, offset, noAssert) {\n _writeUInt32(this, value, offset, false, noAssert)\n}\n\nBuffer.prototype.writeInt8 = function (value, offset, noAssert) {\n if (!noAssert) {\n assert(value !== undefined && value !== null, 'missing value')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset < this.length, 'Trying to write beyond buffer length')\n verifsint(value, 0x7f, -0x80)\n }\n\n if (offset >= this.length)\n return\n\n if (value >= 0)\n this.writeUInt8(value, offset, noAssert)\n else\n this.writeUInt8(0xff + value + 1, offset, noAssert)\n}\n\nfunction _writeInt16 (buf, value, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(value !== undefined && value !== null, 'missing value')\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')\n verifsint(value, 0x7fff, -0x8000)\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n if (value >= 0)\n _writeUInt16(buf, value, offset, littleEndian, noAssert)\n else\n _writeUInt16(buf, 0xffff + value + 1, offset, littleEndian, noAssert)\n}\n\nBuffer.prototype.writeInt16LE = function (value, offset, noAssert) {\n _writeInt16(this, value, offset, true, noAssert)\n}\n\nBuffer.prototype.writeInt16BE = function (value, offset, noAssert) {\n _writeInt16(this, value, offset, false, noAssert)\n}\n\nfunction _writeInt32 (buf, value, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(value !== undefined && value !== null, 'missing value')\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')\n verifsint(value, 0x7fffffff, -0x80000000)\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n if (value >= 0)\n _writeUInt32(buf, value, offset, littleEndian, noAssert)\n else\n _writeUInt32(buf, 0xffffffff + value + 1, offset, littleEndian, noAssert)\n}\n\nBuffer.prototype.writeInt32LE = function (value, offset, noAssert) {\n _writeInt32(this, value, offset, true, noAssert)\n}\n\nBuffer.prototype.writeInt32BE = function (value, offset, noAssert) {\n _writeInt32(this, value, offset, false, noAssert)\n}\n\nfunction _writeFloat (buf, value, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(value !== undefined && value !== null, 'missing value')\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')\n verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n ieee754.write(buf, value, offset, littleEndian, 23, 4)\n}\n\nBuffer.prototype.writeFloatLE = function (value, offset, noAssert) {\n _writeFloat(this, value, offset, true, noAssert)\n}\n\nBuffer.prototype.writeFloatBE = function (value, offset, noAssert) {\n _writeFloat(this, value, offset, false, noAssert)\n}\n\nfunction _writeDouble (buf, value, offset, littleEndian, noAssert) {\n if (!noAssert) {\n assert(value !== undefined && value !== null, 'missing value')\n assert(typeof littleEndian === 'boolean', 'missing or invalid endian')\n assert(offset !== undefined && offset !== null, 'missing offset')\n assert(offset + 7 < buf.length,\n 'Trying to write beyond buffer length')\n verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)\n }\n\n var len = buf.length\n if (offset >= len)\n return\n\n ieee754.write(buf, value, offset, littleEndian, 52, 8)\n}\n\nBuffer.prototype.writeDoubleLE = function (value, offset, noAssert) {\n _writeDouble(this, value, offset, true, noAssert)\n}\n\nBuffer.prototype.writeDoubleBE = function (value, offset, noAssert) {\n _writeDouble(this, value, offset, false, noAssert)\n}\n\n// fill(value, start=0, end=buffer.length)\nBuffer.prototype.fill = function (value, start, end) {\n if (!value) value = 0\n if (!start) start = 0\n if (!end) end = this.length\n\n if (typeof value === 'string') {\n value = value.charCodeAt(0)\n }\n\n assert(typeof value === 'number' && !isNaN(value), 'value is not a number')\n assert(end >= start, 'end < start')\n\n // Fill 0 bytes; we're done\n if (end === start) return\n if (this.length === 0) return\n\n assert(start >= 0 && start < this.length, 'start out of bounds')\n assert(end >= 0 && end <= this.length, 'end out of bounds')\n\n for (var i = start; i < end; i++) {\n this[i] = value\n }\n}\n\nBuffer.prototype.inspect = function () {\n var out = []\n var len = this.length\n for (var i = 0; i < len; i++) {\n out[i] = toHex(this[i])\n if (i === exports.INSPECT_MAX_BYTES) {\n out[i + 1] = '...'\n break\n }\n }\n return ''\n}\n\n/**\n * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.\n * Added in Node 0.12. Only available in browsers that support ArrayBuffer.\n */\nBuffer.prototype.toArrayBuffer = function () {\n if (typeof Uint8Array !== 'undefined') {\n if (Buffer._useTypedArrays) {\n return (new Buffer(this)).buffer\n } else {\n var buf = new Uint8Array(this.length)\n for (var i = 0, len = buf.length; i < len; i += 1)\n buf[i] = this[i]\n return buf.buffer\n }\n } else {\n throw new Error('Buffer.toArrayBuffer not supported in this browser')\n }\n}\n\n// HELPER FUNCTIONS\n// ================\n\nfunction stringtrim (str) {\n if (str.trim) return str.trim()\n return str.replace(/^\\s+|\\s+$/g, '')\n}\n\nvar BP = Buffer.prototype\n\n/**\n * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods\n */\nBuffer._augment = function (arr) {\n arr._isBuffer = true\n\n // save reference to original Uint8Array get/set methods before overwriting\n arr._get = arr.get\n arr._set = arr.set\n\n // deprecated, will be removed in node 0.13+\n arr.get = BP.get\n arr.set = BP.set\n\n arr.write = BP.write\n arr.toString = BP.toString\n arr.toLocaleString = BP.toString\n arr.toJSON = BP.toJSON\n arr.copy = BP.copy\n arr.slice = BP.slice\n arr.readUInt8 = BP.readUInt8\n arr.readUInt16LE = BP.readUInt16LE\n arr.readUInt16BE = BP.readUInt16BE\n arr.readUInt32LE = BP.readUInt32LE\n arr.readUInt32BE = BP.readUInt32BE\n arr.readInt8 = BP.readInt8\n arr.readInt16LE = BP.readInt16LE\n arr.readInt16BE = BP.readInt16BE\n arr.readInt32LE = BP.readInt32LE\n arr.readInt32BE = BP.readInt32BE\n arr.readFloatLE = BP.readFloatLE\n arr.readFloatBE = BP.readFloatBE\n arr.readDoubleLE = BP.readDoubleLE\n arr.readDoubleBE = BP.readDoubleBE\n arr.writeUInt8 = BP.writeUInt8\n arr.writeUInt16LE = BP.writeUInt16LE\n arr.writeUInt16BE = BP.writeUInt16BE\n arr.writeUInt32LE = BP.writeUInt32LE\n arr.writeUInt32BE = BP.writeUInt32BE\n arr.writeInt8 = BP.writeInt8\n arr.writeInt16LE = BP.writeInt16LE\n arr.writeInt16BE = BP.writeInt16BE\n arr.writeInt32LE = BP.writeInt32LE\n arr.writeInt32BE = BP.writeInt32BE\n arr.writeFloatLE = BP.writeFloatLE\n arr.writeFloatBE = BP.writeFloatBE\n arr.writeDoubleLE = BP.writeDoubleLE\n arr.writeDoubleBE = BP.writeDoubleBE\n arr.fill = BP.fill\n arr.inspect = BP.inspect\n arr.toArrayBuffer = BP.toArrayBuffer\n\n return arr\n}\n\n// slice(start, end)\nfunction clamp (index, len, defaultValue) {\n if (typeof index !== 'number') return defaultValue\n index = ~~index; // Coerce to integer.\n if (index >= len) return len\n if (index >= 0) return index\n index += len\n if (index >= 0) return index\n return 0\n}\n\nfunction coerce (length) {\n // Coerce length to a number (possibly NaN), round up\n // in case it's fractional (e.g. 123.456) then do a\n // double negate to coerce a NaN to 0. Easy, right?\n length = ~~Math.ceil(+length)\n return length < 0 ? 0 : length\n}\n\nfunction isArray (subject) {\n return (Array.isArray || function (subject) {\n return Object.prototype.toString.call(subject) === '[object Array]'\n })(subject)\n}\n\nfunction isArrayish (subject) {\n return isArray(subject) || Buffer.isBuffer(subject) ||\n subject && typeof subject === 'object' &&\n typeof subject.length === 'number'\n}\n\nfunction toHex (n) {\n if (n < 16) return '0' + n.toString(16)\n return n.toString(16)\n}\n\nfunction utf8ToBytes (str) {\n var byteArray = []\n for (var i = 0; i < str.length; i++) {\n var b = str.charCodeAt(i)\n if (b <= 0x7F)\n byteArray.push(str.charCodeAt(i))\n else {\n var start = i\n if (b >= 0xD800 && b <= 0xDFFF) i++\n var h = encodeURIComponent(str.slice(start, i+1)).substr(1).split('%')\n for (var j = 0; j < h.length; j++)\n byteArray.push(parseInt(h[j], 16))\n }\n }\n return byteArray\n}\n\nfunction asciiToBytes (str) {\n var byteArray = []\n for (var i = 0; i < str.length; i++) {\n // Node's code seems to be doing this and not & 0x7F..\n byteArray.push(str.charCodeAt(i) & 0xFF)\n }\n return byteArray\n}\n\nfunction utf16leToBytes (str) {\n var c, hi, lo\n var byteArray = []\n for (var i = 0; i < str.length; i++) {\n c = str.charCodeAt(i)\n hi = c >> 8\n lo = c % 256\n byteArray.push(lo)\n byteArray.push(hi)\n }\n\n return byteArray\n}\n\nfunction base64ToBytes (str) {\n return base64.toByteArray(str)\n}\n\nfunction blitBuffer (src, dst, offset, length) {\n var pos\n for (var i = 0; i < length; i++) {\n if ((i + offset >= dst.length) || (i >= src.length))\n break\n dst[i + offset] = src[i]\n }\n return i\n}\n\nfunction decodeUtf8Char (str) {\n try {\n return decodeURIComponent(str)\n } catch (err) {\n return String.fromCharCode(0xFFFD) // UTF 8 invalid char\n }\n}\n\n/*\n * We have to make sure that the value is a valid integer. This means that it\n * is non-negative. It has no fractional component and that it does not\n * exceed the maximum allowed value.\n */\nfunction verifuint (value, max) {\n assert(typeof value === 'number', 'cannot write a non-number as a number')\n assert(value >= 0, 'specified a negative value for writing an unsigned value')\n assert(value <= max, 'value is larger than maximum value for type')\n assert(Math.floor(value) === value, 'value has a fractional component')\n}\n\nfunction verifsint (value, max, min) {\n assert(typeof value === 'number', 'cannot write a non-number as a number')\n assert(value <= max, 'value larger than maximum allowed value')\n assert(value >= min, 'value smaller than minimum allowed value')\n assert(Math.floor(value) === value, 'value has a fractional component')\n}\n\nfunction verifIEEE754 (value, max, min) {\n assert(typeof value === 'number', 'cannot write a non-number as a number')\n assert(value <= max, 'value larger than maximum allowed value')\n assert(value >= min, 'value smaller than minimum allowed value')\n}\n\nfunction assert (test, message) {\n if (!test) throw new Error(message || 'Failed assertion')\n}\n", - "var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n;(function (exports) {\n\t'use strict';\n\n var Arr = (typeof Uint8Array !== 'undefined')\n ? Uint8Array\n : Array\n\n\tvar ZERO = '0'.charCodeAt(0)\n\tvar PLUS = '+'.charCodeAt(0)\n\tvar SLASH = '/'.charCodeAt(0)\n\tvar NUMBER = '0'.charCodeAt(0)\n\tvar LOWER = 'a'.charCodeAt(0)\n\tvar UPPER = 'A'.charCodeAt(0)\n\n\tfunction decode (elt) {\n\t\tvar code = elt.charCodeAt(0)\n\t\tif (code === PLUS)\n\t\t\treturn 62 // '+'\n\t\tif (code === SLASH)\n\t\t\treturn 63 // '/'\n\t\tif (code < NUMBER)\n\t\t\treturn -1 //no match\n\t\tif (code < NUMBER + 10)\n\t\t\treturn code - NUMBER + 26 + 26\n\t\tif (code < UPPER + 26)\n\t\t\treturn code - UPPER\n\t\tif (code < LOWER + 26)\n\t\t\treturn code - LOWER + 26\n\t}\n\n\tfunction b64ToByteArray (b64) {\n\t\tvar i, j, l, tmp, placeHolders, arr\n\n\t\tif (b64.length % 4 > 0) {\n\t\t\tthrow new Error('Invalid string. Length must be a multiple of 4')\n\t\t}\n\n\t\t// the number of equal signs (place holders)\n\t\t// if there are two placeholders, than the two characters before it\n\t\t// represent one byte\n\t\t// if there is only one, then the three characters before it represent 2 bytes\n\t\t// this is just a cheap hack to not do indexOf twice\n\t\tvar len = b64.length\n\t\tplaceHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0\n\n\t\t// base64 is 4/3 + up to two characters of the original data\n\t\tarr = new Arr(b64.length * 3 / 4 - placeHolders)\n\n\t\t// if there are placeholders, only get up to the last complete 4 chars\n\t\tl = placeHolders > 0 ? b64.length - 4 : b64.length\n\n\t\tvar L = 0\n\n\t\tfunction push (v) {\n\t\t\tarr[L++] = v\n\t\t}\n\n\t\tfor (i = 0, j = 0; i < l; i += 4, j += 3) {\n\t\t\ttmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))\n\t\t\tpush((tmp & 0xFF0000) >> 16)\n\t\t\tpush((tmp & 0xFF00) >> 8)\n\t\t\tpush(tmp & 0xFF)\n\t\t}\n\n\t\tif (placeHolders === 2) {\n\t\t\ttmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)\n\t\t\tpush(tmp & 0xFF)\n\t\t} else if (placeHolders === 1) {\n\t\t\ttmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)\n\t\t\tpush((tmp >> 8) & 0xFF)\n\t\t\tpush(tmp & 0xFF)\n\t\t}\n\n\t\treturn arr\n\t}\n\n\tfunction uint8ToBase64 (uint8) {\n\t\tvar i,\n\t\t\textraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes\n\t\t\toutput = \"\",\n\t\t\ttemp, length\n\n\t\tfunction encode (num) {\n\t\t\treturn lookup.charAt(num)\n\t\t}\n\n\t\tfunction tripletToBase64 (num) {\n\t\t\treturn encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)\n\t\t}\n\n\t\t// go through the array every three bytes, we'll deal with trailing stuff later\n\t\tfor (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {\n\t\t\ttemp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])\n\t\t\toutput += tripletToBase64(temp)\n\t\t}\n\n\t\t// pad the end with zeros, but make sure to not forget the extra bytes\n\t\tswitch (extraBytes) {\n\t\t\tcase 1:\n\t\t\t\ttemp = uint8[uint8.length - 1]\n\t\t\t\toutput += encode(temp >> 2)\n\t\t\t\toutput += encode((temp << 4) & 0x3F)\n\t\t\t\toutput += '=='\n\t\t\t\tbreak\n\t\t\tcase 2:\n\t\t\t\ttemp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])\n\t\t\t\toutput += encode(temp >> 10)\n\t\t\t\toutput += encode((temp >> 4) & 0x3F)\n\t\t\t\toutput += encode((temp << 2) & 0x3F)\n\t\t\t\toutput += '='\n\t\t\t\tbreak\n\t\t}\n\n\t\treturn output\n\t}\n\n\tmodule.exports.toByteArray = b64ToByteArray\n\tmodule.exports.fromByteArray = uint8ToBase64\n}())\n", - "exports.read = function(buffer, offset, isLE, mLen, nBytes) {\n var e, m,\n eLen = nBytes * 8 - mLen - 1,\n eMax = (1 << eLen) - 1,\n eBias = eMax >> 1,\n nBits = -7,\n i = isLE ? (nBytes - 1) : 0,\n d = isLE ? -1 : 1,\n s = buffer[offset + i];\n\n i += d;\n\n e = s & ((1 << (-nBits)) - 1);\n s >>= (-nBits);\n nBits += eLen;\n for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8);\n\n m = e & ((1 << (-nBits)) - 1);\n e >>= (-nBits);\n nBits += mLen;\n for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8);\n\n if (e === 0) {\n e = 1 - eBias;\n } else if (e === eMax) {\n return m ? NaN : ((s ? -1 : 1) * Infinity);\n } else {\n m = m + Math.pow(2, mLen);\n e = e - eBias;\n }\n return (s ? -1 : 1) * m * Math.pow(2, e - mLen);\n};\n\nexports.write = function(buffer, value, offset, isLE, mLen, nBytes) {\n var e, m, c,\n eLen = nBytes * 8 - mLen - 1,\n eMax = (1 << eLen) - 1,\n eBias = eMax >> 1,\n rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),\n i = isLE ? 0 : (nBytes - 1),\n d = isLE ? 1 : -1,\n s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;\n\n value = Math.abs(value);\n\n if (isNaN(value) || value === Infinity) {\n m = isNaN(value) ? 1 : 0;\n e = eMax;\n } else {\n e = Math.floor(Math.log(value) / Math.LN2);\n if (value * (c = Math.pow(2, -e)) < 1) {\n e--;\n c *= 2;\n }\n if (e + eBias >= 1) {\n value += rt / c;\n } else {\n value += rt * Math.pow(2, 1 - eBias);\n }\n if (value * c >= 2) {\n e++;\n c /= 2;\n }\n\n if (e + eBias >= eMax) {\n m = 0;\n e = eMax;\n } else if (e + eBias >= 1) {\n m = (value * c - 1) * Math.pow(2, mLen);\n e = e + eBias;\n } else {\n m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);\n e = 0;\n }\n }\n\n for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8);\n\n e = (e << mLen) | m;\n eLen += mLen;\n for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8);\n\n buffer[offset + i - d] |= s * 128;\n};\n" + "var extend = require('deep-extend'),\n //clone = require('clone'),\n\tconverter = require('./converter.js');\n\n//g2svg as geojson2svg (shorthand)\nvar g2svg = function(viewportSize,options) {\n if(!viewportSize) return;\n this.viewportSize = viewportSize;\n this.options = options || {};\n this.mapExtent = this.options.mapExtent \n || {'left':-180,'bottom':-90,'right':180,'top':90}; \n this.res = this.calResolution(this.mapExtent,this.viewportSize);\n};\ng2svg.prototype.calResolution = function(extent,size) {\n var xres = (extent.right - extent.left)/size.width;\n var yres = (extent.top - extent.bottom)/size.height;\n return Math.max(xres,yres);\n};\ng2svg.prototype.convert = function(geojson,options) {\n var opt = extend(extend({},this.options), options || {});\n var multiGeometries = ['MultiPoint','MultiLineString','MultiPolygon'];\n var geometries = ['Point', 'LineString', 'Polygon'];\n var svgElements = [];\n if (geojson.type == 'FeatureCollection') {\n for(var i=0; i< geojson.features.length; i++) {\n svgElements = svgElements.concat(\n this.convertFeature(geojson.features[i],opt));\n }\n } else if (geojson.type == 'Feature') {\n svgElements = this.convertFeature(geojson,opt);\n } else if (geojson.type == 'GeomtryCollection') {\n for(var i=0; i< geojson.geometries.length; i++) {\n svgElements = svgElements.concat(\n this.convertGeometry(geojson.geometries[i],opt));\n }\n } else if (converter[geojson.type]) {\n svgElements = this.convertGeometry(geojson,opt);\n } else {\n return;\n }\n if(opt.callback) opt.callback.call(this,svgElements);\n return svgElements;\n};\ng2svg.prototype.convertFeature = function(feature,options) {\n if(!feature && !feature.geometry) return;\n var opt = extend(extend({},this.options), options || {});\n opt.attributes = opt.attributes || {};\n opt.attributes.id = opt.attributes.id || feature.id || null;\n return this.convertGeometry(feature.geometry,opt);\n};\ng2svg.prototype.convertGeometry = function(geom,options) {\n if(converter[geom.type]) {\n var opt = extend(extend({},this.options), options || {});\n //var explode = opt.hasOwnProperty('explode') ? opt.explode : false;\n var paths = converter[geom.type].call(this,geom,\n this.res,\n {x:this.mapExtent.left,y:this.mapExtent.top},\n opt\n );\n var svgJsons,svgEles;\n if(opt.output && opt.output.toLowerCase() == 'svg') {\n svgJsons = paths.map(function(path) {\n return pathToSvgJson(path,geom.type,opt.attributes,opt);\n });\n svgEles = svgJsons.map(function(json) {\n return jsonToSvgElement(json,geom.type);\n });\n return svgEles;\n }\n return paths;\n } else {\n return;\n }\n};\nvar pathToSvgJson = function(path,type,attributes,opt) {\n var svg = {};\n var forcePath = opt && opt.hasOwnProperty('forcePath') ? opt.forcePath\n : true;\n if((type == 'Point' || type == 'MultiPoint') && !forcePath) {\n svg['cx'] = path.split(',')[0];\n svg['cy'] = path.split(',')[1];\n svg['r'] = opt && opt.r ? opt.r : '1';\n } else {\n svg = {d: path};\n if(type == 'Polygon' || type == 'MultiPolygon') {\n svg['fill-rule'] == 'evenodd'; \n } \n }\n for (var key in attributes) {\n svg[key]= attributes[key];\n }\n return svg;\n};\nvar jsonToSvgElement = function(json,type,opt) {\n var forcePath = opt && opt.hasOwnProperty('forcePath') ? opt.forcePath\n : true;\n var ele =' - +

World Map

diff --git a/package.json b/package.json index b310fd2..10c2ef2 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,14 @@ { "name": "geojson2svg", - "version": "0.0.6", + "version": "0.0.7", "description": "Converts geojson to svg/path string given svg viewport size and maps extent.", "main": "src/main.js", "scripts": { - "test": "test/test.js" + "test": "mocha", + "build-debug": "browserify src/main.js --debug --standalone geojson2svg | exorcist dist/geojson2svg.js.map > dist/geojson2svg.js", + "build-min": "browserify src/main.js --standalone geojson2svg | uglifyjs -c > dist/geojson2svg.min.js", + "build": "npm run build-debug && npm run build-min", + "watch": "watchify src/main.js --debug --standalone geojson2svg -o dist/geojson2svg.js -v" }, "keywords": [ "maps", @@ -18,18 +22,16 @@ "auther": "Gagan Bansal", "license": "MIT", "dependencies": { - "clone": "~0.1.11", "deep-extend": "~0.2.8", "multigeojson": "0.0.0" }, "devDependencies": { - "mocha": "~1.17.1", + "browserify": "^3.46.0", "chai": "~1.9.0", + "jsdom": "~0.10.5", + "mocha": "~1.17.1", "parse-svg-path": "~0.1.1", - "expect.js": "~0.3.1", - "jsdom": "~0.10.5" - }, - "scripts": { - "test": "mocha" + "uglify-js": "^2.4.13", + "watchify": "^0.8.3" } } diff --git a/src/instance.js b/src/instance.js index 7703c57..fadcf02 100644 --- a/src/instance.js +++ b/src/instance.js @@ -1,5 +1,4 @@ var extend = require('deep-extend'), - clone = require('clone'), converter = require('./converter.js'); //g2svg as geojson2svg (shorthand) @@ -17,7 +16,7 @@ g2svg.prototype.calResolution = function(extent,size) { return Math.max(xres,yres); }; g2svg.prototype.convert = function(geojson,options) { - var opt = extend(clone(this.options), options || {}); + var opt = extend(extend({},this.options), options || {}); var multiGeometries = ['MultiPoint','MultiLineString','MultiPolygon']; var geometries = ['Point', 'LineString', 'Polygon']; var svgElements = []; @@ -43,14 +42,14 @@ g2svg.prototype.convert = function(geojson,options) { }; g2svg.prototype.convertFeature = function(feature,options) { if(!feature && !feature.geometry) return; - var opt = extend(clone(this.options), options || {}); + var opt = extend(extend({},this.options), options || {}); opt.attributes = opt.attributes || {}; opt.attributes.id = opt.attributes.id || feature.id || null; return this.convertGeometry(feature.geometry,opt); }; g2svg.prototype.convertGeometry = function(geom,options) { if(converter[geom.type]) { - var opt = extend(clone(this.options), options || {}); + var opt = extend(extend({},this.options), options || {}); //var explode = opt.hasOwnProperty('explode') ? opt.explode : false; var paths = converter[geom.type].call(this,geom, this.res,