code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function JSONPPolling (socket) {
io.Transport['xhr-polling'].apply(this, arguments);
this.index = io.j.length;
var self = this;
io.j.push(function (msg) {
self._(msg);
});
} | The JSONP transport creates an persistent connection by dynamically
inserting a script tag in the page. This script tag will receive the
information of the Socket.IO server. When new information is received
it creates a new script tag for the new data stream.
@constructor
@extends {io.Transport.xhr-polling}
@api public | JSONPPolling | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/socket.io.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/socket.io.js | MIT |
function complete () {
initIframe();
self.socket.setBuffer(false);
} | Posts a encoded message to the Socket.IO server using an iframe.
The iframe is used because script tags can create POST based requests.
The iframe is positioned outside of the view so the user does not
notice it's existence.
@param {String} data A encoded message.
@api private | complete | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/socket.io.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/socket.io.js | MIT |
function initIframe () {
if (self.iframe) {
self.form.removeChild(self.iframe);
}
try {
// ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
iframe = document.createElement('<iframe name="'+ self.iframeId +'">');
} catch (e) {
iframe = document.createElement('iframe');
iframe.name = self.iframeId;
}
iframe.id = self.iframeId;
self.form.appendChild(iframe);
self.iframe = iframe;
} | Posts a encoded message to the Socket.IO server using an iframe.
The iframe is used because script tags can create POST based requests.
The iframe is positioned outside of the view so the user does not
notice it's existence.
@param {String} data A encoded message.
@api private | initIframe | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/socket.io.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/socket.io.js | MIT |
function Buffer (arg, encodingOrOffset, length) {
if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer)) {
return new Buffer(arg, encodingOrOffset, length)
}
// Common case.
if (typeof arg === 'number') {
if (typeof encodingOrOffset === 'string') {
throw new Error(
'If encoding is specified then the first argument must be a string'
)
}
return allocUnsafe(this, arg)
}
return from(this, arg, encodingOrOffset, length)
} | The Buffer constructor returns instances of `Uint8Array` that have their
prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
`Uint8Array`, so the returned instances will have all the node `Buffer` methods
and the `Uint8Array` methods. Square bracket notation works as expected -- it
returns a single octet.
The `Uint8Array` prototype remains unmodified. | Buffer | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function from (that, value, encodingOrOffset, length) {
if (typeof value === 'number') {
throw new TypeError('"value" argument must not be a number')
}
if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) {
return fromArrayBuffer(that, value, encodingOrOffset, length)
}
if (typeof value === 'string') {
return fromString(that, value, encodingOrOffset)
}
return fromObject(that, value)
} | The Buffer constructor returns instances of `Uint8Array` that have their
prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
`Uint8Array`, so the returned instances will have all the node `Buffer` methods
and the `Uint8Array` methods. Square bracket notation works as expected -- it
returns a single octet.
The `Uint8Array` prototype remains unmodified. | from | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function assertSize (size) {
if (typeof size !== 'number') {
throw new TypeError('"size" argument must be a number')
} else if (size < 0) {
throw new RangeError('"size" argument must not be negative')
}
} | Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
if value is a number.
Buffer.from(str[, encoding])
Buffer.from(array)
Buffer.from(buffer)
Buffer.from(arrayBuffer[, byteOffset[, length]]) | assertSize | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function alloc (that, size, fill, encoding) {
assertSize(size)
if (size <= 0) {
return createBuffer(that, size)
}
if (fill !== undefined) {
// Only pay attention to encoding if it's a string. This
// prevents accidentally sending in a number that would
// be interpretted as a start offset.
return typeof encoding === 'string'
? createBuffer(that, size).fill(fill, encoding)
: createBuffer(that, size).fill(fill)
}
return createBuffer(that, size)
} | Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
if value is a number.
Buffer.from(str[, encoding])
Buffer.from(array)
Buffer.from(buffer)
Buffer.from(arrayBuffer[, byteOffset[, length]]) | alloc | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function allocUnsafe (that, size) {
assertSize(size)
that = createBuffer(that, size < 0 ? 0 : checked(size) | 0)
if (!Buffer.TYPED_ARRAY_SUPPORT) {
for (var i = 0; i < size; ++i) {
that[i] = 0
}
}
return that
} | Creates a new filled Buffer instance.
alloc(size[, fill[, encoding]]) | allocUnsafe | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function fromString (that, string, encoding) {
if (typeof encoding !== 'string' || encoding === '') {
encoding = 'utf8'
}
if (!Buffer.isEncoding(encoding)) {
throw new TypeError('"encoding" must be a valid string encoding')
}
var length = byteLength(string, encoding) | 0
that = createBuffer(that, length)
var actual = that.write(string, encoding)
if (actual !== length) {
// Writing a hex string, for example, that contains invalid characters will
// cause everything after the first invalid character to be ignored. (e.g.
// 'abxxcd' will be treated as 'ab')
that = that.slice(0, actual)
}
return that
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | fromString | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function fromArrayLike (that, array) {
var length = array.length < 0 ? 0 : checked(array.length) | 0
that = createBuffer(that, length)
for (var i = 0; i < length; i += 1) {
that[i] = array[i] & 255
}
return that
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | fromArrayLike | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function fromArrayBuffer (that, array, byteOffset, length) {
array.byteLength // this throws if `array` is not a valid ArrayBuffer
if (byteOffset < 0 || array.byteLength < byteOffset) {
throw new RangeError('\'offset\' is out of bounds')
}
if (array.byteLength < byteOffset + (length || 0)) {
throw new RangeError('\'length\' is out of bounds')
}
if (byteOffset === undefined && length === undefined) {
array = new Uint8Array(array)
} else if (length === undefined) {
array = new Uint8Array(array, byteOffset)
} else {
array = new Uint8Array(array, byteOffset, length)
}
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
that = array
that.__proto__ = Buffer.prototype
} else {
// Fallback: Return an object instance of the Buffer class
that = fromArrayLike(that, array)
}
return that
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | fromArrayBuffer | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function fromObject (that, obj) {
if (Buffer.isBuffer(obj)) {
var len = checked(obj.length) | 0
that = createBuffer(that, len)
if (that.length === 0) {
return that
}
obj.copy(that, 0, 0, len)
return that
}
if (obj) {
if ((typeof ArrayBuffer !== 'undefined' &&
obj.buffer instanceof ArrayBuffer) || 'length' in obj) {
if (typeof obj.length !== 'number' || isnan(obj.length)) {
return createBuffer(that, 0)
}
return fromArrayLike(that, obj)
}
if (obj.type === 'Buffer' && isArray(obj.data)) {
return fromArrayLike(that, obj.data)
}
}
throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.')
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | fromObject | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function checked (length) {
// Note: cannot use `length < kMaxLength()` here because that fails when
// length is NaN (which is otherwise coerced to zero.)
if (length >= kMaxLength()) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
'size: 0x' + kMaxLength().toString(16) + ' bytes')
}
return length | 0
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | checked | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function SlowBuffer (length) {
if (+length != length) { // eslint-disable-line eqeqeq
length = 0
}
return Buffer.alloc(+length)
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | SlowBuffer | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function byteLength (string, encoding) {
if (Buffer.isBuffer(string)) {
return string.length
}
if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
(ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) {
return string.byteLength
}
if (typeof string !== 'string') {
string = '' + string
}
var len = string.length
if (len === 0) return 0
// Use a for loop to avoid recursion
var loweredCase = false
for (;;) {
switch (encoding) {
case 'ascii':
case 'latin1':
case 'binary':
return len
case 'utf8':
case 'utf-8':
case undefined:
return utf8ToBytes(string).length
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return len * 2
case 'hex':
return len >>> 1
case 'base64':
return base64ToBytes(string).length
default:
if (loweredCase) return utf8ToBytes(string).length // assume utf8
encoding = ('' + encoding).toLowerCase()
loweredCase = true
}
}
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | byteLength | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function slowToString (encoding, start, end) {
var loweredCase = false
// No need to verify that "this.length <= MAX_UINT32" since it's a read-only
// property of a typed array.
// This behaves neither like String nor Uint8Array in that we set start/end
// to their upper/lower bounds if the value passed is out of range.
// undefined is handled specially as per ECMA-262 6th Edition,
// Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
if (start === undefined || start < 0) {
start = 0
}
// Return early if start > this.length. Done here to prevent potential uint32
// coercion fail below.
if (start > this.length) {
return ''
}
if (end === undefined || end > this.length) {
end = this.length
}
if (end <= 0) {
return ''
}
// Force coersion to uint32. This will also coerce falsey/NaN values to 0.
end >>>= 0
start >>>= 0
if (end <= start) {
return ''
}
if (!encoding) encoding = 'utf8'
while (true) {
switch (encoding) {
case 'hex':
return hexSlice(this, start, end)
case 'utf8':
case 'utf-8':
return utf8Slice(this, start, end)
case 'ascii':
return asciiSlice(this, start, end)
case 'latin1':
case 'binary':
return latin1Slice(this, start, end)
case 'base64':
return base64Slice(this, start, end)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return utf16leSlice(this, start, end)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = (encoding + '').toLowerCase()
loweredCase = true
}
}
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | slowToString | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function swap (b, n, m) {
var i = b[n]
b[n] = b[m]
b[m] = i
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | swap | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) {
// Empty buffer means no match
if (buffer.length === 0) return -1
// Normalize byteOffset
if (typeof byteOffset === 'string') {
encoding = byteOffset
byteOffset = 0
} else if (byteOffset > 0x7fffffff) {
byteOffset = 0x7fffffff
} else if (byteOffset < -0x80000000) {
byteOffset = -0x80000000
}
byteOffset = +byteOffset // Coerce to Number.
if (isNaN(byteOffset)) {
// byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
byteOffset = dir ? 0 : (buffer.length - 1)
}
// Normalize byteOffset: negative offsets start from the end of the buffer
if (byteOffset < 0) byteOffset = buffer.length + byteOffset
if (byteOffset >= buffer.length) {
if (dir) return -1
else byteOffset = buffer.length - 1
} else if (byteOffset < 0) {
if (dir) byteOffset = 0
else return -1
}
// Normalize val
if (typeof val === 'string') {
val = Buffer.from(val, encoding)
}
// Finally, search either indexOf (if dir is true) or lastIndexOf
if (Buffer.isBuffer(val)) {
// Special case: looking for empty string/buffer always fails
if (val.length === 0) {
return -1
}
return arrayIndexOf(buffer, val, byteOffset, encoding, dir)
} else if (typeof val === 'number') {
val = val & 0xFF // Search for a byte value [0-255]
if (Buffer.TYPED_ARRAY_SUPPORT &&
typeof Uint8Array.prototype.indexOf === 'function') {
if (dir) {
return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset)
} else {
return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset)
}
}
return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir)
}
throw new TypeError('val must be string, number or Buffer')
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | bidirectionalIndexOf | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function arrayIndexOf (arr, val, byteOffset, encoding, dir) {
var indexSize = 1
var arrLength = arr.length
var valLength = val.length
if (encoding !== undefined) {
encoding = String(encoding).toLowerCase()
if (encoding === 'ucs2' || encoding === 'ucs-2' ||
encoding === 'utf16le' || encoding === 'utf-16le') {
if (arr.length < 2 || val.length < 2) {
return -1
}
indexSize = 2
arrLength /= 2
valLength /= 2
byteOffset /= 2
}
}
function read (buf, i) {
if (indexSize === 1) {
return buf[i]
} else {
return buf.readUInt16BE(i * indexSize)
}
}
var i
if (dir) {
var foundIndex = -1
for (i = byteOffset; i < arrLength; i++) {
if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
if (foundIndex === -1) foundIndex = i
if (i - foundIndex + 1 === valLength) return foundIndex * indexSize
} else {
if (foundIndex !== -1) i -= i - foundIndex
foundIndex = -1
}
}
} else {
if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength
for (i = byteOffset; i >= 0; i--) {
var found = true
for (var j = 0; j < valLength; j++) {
if (read(arr, i + j) !== read(val, j)) {
found = false
break
}
}
if (found) return i
}
}
return -1
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | arrayIndexOf | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function read (buf, i) {
if (indexSize === 1) {
return buf[i]
} else {
return buf.readUInt16BE(i * indexSize)
}
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | read | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function hexWrite (buf, string, offset, length) {
offset = Number(offset) || 0
var remaining = buf.length - offset
if (!length) {
length = remaining
} else {
length = Number(length)
if (length > remaining) {
length = remaining
}
}
// must be an even number of digits
var strLen = string.length
if (strLen % 2 !== 0) throw new TypeError('Invalid hex string')
if (length > strLen / 2) {
length = strLen / 2
}
for (var i = 0; i < length; ++i) {
var parsed = parseInt(string.substr(i * 2, 2), 16)
if (isNaN(parsed)) return i
buf[offset + i] = parsed
}
return i
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | hexWrite | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function utf8Write (buf, string, offset, length) {
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | utf8Write | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function asciiWrite (buf, string, offset, length) {
return blitBuffer(asciiToBytes(string), buf, offset, length)
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | asciiWrite | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function latin1Write (buf, string, offset, length) {
return asciiWrite(buf, string, offset, length)
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | latin1Write | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function base64Write (buf, string, offset, length) {
return blitBuffer(base64ToBytes(string), buf, offset, length)
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | base64Write | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function ucs2Write (buf, string, offset, length) {
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | ucs2Write | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function base64Slice (buf, start, end) {
if (start === 0 && end === buf.length) {
return base64.fromByteArray(buf)
} else {
return base64.fromByteArray(buf.slice(start, end))
}
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | base64Slice | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function utf8Slice (buf, start, end) {
end = Math.min(buf.length, end)
var res = []
var i = start
while (i < end) {
var firstByte = buf[i]
var codePoint = null
var bytesPerSequence = (firstByte > 0xEF) ? 4
: (firstByte > 0xDF) ? 3
: (firstByte > 0xBF) ? 2
: 1
if (i + bytesPerSequence <= end) {
var secondByte, thirdByte, fourthByte, tempCodePoint
switch (bytesPerSequence) {
case 1:
if (firstByte < 0x80) {
codePoint = firstByte
}
break
case 2:
secondByte = buf[i + 1]
if ((secondByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
if (tempCodePoint > 0x7F) {
codePoint = tempCodePoint
}
}
break
case 3:
secondByte = buf[i + 1]
thirdByte = buf[i + 2]
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
codePoint = tempCodePoint
}
}
break
case 4:
secondByte = buf[i + 1]
thirdByte = buf[i + 2]
fourthByte = buf[i + 3]
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
codePoint = tempCodePoint
}
}
}
}
if (codePoint === null) {
// we did not generate a valid codePoint so insert a
// replacement char (U+FFFD) and advance only 1 byte
codePoint = 0xFFFD
bytesPerSequence = 1
} else if (codePoint > 0xFFFF) {
// encode to utf16 (surrogate pair dance)
codePoint -= 0x10000
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
codePoint = 0xDC00 | codePoint & 0x3FF
}
res.push(codePoint)
i += bytesPerSequence
}
return decodeCodePointsArray(res)
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | utf8Slice | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function decodeCodePointsArray (codePoints) {
var len = codePoints.length
if (len <= MAX_ARGUMENTS_LENGTH) {
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
}
// Decode in chunks to avoid "call stack size exceeded".
var res = ''
var i = 0
while (i < len) {
res += String.fromCharCode.apply(
String,
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
)
}
return res
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | decodeCodePointsArray | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function asciiSlice (buf, start, end) {
var ret = ''
end = Math.min(buf.length, end)
for (var i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i] & 0x7F)
}
return ret
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | asciiSlice | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function latin1Slice (buf, start, end) {
var ret = ''
end = Math.min(buf.length, end)
for (var i = start; i < end; ++i) {
ret += String.fromCharCode(buf[i])
}
return ret
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | latin1Slice | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
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
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | hexSlice | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
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
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | utf16leSlice | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function checkOffset (offset, ext, length) {
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | checkOffset | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function checkInt (buf, value, offset, ext, max, min) {
if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance')
if (value > max || value < min) throw new RangeError('"value" argument is out of bounds')
if (offset + ext > buf.length) throw new RangeError('Index out of range')
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | checkInt | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function objectWriteUInt16 (buf, value, offset, littleEndian) {
if (value < 0) value = 0xffff + value + 1
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; ++i) {
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
(littleEndian ? i : 1 - i) * 8
}
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | objectWriteUInt16 | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function objectWriteUInt32 (buf, value, offset, littleEndian) {
if (value < 0) value = 0xffffffff + value + 1
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; ++i) {
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
}
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | objectWriteUInt32 | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function checkIEEE754 (buf, value, offset, ext, max, min) {
if (offset + ext > buf.length) throw new RangeError('Index out of range')
if (offset < 0) throw new RangeError('Index out of range')
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | checkIEEE754 | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function writeFloat (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
}
ieee754.write(buf, value, offset, littleEndian, 23, 4)
return offset + 4
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | writeFloat | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function writeDouble (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
}
ieee754.write(buf, value, offset, littleEndian, 52, 8)
return offset + 8
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | writeDouble | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function base64clean (str) {
// Node strips out invalid characters like \n and \t from the string, base64-js does not
str = stringtrim(str).replace(INVALID_BASE64_RE, '')
// Node converts strings with length < 2 to ''
if (str.length < 2) return ''
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
while (str.length % 4 !== 0) {
str = str + '='
}
return str
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | base64clean | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function stringtrim (str) {
if (str.trim) return str.trim()
return str.replace(/^\s+|\s+$/g, '')
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | stringtrim | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function toHex (n) {
if (n < 16) return '0' + n.toString(16)
return n.toString(16)
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | toHex | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function utf8ToBytes (string, units) {
units = units || Infinity
var codePoint
var length = string.length
var leadSurrogate = null
var bytes = []
for (var i = 0; i < length; ++i) {
codePoint = string.charCodeAt(i)
// is surrogate component
if (codePoint > 0xD7FF && codePoint < 0xE000) {
// last char was a lead
if (!leadSurrogate) {
// no lead yet
if (codePoint > 0xDBFF) {
// unexpected trail
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
continue
} else if (i + 1 === length) {
// unpaired lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
continue
}
// valid lead
leadSurrogate = codePoint
continue
}
// 2 leads in a row
if (codePoint < 0xDC00) {
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
leadSurrogate = codePoint
continue
}
// valid surrogate pair
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
} else if (leadSurrogate) {
// valid bmp char, but last char was a lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
}
leadSurrogate = null
// encode utf8
if (codePoint < 0x80) {
if ((units -= 1) < 0) break
bytes.push(codePoint)
} else if (codePoint < 0x800) {
if ((units -= 2) < 0) break
bytes.push(
codePoint >> 0x6 | 0xC0,
codePoint & 0x3F | 0x80
)
} else if (codePoint < 0x10000) {
if ((units -= 3) < 0) break
bytes.push(
codePoint >> 0xC | 0xE0,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
)
} else if (codePoint < 0x110000) {
if ((units -= 4) < 0) break
bytes.push(
codePoint >> 0x12 | 0xF0,
codePoint >> 0xC & 0x3F | 0x80,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
)
} else {
throw new Error('Invalid code point')
}
}
return bytes
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | utf8ToBytes | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
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
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | asciiToBytes | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function utf16leToBytes (str, units) {
var c, hi, lo
var byteArray = []
for (var i = 0; i < str.length; ++i) {
if ((units -= 2) < 0) break
c = str.charCodeAt(i)
hi = c >> 8
lo = c % 256
byteArray.push(lo)
byteArray.push(hi)
}
return byteArray
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | utf16leToBytes | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function base64ToBytes (str) {
return base64.toByteArray(base64clean(str))
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | base64ToBytes | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function blitBuffer (src, dst, offset, length) {
for (var i = 0; i < length; ++i) {
if ((i + offset >= dst.length) || (i >= src.length)) break
dst[i + offset] = src[i]
}
return i
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | blitBuffer | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isnan (val) {
return val !== val // eslint-disable-line no-self-compare
} | Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | isnan | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function calcLengthLength (length) {
if (length >= 0 && length < 128) return 1
else if (length >= 128 && length < 16384) return 2
else if (length >= 16384 && length < 2097152) return 3
else if (length >= 2097152 && length < 268435456) return 4
else return 0
} | calcLengthLength - calculate the length of the remaining
length field
@api private | calcLengthLength | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function genBufLength (length) {
var digit = 0
var pos = 0
var buffer = new Buffer(calcLengthLength(length))
do {
digit = length % 128 | 0
length = length / 128 | 0
if (length > 0) digit = digit | 0x80
buffer.writeUInt8(digit, pos++, true)
} while (length > 0)
return buffer
} | calcLengthLength - calculate the length of the remaining
length field
@api private | genBufLength | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function writeLength (stream, length) {
var buffer = lengthCache[length]
if (!buffer) {
buffer = genBufLength(length)
if (length < 16384) lengthCache[length] = buffer
}
stream.write(buffer)
} | writeLength - write an MQTT style length field to the buffer
@param <Buffer> buffer - destination
@param <Number> pos - offset
@param <Number> length - length (>0)
@returns <Number> number of bytes written
@api private | writeLength | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function writeString (stream, string) {
var strlen = Buffer.byteLength(string)
writeNumber(stream, strlen)
stream.write(string, 'utf8')
} | writeString - write a utf8 string to the buffer
@param <Buffer> buffer - destination
@param <Number> pos - offset
@param <String> string - string to write
@return <Number> number of bytes written
@api private | writeString | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function writeNumber (stream, number) {
return stream.write(numCache[number])
} | writeNumber - write a two byte number to the buffer
@param <Buffer> buffer - destination
@param <Number> pos - offset
@param <String> number - number to write
@return <Number> number of bytes written
@api private | writeNumber | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function writeStringOrBuffer (stream, toWrite) {
if (toWrite && typeof toWrite === 'string') writeString(stream, toWrite)
else if (toWrite) {
writeNumber(stream, toWrite.length)
stream.write(toWrite)
} else writeNumber(stream, 0)
} | writeStringOrBuffer - write a String or Buffer with the its length prefix
@param <Buffer> buffer - destination
@param <Number> pos - offset
@param <String> toWrite - String or Buffer
@return <Number> number of bytes written | writeStringOrBuffer | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function byteLength (bufOrString) {
if (!bufOrString) return 0
else if (Buffer.isBuffer(bufOrString)) return bufOrString.length
else return Buffer.byteLength(bufOrString)
} | writeStringOrBuffer - write a String or Buffer with the its length prefix
@param <Buffer> buffer - destination
@param <Number> pos - offset
@param <String> toWrite - String or Buffer
@return <Number> number of bytes written | byteLength | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function inspect(obj, opts) {
// default options
var ctx = {
seen: [],
stylize: stylizeNoColor
};
// legacy...
if (arguments.length >= 3) ctx.depth = arguments[2];
if (arguments.length >= 4) ctx.colors = arguments[3];
if (isBoolean(opts)) {
// legacy...
ctx.showHidden = opts;
} else if (opts) {
// got an "options" object
exports._extend(ctx, opts);
}
// set default options
if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
if (isUndefined(ctx.depth)) ctx.depth = 2;
if (isUndefined(ctx.colors)) ctx.colors = false;
if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
if (ctx.colors) ctx.stylize = stylizeWithColor;
return formatValue(ctx, obj, ctx.depth);
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | inspect | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function stylizeWithColor(str, styleType) {
var style = inspect.styles[styleType];
if (style) {
return '\u001b[' + inspect.colors[style][0] + 'm' + str +
'\u001b[' + inspect.colors[style][1] + 'm';
} else {
return str;
}
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | stylizeWithColor | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function stylizeNoColor(str, styleType) {
return str;
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | stylizeNoColor | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function arrayToHash(array) {
var hash = {};
array.forEach(function(val, idx) {
hash[val] = true;
});
return hash;
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | arrayToHash | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function formatValue(ctx, value, recurseTimes) {
// Provide a hook for user-specified inspect functions.
// Check that value is an object with an inspect function on it
if (ctx.customInspect &&
value &&
isFunction(value.inspect) &&
// Filter out the util module, it's inspect function is special
value.inspect !== exports.inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
var ret = value.inspect(recurseTimes, ctx);
if (!isString(ret)) {
ret = formatValue(ctx, ret, recurseTimes);
}
return ret;
}
// Primitive types cannot have properties
var primitive = formatPrimitive(ctx, value);
if (primitive) {
return primitive;
}
// Look up the keys of the object.
var keys = Object.keys(value);
var visibleKeys = arrayToHash(keys);
if (ctx.showHidden) {
keys = Object.getOwnPropertyNames(value);
}
// IE doesn't make error fields non-enumerable
// http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
if (isError(value)
&& (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
return formatError(value);
}
// Some type of object without properties can be shortcutted.
if (keys.length === 0) {
if (isFunction(value)) {
var name = value.name ? ': ' + value.name : '';
return ctx.stylize('[Function' + name + ']', 'special');
}
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
}
if (isDate(value)) {
return ctx.stylize(Date.prototype.toString.call(value), 'date');
}
if (isError(value)) {
return formatError(value);
}
}
var base = '', array = false, braces = ['{', '}'];
// Make Array say that they are Array
if (isArray(value)) {
array = true;
braces = ['[', ']'];
}
// Make functions say that they are functions
if (isFunction(value)) {
var n = value.name ? ': ' + value.name : '';
base = ' [Function' + n + ']';
}
// Make RegExps say that they are RegExps
if (isRegExp(value)) {
base = ' ' + RegExp.prototype.toString.call(value);
}
// Make dates with properties first say the date
if (isDate(value)) {
base = ' ' + Date.prototype.toUTCString.call(value);
}
// Make error with message first say the error
if (isError(value)) {
base = ' ' + formatError(value);
}
if (keys.length === 0 && (!array || value.length == 0)) {
return braces[0] + base + braces[1];
}
if (recurseTimes < 0) {
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
} else {
return ctx.stylize('[Object]', 'special');
}
}
ctx.seen.push(value);
var output;
if (array) {
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
} else {
output = keys.map(function(key) {
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
});
}
ctx.seen.pop();
return reduceToSingleString(output, base, braces);
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | formatValue | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function formatPrimitive(ctx, value) {
if (isUndefined(value))
return ctx.stylize('undefined', 'undefined');
if (isString(value)) {
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
.replace(/'/g, "\\'")
.replace(/\\"/g, '"') + '\'';
return ctx.stylize(simple, 'string');
}
if (isNumber(value))
return ctx.stylize('' + value, 'number');
if (isBoolean(value))
return ctx.stylize('' + value, 'boolean');
// For some reason typeof null is "object", so special case here.
if (isNull(value))
return ctx.stylize('null', 'null');
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | formatPrimitive | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function formatError(value) {
return '[' + Error.prototype.toString.call(value) + ']';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | formatError | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
var output = [];
for (var i = 0, l = value.length; i < l; ++i) {
if (hasOwnProperty(value, String(i))) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
String(i), true));
} else {
output.push('');
}
}
keys.forEach(function(key) {
if (!key.match(/^\d+$/)) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
key, true));
}
});
return output;
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | formatArray | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
var name, str, desc;
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
if (desc.get) {
if (desc.set) {
str = ctx.stylize('[Getter/Setter]', 'special');
} else {
str = ctx.stylize('[Getter]', 'special');
}
} else {
if (desc.set) {
str = ctx.stylize('[Setter]', 'special');
}
}
if (!hasOwnProperty(visibleKeys, key)) {
name = '[' + key + ']';
}
if (!str) {
if (ctx.seen.indexOf(desc.value) < 0) {
if (isNull(recurseTimes)) {
str = formatValue(ctx, desc.value, null);
} else {
str = formatValue(ctx, desc.value, recurseTimes - 1);
}
if (str.indexOf('\n') > -1) {
if (array) {
str = str.split('\n').map(function(line) {
return ' ' + line;
}).join('\n').substr(2);
} else {
str = '\n' + str.split('\n').map(function(line) {
return ' ' + line;
}).join('\n');
}
}
} else {
str = ctx.stylize('[Circular]', 'special');
}
}
if (isUndefined(name)) {
if (array && key.match(/^\d+$/)) {
return str;
}
name = JSON.stringify('' + key);
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
name = name.substr(1, name.length - 2);
name = ctx.stylize(name, 'name');
} else {
name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
.replace(/(^"|"$)/g, "'");
name = ctx.stylize(name, 'string');
}
}
return name + ': ' + str;
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | formatProperty | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function reduceToSingleString(output, base, braces) {
var numLinesEst = 0;
var length = output.reduce(function(prev, cur) {
numLinesEst++;
if (cur.indexOf('\n') >= 0) numLinesEst++;
return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
}, 0);
if (length > 60) {
return braces[0] +
(base === '' ? '' : base + '\n ') +
' ' +
output.join(',\n ') +
' ' +
braces[1];
}
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | reduceToSingleString | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isArray(ar) {
return Array.isArray(ar);
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isArray | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isBoolean(arg) {
return typeof arg === 'boolean';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isBoolean | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isNull(arg) {
return arg === null;
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isNull | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isNullOrUndefined(arg) {
return arg == null;
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isNullOrUndefined | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isNumber(arg) {
return typeof arg === 'number';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isNumber | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isString(arg) {
return typeof arg === 'string';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isString | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isSymbol(arg) {
return typeof arg === 'symbol';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isSymbol | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isUndefined(arg) {
return arg === void 0;
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isUndefined | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isRegExp(re) {
return isObject(re) && objectToString(re) === '[object RegExp]';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isRegExp | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isObject | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isDate(d) {
return isObject(d) && objectToString(d) === '[object Date]';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isDate | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isError(e) {
return isObject(e) &&
(objectToString(e) === '[object Error]' || e instanceof Error);
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isError | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isFunction(arg) {
return typeof arg === 'function';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isFunction | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function isPrimitive(arg) {
return arg === null ||
typeof arg === 'boolean' ||
typeof arg === 'number' ||
typeof arg === 'string' ||
typeof arg === 'symbol' || // ES6 symbol
typeof arg === 'undefined';
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | isPrimitive | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function objectToString(o) {
return Object.prototype.toString.call(o);
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | objectToString | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function pad(n) {
return n < 10 ? '0' + n.toString(10) : n.toString(10);
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | pad | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function timestamp() {
var d = new Date();
var time = [pad(d.getHours()),
pad(d.getMinutes()),
pad(d.getSeconds())].join(':');
return [d.getDate(), months[d.getMonth()], time].join(' ');
} | Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Object} opts Optional options object that alters the output. | timestamp | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
} | Inherit the prototype methods from one constructor into another.
The Function.prototype.inherits from lang.js rewritten as a standalone
function (not on Function.prototype). NOTE: If this file is to be loaded
during bootstrapping this function needs to be rewritten using some native
functions as prototype setup using normal JavaScript does not work as
expected during bootstrapping (see mirror.js in r114903).
@param {function} ctor Constructor function which needs to inherit the
prototype.
@param {function} superCtor Constructor function to inherit prototype from. | hasOwnProperty | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function MqttClient (streamBuilder, options) {
var k
var that = this
if (!(this instanceof MqttClient)) {
return new MqttClient(streamBuilder, options)
}
this.options = options || {}
// Defaults
for (k in defaultConnectOptions) {
if (typeof this.options[k] === 'undefined') {
this.options[k] = defaultConnectOptions[k]
} else {
this.options[k] = options[k]
}
}
this.options.clientId = this.options.clientId || defaultId()
this.streamBuilder = streamBuilder
// Inflight message storages
this.outgoingStore = this.options.outgoingStore || new Store()
this.incomingStore = this.options.incomingStore || new Store()
// Should QoS zero messages be queued when the connection is broken?
this.queueQoSZero = this.options.queueQoSZero === undefined ? true : this.options.queueQoSZero
// map of subscribed topics to support reconnection
this._subscribedTopics = {}
// Ping timer, setup in _setupPingTimer
this.pingTimer = null
// Is the client connected?
this.connected = false
// Are we disconnecting?
this.disconnecting = false
// Packet queue
this.queue = []
// connack timer
this.connackTimer = null
// Reconnect timer
this.reconnectTimer = null
// MessageIDs starting with 1
this.nextId = Math.floor(Math.random() * 65535)
// Inflight callbacks
this.outgoing = {}
// Mark connected on connect
this.on('connect', function () {
if (this.disconnected) {
return
}
this.connected = true
var outStore = null
outStore = this.outgoingStore.createStream()
// Control of stored messages
outStore.once('readable', function () {
function storeDeliver () {
var packet = outStore.read(1)
var cb
if (!packet) {
return
}
// Avoid unnecesary stream read operations when disconnected
if (!that.disconnecting && !that.reconnectTimer && that.options.reconnectPeriod > 0) {
outStore.read(0)
cb = that.outgoing[packet.messageId]
that.outgoing[packet.messageId] = function (err, status) {
// Ensure that the original callback passed in to publish gets invoked
if (cb) {
cb(err, status)
}
storeDeliver()
}
that._sendPacket(packet)
} else if (outStore.destroy) {
outStore.destroy()
}
}
storeDeliver()
})
.on('error', this.emit.bind(this, 'error'))
})
// Mark disconnected on stream close
this.on('close', function () {
this.connected = false
clearTimeout(this.connackTimer)
})
// Setup ping timer
this.on('connect', this._setupPingTimer)
// Send queued packets
this.on('connect', function () {
var queue = this.queue
function deliver () {
var entry = queue.shift()
var packet = null
if (!entry) {
return
}
packet = entry.packet
that._sendPacket(
packet,
function (err) {
if (entry.cb) {
entry.cb(err)
}
deliver()
}
)
}
deliver()
})
// resubscribe
this.on('connect', function () {
if (this.options.clean && Object.keys(this._subscribedTopics).length > 0) {
this.subscribe(this._subscribedTopics)
}
})
// Clear ping timer
this.on('close', function () {
if (that.pingTimer !== null) {
that.pingTimer.clear()
that.pingTimer = null
}
})
// Setup reconnect timer on disconnect
this.on('close', this._setupReconnect)
events.EventEmitter.call(this)
this._setupStream()
} | MqttClient constructor
@param {Stream} stream - stream
@param {Object} [options] - connection options
(see Connection#connect) | MqttClient | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function storeDeliver () {
var packet = outStore.read(1)
var cb
if (!packet) {
return
}
// Avoid unnecesary stream read operations when disconnected
if (!that.disconnecting && !that.reconnectTimer && that.options.reconnectPeriod > 0) {
outStore.read(0)
cb = that.outgoing[packet.messageId]
that.outgoing[packet.messageId] = function (err, status) {
// Ensure that the original callback passed in to publish gets invoked
if (cb) {
cb(err, status)
}
storeDeliver()
}
that._sendPacket(packet)
} else if (outStore.destroy) {
outStore.destroy()
}
} | MqttClient constructor
@param {Stream} stream - stream
@param {Object} [options] - connection options
(see Connection#connect) | storeDeliver | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function deliver () {
var entry = queue.shift()
var packet = null
if (!entry) {
return
}
packet = entry.packet
that._sendPacket(
packet,
function (err) {
if (entry.cb) {
entry.cb(err)
}
deliver()
}
)
} | MqttClient constructor
@param {Stream} stream - stream
@param {Object} [options] - connection options
(see Connection#connect) | deliver | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function process () {
var packet = packets.shift()
var done = completeParse
if (packet) {
that._handlePacket(packet, process)
} else {
completeParse = null
done()
}
} | setup the event handlers in the inner stream.
@api private | process | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function closeStores () {
that.disconnected = true
that.incomingStore.close(function () {
that.outgoingStore.close(cb)
})
} | end - close connection
@returns {MqttClient} this - for chaining
@param {Boolean} force - do not wait for all in-flight messages to be acked
@param {Function} cb - called when the client has been closed
@api public | closeStores | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function finish () {
// defer closesStores of an I/O cycle,
// just to make sure things are
// ok for websockets
that._cleanUp(force, setImmediate.bind(null, closeStores))
} | end - close connection
@returns {MqttClient} this - for chaining
@param {Boolean} force - do not wait for all in-flight messages to be acked
@param {Function} cb - called when the client has been closed
@api public | finish | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function Store () {
if (!(this instanceof Store)) {
return new Store()
}
this._inflights = {}
} | In-memory implementation of the message store
This can actually be saved into files. | Store | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function validateTopic (topic) {
var parts = topic.split('/')
for (var i = 0; i < parts.length; i++) {
if (parts[i] === '+') {
continue
}
if (parts[i] === '#') {
// for Rule #2
return i === parts.length - 1
}
if (parts[i].indexOf('+') !== -1 || parts[i].indexOf('#') !== -1) {
return false
}
}
return true
} | Validate a topic to see if it's valid or not.
A topic is valid if it follow below rules:
- Rule #1: If any part of the topic is not `+` or `#`, then it must not contain `+` and '#'
- Rule #2: Part `#` must be located at the end of the mailbox
@param {String} topic - A topic
@returns {Boolean} If the topic is valid, returns true. Otherwise, returns false. | validateTopic | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function validateTopics (topics) {
if (topics.length === 0) {
return 'empty_topic_list'
}
for (var i = 0; i < topics.length; i++) {
if (!validateTopic(topics[i])) {
return topics[i]
}
}
return null
} | Validate an array of topics to see if any of them is valid or not
@param {Array} topics - Array of topics
@returns {String} If the topics is valid, returns null. Otherwise, returns the invalid one | validateTopics | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function deprecate (fn, msg) {
if (config('noDeprecation')) {
return fn;
}
var warned = false;
function deprecated() {
if (!warned) {
if (config('throwDeprecation')) {
throw new Error(msg);
} else if (config('traceDeprecation')) {
console.trace(msg);
} else {
console.warn(msg);
}
warned = true;
}
return fn.apply(this, arguments);
}
return deprecated;
} | Mark that a method should not be used.
Returns a modified function which warns once by default.
If `localStorage.noDeprecation = true` is set, then it is a no-op.
If `localStorage.throwDeprecation = true` is set, then deprecated functions
will throw an Error when invoked.
If `localStorage.traceDeprecation = true` is set, then deprecated functions
will invoke `console.trace()` instead of `console.error()`.
@param {Function} fn - the function to deprecate
@param {String} msg - the string to print to the console when `fn` is invoked
@returns {Function} a new "deprecated" version of `fn`
@api public | deprecate | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function deprecated() {
if (!warned) {
if (config('throwDeprecation')) {
throw new Error(msg);
} else if (config('traceDeprecation')) {
console.trace(msg);
} else {
console.warn(msg);
}
warned = true;
}
return fn.apply(this, arguments);
} | Mark that a method should not be used.
Returns a modified function which warns once by default.
If `localStorage.noDeprecation = true` is set, then it is a no-op.
If `localStorage.throwDeprecation = true` is set, then deprecated functions
will throw an Error when invoked.
If `localStorage.traceDeprecation = true` is set, then deprecated functions
will invoke `console.trace()` instead of `console.error()`.
@param {Function} fn - the function to deprecate
@param {String} msg - the string to print to the console when `fn` is invoked
@returns {Function} a new "deprecated" version of `fn`
@api public | deprecated | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function config (name) {
// accessing global.localStorage can trigger a DOMException in sandboxed iframes
try {
if (!global.localStorage) return false;
} catch (_) {
return false;
}
var val = global.localStorage[name];
if (null == val) return false;
return String(val).toLowerCase() === 'true';
} | Checks `localStorage` for boolean values for the given `name`.
@param {String} name
@returns {Boolean}
@api private | config | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function error(type) {
throw new RangeError(errors[type]);
} | A generic error utility function.
@private
@param {String} type The error type.
@returns {Error} Throws a `RangeError` with the applicable error message. | error | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function map(array, fn) {
var length = array.length;
var result = [];
while (length--) {
result[length] = fn(array[length]);
}
return result;
} | A generic `Array#map` utility function.
@private
@param {Array} array The array to iterate over.
@param {Function} callback The function that gets called for every array
item.
@returns {Array} A new array of values returned by the callback function. | map | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function mapDomain(string, fn) {
var parts = string.split('@');
var result = '';
if (parts.length > 1) {
// In email addresses, only the domain name should be punycoded. Leave
// the local part (i.e. everything up to `@`) intact.
result = parts[0] + '@';
string = parts[1];
}
// Avoid `split(regex)` for IE8 compatibility. See #17.
string = string.replace(regexSeparators, '\x2E');
var labels = string.split('.');
var encoded = map(labels, fn).join('.');
return result + encoded;
} | A simple `Array#map`-like wrapper to work with domain name strings or email
addresses.
@private
@param {String} domain The domain name or email address.
@param {Function} callback The function that gets called for every
character.
@returns {Array} A new string of characters returned by the callback
function. | mapDomain | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
function ucs2decode(string) {
var output = [],
counter = 0,
length = string.length,
value,
extra;
while (counter < length) {
value = string.charCodeAt(counter++);
if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
// high surrogate, and there is a next character
extra = string.charCodeAt(counter++);
if ((extra & 0xFC00) == 0xDC00) { // low surrogate
output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
} else {
// unmatched surrogate; only append this code unit, in case the next
// code unit is the high surrogate of a surrogate pair
output.push(value);
counter--;
}
} else {
output.push(value);
}
}
return output;
} | Creates an array containing the numeric code points of each Unicode
character in the string. While JavaScript uses UCS-2 internally,
this function will convert a pair of surrogate halves (each of which
UCS-2 exposes as separate characters) into a single code point,
matching UTF-16.
@see `punycode.ucs2.encode`
@see <https://mathiasbynens.be/notes/javascript-encoding>
@memberOf punycode.ucs2
@name decode
@param {String} string The Unicode input string (UCS-2).
@returns {Array} The new array of code points. | ucs2decode | javascript | node-pinus/pinus | tools/pinus-admin-web/public/js/util/browserMqtt.js | https://github.com/node-pinus/pinus/blob/master/tools/pinus-admin-web/public/js/util/browserMqtt.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.