From 506e79788f825cc28f54c11466ae3ec7828de830 Mon Sep 17 00:00:00 2001 From: dencap Date: Thu, 12 Nov 2015 15:30:55 +0100 Subject: [PATCH 1/8] Added definition for bytebuffer.js (with long.js) --- bytebuffer/bytebuffer.d.ts | 612 +++++++++++++++++++++++++++++++++++++ bytebuffer/long.d.ts | 349 +++++++++++++++++++++ 2 files changed, 961 insertions(+) create mode 100644 bytebuffer/bytebuffer.d.ts create mode 100644 bytebuffer/long.d.ts diff --git a/bytebuffer/bytebuffer.d.ts b/bytebuffer/bytebuffer.d.ts new file mode 100644 index 000000000..6123ed50b --- /dev/null +++ b/bytebuffer/bytebuffer.d.ts @@ -0,0 +1,612 @@ +// Type definitions for ByteBuffer.js 5.0.0 +// Project: https://github.com/dcodeIO/bytebuffer.js + +/// + +declare class ByteBuffer +{ + /** + * Constructs a new ByteBuffer. + */ + constructor( capacity?: number, littleEndian?: boolean, noAssert?: boolean ); + + /** + * Big endian constant that can be used instead of its boolean value. Evaluates to false. + */ + static BIG_ENDIAN: boolean; + + /** + * Default initial capacity of 16. + */ + static DEFAULT_CAPACITY: number; + + /** + * Default no assertions flag of false. + */ + static DEFAULT_NOASSERT + + /** + * Little endian constant that can be used instead of its boolean value. Evaluates to true. + */ + static LITTLE_ENDIAN: boolean; + + /** + * Maximum number of bytes required to store a 32bit base 128 variable-length integer. + */ + static MAX_VARINT32_BYTES: number; + + /** + * Maximum number of bytes required to store a 64bit base 128 variable-length integer. + */ + static MAX_VARINT64_BYTES: number; + + /** + * Metrics representing number of bytes.Evaluates to 2. + */ + static METRICS_BYTES: number; + + /** + * Metrics representing number of UTF8 characters.Evaluates to 1. + */ + static METRICS_CHARS + + /** + * ByteBuffer version. + */ + static VERSION: string; + + /** + * Backing buffer. + */ + buffer: ArrayBuffer; + + /** + * Absolute limit of the contained data. Set to the backing buffer's capacity upon allocation. + */ + limit: number; + + /** + * Whether to use little endian byte order, defaults to false for big endian. + */ + littleEndian: boolean; + + /** + * Marked offset. + */ + markedOffset: number; + + /** + * Whether to skip assertions of offsets and values, defaults to false. + */ + noAssert: boolean; + + /** + * Absolute read/write offset. + */ + offset: number; + + /** + * Data view to manipulate the backing buffer. Becomes null if the backing buffer has a capacity of 0. + */ + view: DataView; + + /** + * Allocates a new ByteBuffer backed by a buffer of the specified capacity. + */ + static allocate( capacity?: number, littleEndian?: number, noAssert?: boolean ): ByteBuffer; + + /** + * Decodes a base64 encoded string to binary like window.atob does. + */ + static atob( b64: string ): string; + + /** + * Encodes a binary string to base64 like window.btoa does. + */ + static btoa( str: string ): string; + + /** + * Calculates the number of UTF8 bytes of a string. + */ + static calculateUTF8Byte( str: string ): number; + + /** + * Calculates the number of UTF8 characters of a string.JavaScript itself uses UTF- 16, so that a string's length property does not reflect its actual UTF8 size if it contains code points larger than 0xFFFF. + */ + static calculateUTF8Char( str: string ): number; + + /** + * Calculates the actual number of bytes required to store a 32bit base 128 variable-length integer. + */ + static calculateVariant32( value: number ): number; + + /** + * Calculates the actual number of bytes required to store a 64bit base 128 variable-length integer. + */ + static calculateVariant64( value: number | Long ): number; + + /** + * Concatenates multiple ByteBuffers into one. + */ + static concat( buffers: Array | ArrayBuffer | Uint8Array | string, encoding?: string | boolean, litteEndian?: boolean, noAssert?: boolean ): ByteBuffer; + + /** + * Decodes a base64 encoded string to a ByteBuffer. + */ + static fromBase64( str: string, littleEndian?: boolean, noAssert?: boolean ): ByteBuffer; + + /** + * Decodes a binary encoded string, that is using only characters 0x00-0xFF as bytes, to a ByteBuffer. + */ + static fromBinary( str: string, littleEndian?: boolean, noAssert?: boolean ): ByteBuffer; + + /** + * Decodes a hex encoded string with marked offsets to a ByteBuffer. + */ + static fromDebug( str: string, littleEndian?: boolean, noAssert?: boolean ): ByteBuffer; + + /** + * Decodes a hex encoded string to a ByteBuffer. + */ + static fromHex( str: string, littleEndian?: boolean, noAssert?: boolean ): ByteBuffer; + + /** + * Decodes an UTF8 encoded string to a ByteBuffer. + */ + static fromUTF8( str: string, littleEndian?: boolean, noAssert?: boolean ): ByteBuffer; + + /** + * Gets the backing buffer type. + */ + static isByteBuffer( bb: any ): boolean; + + /** + * Wraps a buffer or a string. Sets the allocated ByteBuffer's ByteBuffer#offset to 0 and its ByteBuffer#limit to the length of the wrapped data. + * @param buffer Anything that can be wrapped + * @param encoding String encoding if buffer is a string ("base64", "hex", "binary", defaults to "utf8") + * @param littleEndian Whether to use little or big endian byte order. Defaults to ByteBuffer.DEFAULT_ENDIAN. + * @param noAssert Whether to skip assertions of offsets and values. Defaults to ByteBuffer.DEFAULT_NOASSERT. + */ + static wrap( buffer: ByteBuffer | ArrayBuffer | Uint8Array | string, enc?: string | boolean, littleEndian?: boolean, noAssert?: boolean ): ByteBuffer; + + /** + * Decodes a zigzag encoded signed 32bit integer. + */ + static zigZagDecode32( n: number ): number; + + /** + * Decodes a zigzag encoded signed 64bit integer. + */ + static zigZagDecode64( n: number | Long ): Long; + + /** + * Zigzag encodes a signed 32bit integer so that it can be effectively used with varint encoding. + */ + static zigZagEncode32( n: number ): number; + + /** + * Zigzag encodes a signed 64bit integer so that it can be effectively used with varint encoding. + */ + static zigZagEncode64( n: number | Long ): Long; + + /** + * Switches (to) big endian byte order. + */ + BE( bigEndian?: boolean ): ByteBuffer; + + /** + * Switches (to) little endian byte order. + */ + LE( bigEndian?: boolean ): ByteBuffer; + + /** + * Appends some data to this ByteBuffer. This will overwrite any contents behind the specified offset up to the appended data's length. + */ + append( source: ByteBuffer | ArrayBuffer | Uint8Array | string, encoding?: string | number, offset?: number ): ByteBuffer; + + /** + * Appends this ByteBuffer's contents to another ByteBuffer. This will overwrite any contents behind the specified offset up to the length of this ByteBuffer's data. + */ + appendTo( target: ByteBuffer, offset?: number ): ByteBuffer; + + /** + * Enables or disables assertions of argument types and offsets. Assertions are enabled by default but you can opt to disable them if your code already makes sure that everything is valid. + */ + assert( assert: boolean ): ByteBuffer; + + /** + * Gets the capacity of this ByteBuffer's backing buffer. + */ + capacity(): number; + + /** + * Clears this ByteBuffer's offsets by setting ByteBuffer#offset to 0 and + * ByteBuffer#limit to the backing buffer's capacity. Discards ByteBuffer#markedOffset. + */ + clear(): ByteBuffer; + + /** + * Creates a cloned instance of this ByteBuffer, preset with this ByteBuffer's values for ByteBuffer#offset, ByteBuffer#markedOffset and ByteBuffer#limit. + */ + clone( copy?: boolean ): ByteBuffer; + + /** + * Compacts this ByteBuffer to be backed by a ByteBuffer#buffer of its contents' length. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. Will set offset = 0 and limit = capacity and adapt ByteBuffer#markedOffset to the same relative position if set. + */ + compact( begin?: number, end?: number ): ByteBuffer; + + /** + * Creates a copy of this ByteBuffer's contents. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. + */ + copy( begin?: number, end?: number ): ByteBuffer; + + /** + * Copies this ByteBuffer's contents to another ByteBuffer. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. + */ + copyTo( target: ByteBuffer, targetOffset?: number, sourceOffset?: number, sourceLimit?: number ): ByteBuffer; + + /** + * Makes sure that this ByteBuffer is backed by a ByteBuffer#buffer of at least the specified capacity. If the current capacity is exceeded, it will be doubled. If double the current capacity is less than the required capacity, the required capacity will be used instead. + */ + ensureCapacity( capacity: number ): ByteBuffer; + + /** + * Overwrites this ByteBuffer's contents with the specified value. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. + */ + fill( value: number | string, begin?: number, end?: number ): ByteBuffer; + + /** + * Makes this ByteBuffer ready for a new sequence of write or relative read operations. Sets limit = offset and offset = 0. Make sure always to flip a ByteBuffer when all relative read or write operations are complete. + */ + flip(): ByteBuffer; + + /** + * Marks an offset on this ByteBuffer to be used later. + */ + mark( offset?: number ): ByteBuffer; + + /** + * Sets the byte order. + */ + order( littleEndian: boolean ): ByteBuffer; + + /** + * Prepends some data to this ByteBuffer. This will overwrite any contents before the specified offset up to the prepended data's length. If there is not enough space available before the specified offset, the backing buffer will be resized and its contents moved accordingly. + */ + prepend( source: ByteBuffer | string | ArrayBuffer, encoding?: string | number, offset?: number ): ByteBuffer; + + /** + * Prepends this ByteBuffer to another ByteBuffer. This will overwrite any contents before the specified offset up to the prepended data's length. If there is not enough space available before the specified offset, the backing buffer will be resized and its contents moved accordingly. + */ + prependTo( target: ByteBuffer, offset?: number ): ByteBuffer; + + /** + * Prints debug information about this ByteBuffer's contents. + */ + printDebug( out?: ( string ) => void ): void; + + /** + * Reads an 8bit signed integer. This is an alias of ByteBuffer#readInt8. + */ + readByte( offset?: number ): number; + + /** + * Reads a NULL-terminated UTF8 encoded string. For this to work the string read must not contain any NULL characters itself. + */ + readCString( offset?: number ): string; + + /** + * Reads a 64bit float. This is an alias of ByteBuffer#readFloat64. + */ + readDouble( offset?: number ): number; + + /** + * Reads a 32bit float. This is an alias of ByteBuffer#readFloat32. + */ + readFloat( offset?: number ): number; + + /** + * Reads a 32bit float. + */ + readFloat32( offset?: number ): number; + + /** + * Reads a 64bit float. + */ + readFloat64( offset?: number ): number; + + /** + * Reads a length as uint32 prefixed UTF8 encoded string. + */ + readIString( offset?: number ): string; + + /** + * Reads a 32bit signed integer.This is an alias of ByteBuffer#readInt32. + */ + readInt( offset?: number ): number; + + /** + * Reads a 16bit signed integer. + */ + readInt16( offset?: number ): number; + + /** + * Reads a 32bit signed integer. + */ + readInt32( offset?: number ): number; + + /** + * Reads a 64bit signed integer. + */ + readInt64( offset?: number ): Long; + + /** + * Reads an 8bit signed integer. + */ + readInt8( offset?: number ): number; + + /** + * Reads a 64bit signed integer. This is an alias of ByteBuffer#readInt64. + */ + readLong( offset?: number ): Long; + + /** + * Reads a 16bit signed integer. This is an alias of ByteBuffer#readInt16. + */ + readShort( offset?: number ): number; + + /** + * Reads an UTF8 encoded string. This is an alias of ByteBuffer#readUTF8String. + */ + readString( length: number, metrics?: number, offset?: number ): string; + + /** + * Reads an UTF8 encoded string. + */ + readUTF8String( chars: number, offset?: number ): string; + + /** + * Reads a 16bit unsigned integer. + */ + readUint16( offset?: number ): number; + + /** + * Reads a 32bit unsigned integer. + */ + readUint32( offset?: number ): number; + + /** + * Reads a 64bit unsigned integer. + */ + readUint64( offset?: number ): Long; + /** + * Reads an 8bit unsigned integer. + */ + readUint8( offset?: number ): number; + + /** + * Reads a length as varint32 prefixed UTF8 encoded string. + */ + readVString( offset?: number ): string; + + /** + * Reads a 32bit base 128 variable-length integer. + */ + readVarint32( offset?: number ): number; + + /** + * Reads a zig-zag encoded 32bit base 128 variable-length integer. + */ + readVarint32ZiZag( offset?: number ): number; + + /** + * Reads a 64bit base 128 variable-length integer. Requires Long.js. + */ + readVarint64( offset?: number ): Long; + + /** + * Reads a zig-zag encoded 64bit base 128 variable-length integer. Requires Long.js. + */ + readVarint64ZigZag( offset?: number ): Long; + + /** + * Gets the number of remaining readable bytes. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit, so this returns limit - offset. + */ + remaining(): number; + + /** + * Resets this ByteBuffer's ByteBuffer#offset. If an offset has been marked through ByteBuffer#mark before, offset will be set to ByteBuffer#markedOffset, which will then be discarded. If no offset has been marked, sets offset = 0. + */ + reset(): ByteBuffer; + + /** + * Resizes this ByteBuffer to be backed by a buffer of at least the given capacity. Will do nothing if already that large or larger. + */ + resize( capacity: number ): ByteBuffer; + + /** + * Reverses this ByteBuffer's contents + */ + reverse( begin?: number, end?: number ): ByteBuffer; + + /** + * Skips the next length bytes. This will just advance + */ + skip( length: number ): ByteBuffer; + + /** + * Slices this ByteBuffer by creating a cloned instance with offset = begin and limit = end. + */ + slice( begin?: number, end?: number ): ByteBuffer; + + /** + * Returns a raw buffer compacted to contain this ByteBuffer's contents. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. Will transparently ByteBuffer#flip this ByteBuffer if offset > limit but the actual offsets remain untouched. This is an alias of ByteBuffer#toBuffer. + */ + toArrayBuffer( forceCopy?: boolean ): ArrayBuffer; + + /** + * Encodes this ByteBuffer's contents to a base64 encoded string. + */ + toBase64( begin?: number, end?: number ): string; + + /** + * Encodes this ByteBuffer to a binary encoded string, that is using only characters 0x00-0xFF as bytes. + */ + toBinary( begin?: number, end?: number ): string; + + /** + * Returns a copy of the backing buffer that contains this ByteBuffer's contents. Contents are the bytes between ByteBuffer#offset and ByteBuffer#limit. Will transparently ByteBuffer#flip this ByteBuffer if offset > limit but the actual offsets remain untouched. + */ + toBuffer( forceCopy?: boolean ): ArrayBuffer; + + /** + *Encodes this ByteBuffer to a hex encoded string with marked offsets. Offset symbols are: + * < : offset, + * ' : markedOffset, + * > : limit, + * | : offset and limit, + * [ : offset and markedOffset, + * ] : markedOffset and limit, + * ! : offset, markedOffset and limit + */ + toDebug( columns?: boolean ): string | Array + + /** + * Encodes this ByteBuffer's contents to a hex encoded string. + */ + toHex( begin?: number, end?: number ): string; + + /** + * Converts the ByteBuffer's contents to a string. + */ + toString( encoding?: string ): string; + + /** + * Encodes this ByteBuffer's contents between ByteBuffer#offset and ByteBuffer#limit to an UTF8 encoded string. + */ + toUTF8(): string; + + /** + * Writes an 8bit signed integer. This is an alias of ByteBuffer#writeInt8. + */ + writeByte( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a NULL-terminated UTF8 encoded string. For this to work the specified string must not contain any NULL characters itself. + */ + writeCString( str: string, offset?: number ): ByteBuffer; + + /** + * Writes a 64bit float. This is an alias of ByteBuffer#writeFloat64. + */ + writeDouble( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 32bit float. This is an alias of ByteBuffer#writeFloat32. + */ + writeFloat( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 32bit float. + */ + writeFloat32( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 64bit float. + */ + writeFloat64( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a length as uint32 prefixed UTF8 encoded string. + */ + writeIString( str: string, offset?: number ): ByteBuffer; + + /** + * Writes a 32bit signed integer. This is an alias of ByteBuffer#writeInt32. + */ + writeInt( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 16bit signed integer. + */ + writeInt16( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 32bit signed integer. + */ + writeInt32( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 64bit signed integer. + */ + writeInt64( value: number | Long, offset?: number ): ByteBuffer; + + /** + * Writes an 8bit signed integer. + */ + writeInt8( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 16bit signed integer. This is an alias of ByteBuffer#writeInt16. + */ + writeShort( value: number, offset?: number ): ByteBuffer; + + /** + * Writes an UTF8 encoded string.This is an alias of ByteBuffer#writeUTF8String. + */ + WriteString( str: string, offset?: number ): ByteBuffer | number; + + /** + * Writes an UTF8 encoded string. + */ + writeUTF8String( str: string, offset?: number ): ByteBuffer | number; + + /** + * Writes a 16bit unsigned integer. + */ + writeUint16( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 32bit unsigned integer. + */ + writeUint32( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a 64bit unsigned integer. + */ + writeUint64( value: number | Long, offset?: number ): ByteBuffer; + + /** + * Writes an 8bit unsigned integer. + */ + writeUint8( value: number, offset?: number ): ByteBuffer; + + /** + * Writes a length as varint32 prefixed UTF8 encoded string. + */ + writeVString( str: string, offset?: number ): ByteBuffer | number; + + /** + * Writes a 32bit base 128 variable-length integer. + */ + writeVarint32( value: number, offset?: number ): ByteBuffer | number; + + /** + * Writes a zig-zag encoded 32bit base 128 variable-length integer. + */ + writeVarint32ZigZag( value: number, offset?: number ): ByteBuffer | number; + + /** + * Writes a 64bit base 128 variable-length integer. + */ + writeVarint64( value: number | Long, offset?: number ): ByteBuffer; + + /** + * Writes a zig-zag encoded 64bit base 128 variable-length integer. + */ + writeVarint64ZigZag( value: number | Long, offset?: number ): ByteBuffer | number; +} + +declare module 'bytebuffer' { + export = ByteBuffer; +} diff --git a/bytebuffer/long.d.ts b/bytebuffer/long.d.ts new file mode 100644 index 000000000..f5825ffe7 --- /dev/null +++ b/bytebuffer/long.d.ts @@ -0,0 +1,349 @@ +// Type definitions for ByteBuffer.js 5.0.0 +// Project: https://github.com/dcodeIO/bytebuffer.js + +declare class Long +{ + /** + * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers. See the from* functions below for more convenient ways of constructing Longs. + */ + constructor( low: number, high?: number, unsigned?: number ); + + /** + * Maximum unsigned value. + */ + static MAX_UNSIGNED_VALUE: Long; + + /** + * Maximum signed value. + */ + static MAX_VALUE: Long; + + /** + * Minimum signed value. + */ + static MIN_VALUE: Long; + + /** + * Signed negative one. + */ + static NEG_ONE: Long; + + /** + * Signed one. + */ + static ONE: Long; + + /** + * Unsigned one. + */ + static UONE: Long; + + /** + * Unsigned zero. + */ + static UZERO: Long; + + /** + * Signed zero + */ + static ZERO: Long; + + /** + * The high 32 bits as a signed value. + */ + high: number; + + /** + * The low 32 bits as a signed value. + */ + low: number; + + /** + * Whether unsigned or not. + */ + unsigned: number; + + /** + * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits. + */ + static fromBits( lowBits:number, highBits:number, unsigned?:boolean ): Long; + + /** + * Returns a Long representing the given 32 bit integer value. + */ + static fromInt( value: number, unsigned?: boolean ): Long; + + /** + * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. + */ + static fromNumber( value: number, unsigned?: boolean ): Long; + + /** + * Returns a Long representation of the given string, written using the specified radix. + */ + static fromString( str: string, unsigned?: boolean | number, radix?: number ): Long; + + /** + * Tests if the specified object is a Long. + */ + static isLong( obj: any ): boolean; + + /** + * Converts the specified value to a Long. + */ + static fromValue( val: Long | number | string | {low: number, high: number, unsigned: boolean} ): Long; + + /** + * Returns the sum of this and the specified Long. + */ + add( addend: number | Long | string ): Long; + + /** + * Returns the bitwise AND of this Long and the specified. + */ + and( other: Long | number | string ): Long; + + /** + * Compares this Long's value with the specified's. + */ + compare( other: Long | number | string ): number; + + /** + * Compares this Long's value with the specified's. + */ + comp( other: Long | number | string ): number; + + /** + * Returns this Long divided by the specified. + */ + divide( divisor: Long | number | string ): Long; + + /** + * Returns this Long divided by the specified. + */ + div( divisor: Long | number | string ): Long; + + /** + * Tests if this Long's value equals the specified's. + */ + equals( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value equals the specified's. + */ + eq( other: Long | number | string ): boolean; + + /** + * Gets the high 32 bits as a signed integer. + */ + getHighBits(): number; + + /** + * Gets the high 32 bits as an unsigned integer. + */ + getHighBitsUnsigned(): number; + + /** + * Gets the low 32 bits as a signed integer. + */ + getLowBits(): number; + + /** + * Gets the low 32 bits as an unsigned integer. + */ + getLowBitsUnsigned(): number; + + /** + * Gets the number of bits needed to represent the absolute value of this Long. + */ + getNumBitsAbs(): number; + + /** + * Tests if this Long's value is greater than the specified's. + */ + greaterThan( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is greater than the specified's. + */ + gt( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is greater than or equal the specified's. + */ + greaterThanOrEqual( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is greater than or equal the specified's. + */ + gte( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is even. + */ + isEven(): boolean; + + /** + * Tests if this Long's value is negative. + */ + isNegative(): boolean; + + /** + * Tests if this Long's value is odd. + */ + isOdd(): boolean; + + /** + * Tests if this Long's value is positive. + */ + isPositive(): boolean; + + /** + * Tests if this Long's value equals zero. + */ + isZero(): boolean; + + /** + * Tests if this Long's value is less than the specified's. + */ + lessThan( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is less than the specified's. + */ + lt( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is less than or equal the specified's. + */ + lessThanOrEqual( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is less than or equal the specified's. + */ + lte( other: Long | number | string ): boolean; + + /** + * Returns this Long modulo the specified. + */ + modulo( other: Long | number | string ): Long; + + /** + * Returns this Long modulo the specified. + */ + mod( other: Long | number | string ): Long; + + /** + * Returns the product of this and the specified Long. + */ + multiply( multiplier: Long | number | string ): Long; + + /** + * Returns the product of this and the specified Long. + */ + mul( multiplier: Long | number | string ): Long; + + /** + * Negates this Long's value. + */ + negate(): Long; + + /** + * Negates this Long's value. + */ + neg(): Long; + + /** + * Returns the bitwise NOT of this Long. + */ + not(): Long; + + /** + * Tests if this Long's value differs from the specified's. + */ + notEquals( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value differs from the specified's. + */ + neq( other: Long | number | string ): boolean; + + /** + * Returns the bitwise OR of this Long and the specified. + */ + or( other: Long | number | string ): Long; + + /** + * Returns this Long with bits shifted to the left by the given amount. + */ + shiftLeft( numBits: number | Long ): Long; + + /** + * Returns this Long with bits shifted to the left by the given amount. + */ + shl( numBits: number | Long ): Long; + + /** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + */ + shiftRight( numBits: number | Long ): Long; + + /** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + */ + shr( numBits: number | Long ): Long; + + /** + * Returns this Long with bits logically shifted to the right by the given amount. + */ + shiftRightUnsigned( numBits: number | Long ): Long; + + /** + * Returns this Long with bits logically shifted to the right by the given amount. + */ + shru( numBits: number | Long ): Long; + + /** + * Returns the difference of this and the specified Long. + */ + subtract( subtrahend: number | Long ): Long; + + /** + * Returns the difference of this and the specified Long. + */ + sub( subtrahend: number | Long ): Long; + + /** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + */ + toInt(): number; + + /** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + */ + toNumber(): number; + + /** + * Converts this Long to signed. + */ + toSigned(): Long; + + /** + * Converts the Long to a string written in the specified radix. + */ + toString( radix?: number ): string; + + /** + * Converts this Long to unsigned. + */ + toUnsigned(): Long; + + /** + * Returns the bitwise XOR of this Long and the given one. + */ + xor( other: Long | number | string ): Long; +} + +declare module 'long' { + export = Long; +} From d6ff5f59462d27165cde268db5e400e18b02b1ce Mon Sep 17 00:00:00 2001 From: dencap Date: Thu, 12 Nov 2015 15:37:37 +0100 Subject: [PATCH 2/8] Fixed comments in header --- bytebuffer/bytebuffer.d.ts | 3 +++ bytebuffer/long.d.ts | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bytebuffer/bytebuffer.d.ts b/bytebuffer/bytebuffer.d.ts index 6123ed50b..71782bcb1 100644 --- a/bytebuffer/bytebuffer.d.ts +++ b/bytebuffer/bytebuffer.d.ts @@ -1,5 +1,8 @@ // Type definitions for ByteBuffer.js 5.0.0 // Project: https://github.com/dcodeIO/bytebuffer.js +// Definitions by: SINTEF-9012 +// Definitions by: Denis Cappellin +// Definitions: https://github.com/borisyankov/DefinitelyTyped /// diff --git a/bytebuffer/long.d.ts b/bytebuffer/long.d.ts index f5825ffe7..1d2e9f388 100644 --- a/bytebuffer/long.d.ts +++ b/bytebuffer/long.d.ts @@ -1,5 +1,7 @@ -// Type definitions for ByteBuffer.js 5.0.0 -// Project: https://github.com/dcodeIO/bytebuffer.js +// Type definitions for long.js 3.0.2 +// Project: https://github.com/dcodeIO/long.js +// Definitions by: Denis Cappellin +// Definitions: https://github.com/borisyankov/DefinitelyTyped declare class Long { From b9536c14d6030b3b99261b35fc3602e54dd838e6 Mon Sep 17 00:00:00 2001 From: dencap Date: Thu, 12 Nov 2015 17:02:21 +0100 Subject: [PATCH 3/8] Fixed problems suggested by Travis --- bytebuffer/bytebuffer-tests.ts | 8 ++++++++ bytebuffer/bytebuffer.d.ts | 12 ++++++------ bytebuffer/long-tests.ts | 6 ++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 bytebuffer/bytebuffer-tests.ts create mode 100644 bytebuffer/long-tests.ts diff --git a/bytebuffer/bytebuffer-tests.ts b/bytebuffer/bytebuffer-tests.ts new file mode 100644 index 000000000..34db7368d --- /dev/null +++ b/bytebuffer/bytebuffer-tests.ts @@ -0,0 +1,8 @@ +/// + +import ByteBuffer = require("bytebuffer"); + +var bb = new ByteBuffer() + .writeIString("Hello world!") + .flip(); +console.log(bb.readIString()+" from bytebuffer.js"); \ No newline at end of file diff --git a/bytebuffer/bytebuffer.d.ts b/bytebuffer/bytebuffer.d.ts index 71782bcb1..bf1251e5f 100644 --- a/bytebuffer/bytebuffer.d.ts +++ b/bytebuffer/bytebuffer.d.ts @@ -1,10 +1,10 @@ -// Type definitions for ByteBuffer.js 5.0.0 +// Type definitions for bytebuffer.js 5.0.0 // Project: https://github.com/dcodeIO/bytebuffer.js -// Definitions by: SINTEF-9012 // Definitions by: Denis Cappellin // Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions by: SINTEF-9012 -/// +/// declare class ByteBuffer { @@ -26,7 +26,7 @@ declare class ByteBuffer /** * Default no assertions flag of false. */ - static DEFAULT_NOASSERT + static DEFAULT_NOASSERT: boolean; /** * Little endian constant that can be used instead of its boolean value. Evaluates to true. @@ -51,7 +51,7 @@ declare class ByteBuffer /** * Metrics representing number of UTF8 characters.Evaluates to 1. */ - static METRICS_CHARS + static METRICS_CHARS: number; /** * ByteBuffer version. @@ -286,7 +286,7 @@ declare class ByteBuffer /** * Prints debug information about this ByteBuffer's contents. */ - printDebug( out?: ( string ) => void ): void; + printDebug( out?: ( text: string ) => void ): void; /** * Reads an 8bit signed integer. This is an alias of ByteBuffer#readInt8. diff --git a/bytebuffer/long-tests.ts b/bytebuffer/long-tests.ts new file mode 100644 index 000000000..35dd6d784 --- /dev/null +++ b/bytebuffer/long-tests.ts @@ -0,0 +1,6 @@ +/// + +import Long = require("long"); + +var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); +console.log(longVal.toString()); \ No newline at end of file From ec2915345b5e5bd7817c09b6094810d3f26ffc6c Mon Sep 17 00:00:00 2001 From: dencap Date: Mon, 16 Nov 2015 15:15:58 +0100 Subject: [PATCH 4/8] Removed long.js files from folder bytebuffer, fixed some function signatures and updated the version of long available in folder long --- bytebuffer/bytebuffer.d.ts | 2 +- long/long-tests.ts | 2 +- long/long.d.ts | 405 +++++++++++++++++++++++++++++++------ 3 files changed, 343 insertions(+), 66 deletions(-) diff --git a/bytebuffer/bytebuffer.d.ts b/bytebuffer/bytebuffer.d.ts index bf1251e5f..0bfaed7c1 100644 --- a/bytebuffer/bytebuffer.d.ts +++ b/bytebuffer/bytebuffer.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped // Definitions by: SINTEF-9012 -/// +/// declare class ByteBuffer { diff --git a/long/long-tests.ts b/long/long-tests.ts index f70835f66..928cc9453 100644 --- a/long/long-tests.ts +++ b/long/long-tests.ts @@ -2,7 +2,7 @@ import Long = require("long"); -var val: dcodeIO.Long; +var val: Long; var n: number = 42; var b: boolean = true; var s: string = "1337"; diff --git a/long/long.d.ts b/long/long.d.ts index 32d773b9d..f059ff565 100644 --- a/long/long.d.ts +++ b/long/long.d.ts @@ -1,75 +1,352 @@ -// Type definitions for Long.js v2.2.5 -// Project: https://github.com/dcodeIO/Long.js -// Definitions by: Peter Kooijmans +// Type definitions for long.js 3.0.2 +// Project: https://github.com/dcodeIO/long.js +// Definitions by: Denis Cappellin // Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions by: Peter Kooijmans -declare module dcodeIO { - interface LongStatic { - new (low: number, high?: number, unsigned?: boolean): Long; +declare class Long +{ + /** + * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers. See the from* functions below for more convenient ways of constructing Longs. + */ + constructor( low: number, high?: number, unsigned?: boolean ); - MAX_UNSIGNED_VALUE: Long; - MAX_VALUE: Long; - MIN_VALUE: Long; - NEG_ONE: Long; - ONE: Long; - UONE: Long; - UZERO: Long; - ZERO: Long; + /** + * Maximum unsigned value. + */ + static MAX_UNSIGNED_VALUE: Long; - fromBits(lowBits: number, highBits: number, unsigned?: boolean): Long; - fromInt(value: number, unsigned?: boolean): Long; - fromNumber(value: number, unsigned?: boolean): Long; - fromString(str: string, unsigned?: boolean | number, radix?: number): Long; - fromValue(val: Long | number | string): Long; - isLong(obj: any): boolean; - } + /** + * Maximum signed value. + */ + static MAX_VALUE: Long; - interface Long { - high: number; - low: number; - unsigned: boolean; + /** + * Minimum signed value. + */ + static MIN_VALUE: Long; - add(other: Long | number | string): Long; - and(other: Long | number | string): Long; - compare(other: Long | number | string): number; - div(divisor: Long | number | string): Long; - equals(other: Long | number | string): boolean; - getHighBits(): number; - getHighBitsUnsigned(): number; - getLowBits(): number; - getLowBitsUnsigned(): number; - getNumBitsAbs(): number; - greaterThan(other: Long | number | string): boolean; - greaterThanOrEqual(other: Long | number | string): boolean; - isEven(): boolean; - isNegative(): boolean; - isOdd(): boolean; - isPositive(): boolean; - isZero(): boolean; - lessThan(other: Long | number | string): boolean; - lessThanOrEqual(other: Long | number | string): boolean; - modulo(divisor: Long | number | string): Long; - multiply(multiplier: Long | number | string): Long; - negate(): Long; - not(): Long; - notEquals(other: Long | number | string): boolean; - or(other: Long | number | string): Long; - shiftLeft(numBits: number | Long): Long; - shiftRight(numBits: number | Long): Long; - shiftRightUnsigned(numBits: number | Long): Long; - subtract(other: Long | number | string): Long; - toInt(): number; - toNumber(): number; - toSigned(): Long; - toString(radix?: number): string; - toUnsigned(): Long; - xor(other: Long | number | string): Long; - } + /** + * Signed negative one. + */ + static NEG_ONE: Long; - export var Long: LongStatic; + /** + * Signed one. + */ + static ONE: Long; + + /** + * Unsigned one. + */ + static UONE: Long; + + /** + * Unsigned zero. + */ + static UZERO: Long; + + /** + * Signed zero + */ + static ZERO: Long; + + /** + * The high 32 bits as a signed value. + */ + high: number; + + /** + * The low 32 bits as a signed value. + */ + low: number; + + /** + * Whether unsigned or not. + */ + unsigned: boolean; + + /** + * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits. + */ + static fromBits( lowBits:number, highBits:number, unsigned?:boolean ): Long; + + /** + * Returns a Long representing the given 32 bit integer value. + */ + static fromInt( value: number, unsigned?: boolean ): Long; + + /** + * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. + */ + static fromNumber( value: number, unsigned?: boolean ): Long; + + /** + * Returns a Long representation of the given string, written using the specified radix. + */ + static fromString( str: string, unsigned?: boolean | number, radix?: number ): Long; + + /** + * Tests if the specified object is a Long. + */ + static isLong( obj: any ): boolean; + + /** + * Converts the specified value to a Long. + */ + static fromValue( val: Long | number | string | {low: number, high: number, unsigned: boolean} ): Long; + + /** + * Returns the sum of this and the specified Long. + */ + add( addend: number | Long | string ): Long; + + /** + * Returns the bitwise AND of this Long and the specified. + */ + and( other: Long | number | string ): Long; + + /** + * Compares this Long's value with the specified's. + */ + compare( other: Long | number | string ): number; + + /** + * Compares this Long's value with the specified's. + */ + comp( other: Long | number | string ): number; + + /** + * Returns this Long divided by the specified. + */ + divide( divisor: Long | number | string ): Long; + + /** + * Returns this Long divided by the specified. + */ + div( divisor: Long | number | string ): Long; + + /** + * Tests if this Long's value equals the specified's. + */ + equals( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value equals the specified's. + */ + eq( other: Long | number | string ): boolean; + + /** + * Gets the high 32 bits as a signed integer. + */ + getHighBits(): number; + + /** + * Gets the high 32 bits as an unsigned integer. + */ + getHighBitsUnsigned(): number; + + /** + * Gets the low 32 bits as a signed integer. + */ + getLowBits(): number; + + /** + * Gets the low 32 bits as an unsigned integer. + */ + getLowBitsUnsigned(): number; + + /** + * Gets the number of bits needed to represent the absolute value of this Long. + */ + getNumBitsAbs(): number; + + /** + * Tests if this Long's value is greater than the specified's. + */ + greaterThan( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is greater than the specified's. + */ + gt( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is greater than or equal the specified's. + */ + greaterThanOrEqual( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is greater than or equal the specified's. + */ + gte( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is even. + */ + isEven(): boolean; + + /** + * Tests if this Long's value is negative. + */ + isNegative(): boolean; + + /** + * Tests if this Long's value is odd. + */ + isOdd(): boolean; + + /** + * Tests if this Long's value is positive. + */ + isPositive(): boolean; + + /** + * Tests if this Long's value equals zero. + */ + isZero(): boolean; + + /** + * Tests if this Long's value is less than the specified's. + */ + lessThan( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is less than the specified's. + */ + lt( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is less than or equal the specified's. + */ + lessThanOrEqual( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value is less than or equal the specified's. + */ + lte( other: Long | number | string ): boolean; + + /** + * Returns this Long modulo the specified. + */ + modulo( other: Long | number | string ): Long; + + /** + * Returns this Long modulo the specified. + */ + mod( other: Long | number | string ): Long; + + /** + * Returns the product of this and the specified Long. + */ + multiply( multiplier: Long | number | string ): Long; + + /** + * Returns the product of this and the specified Long. + */ + mul( multiplier: Long | number | string ): Long; + + /** + * Negates this Long's value. + */ + negate(): Long; + + /** + * Negates this Long's value. + */ + neg(): Long; + + /** + * Returns the bitwise NOT of this Long. + */ + not(): Long; + + /** + * Tests if this Long's value differs from the specified's. + */ + notEquals( other: Long | number | string ): boolean; + + /** + * Tests if this Long's value differs from the specified's. + */ + neq( other: Long | number | string ): boolean; + + /** + * Returns the bitwise OR of this Long and the specified. + */ + or( other: Long | number | string ): Long; + + /** + * Returns this Long with bits shifted to the left by the given amount. + */ + shiftLeft( numBits: number | Long ): Long; + + /** + * Returns this Long with bits shifted to the left by the given amount. + */ + shl( numBits: number | Long ): Long; + + /** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + */ + shiftRight( numBits: number | Long ): Long; + + /** + * Returns this Long with bits arithmetically shifted to the right by the given amount. + */ + shr( numBits: number | Long ): Long; + + /** + * Returns this Long with bits logically shifted to the right by the given amount. + */ + shiftRightUnsigned( numBits: number | Long ): Long; + + /** + * Returns this Long with bits logically shifted to the right by the given amount. + */ + shru( numBits: number | Long ): Long; + + /** + * Returns the difference of this and the specified Long. + */ + subtract( subtrahend: number | Long | string ): Long; + + /** + * Returns the difference of this and the specified Long. + */ + sub( subtrahend: number | Long |string ): Long; + + /** + * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. + */ + toInt(): number; + + /** + * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). + */ + toNumber(): number; + + /** + * Converts this Long to signed. + */ + toSigned(): Long; + + /** + * Converts the Long to a string written in the specified radix. + */ + toString( radix?: number ): string; + + /** + * Converts this Long to unsigned. + */ + toUnsigned(): Long; + + /** + * Returns the bitwise XOR of this Long and the given one. + */ + xor( other: Long | number | string ): Long; } -declare module "long" { - var Long: dcodeIO.LongStatic; +declare module 'long' { export = Long; } \ No newline at end of file From bf9c2fe2143a2b0a874b0589dee819773925b3a5 Mon Sep 17 00:00:00 2001 From: dencap Date: Mon, 16 Nov 2015 16:44:35 +0100 Subject: [PATCH 5/8] Removed long.js filed from bytebuffer folder and restored original author name in long.js --- bytebuffer/long-tests.ts | 6 - bytebuffer/long.d.ts | 351 --------------------------------------- long/long.d.ts | 4 +- 3 files changed, 2 insertions(+), 359 deletions(-) delete mode 100644 bytebuffer/long-tests.ts delete mode 100644 bytebuffer/long.d.ts diff --git a/bytebuffer/long-tests.ts b/bytebuffer/long-tests.ts deleted file mode 100644 index 35dd6d784..000000000 --- a/bytebuffer/long-tests.ts +++ /dev/null @@ -1,6 +0,0 @@ -/// - -import Long = require("long"); - -var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); -console.log(longVal.toString()); \ No newline at end of file diff --git a/bytebuffer/long.d.ts b/bytebuffer/long.d.ts deleted file mode 100644 index 1d2e9f388..000000000 --- a/bytebuffer/long.d.ts +++ /dev/null @@ -1,351 +0,0 @@ -// Type definitions for long.js 3.0.2 -// Project: https://github.com/dcodeIO/long.js -// Definitions by: Denis Cappellin -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -declare class Long -{ - /** - * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as signed integers. See the from* functions below for more convenient ways of constructing Longs. - */ - constructor( low: number, high?: number, unsigned?: number ); - - /** - * Maximum unsigned value. - */ - static MAX_UNSIGNED_VALUE: Long; - - /** - * Maximum signed value. - */ - static MAX_VALUE: Long; - - /** - * Minimum signed value. - */ - static MIN_VALUE: Long; - - /** - * Signed negative one. - */ - static NEG_ONE: Long; - - /** - * Signed one. - */ - static ONE: Long; - - /** - * Unsigned one. - */ - static UONE: Long; - - /** - * Unsigned zero. - */ - static UZERO: Long; - - /** - * Signed zero - */ - static ZERO: Long; - - /** - * The high 32 bits as a signed value. - */ - high: number; - - /** - * The low 32 bits as a signed value. - */ - low: number; - - /** - * Whether unsigned or not. - */ - unsigned: number; - - /** - * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is assumed to use 32 bits. - */ - static fromBits( lowBits:number, highBits:number, unsigned?:boolean ): Long; - - /** - * Returns a Long representing the given 32 bit integer value. - */ - static fromInt( value: number, unsigned?: boolean ): Long; - - /** - * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned. - */ - static fromNumber( value: number, unsigned?: boolean ): Long; - - /** - * Returns a Long representation of the given string, written using the specified radix. - */ - static fromString( str: string, unsigned?: boolean | number, radix?: number ): Long; - - /** - * Tests if the specified object is a Long. - */ - static isLong( obj: any ): boolean; - - /** - * Converts the specified value to a Long. - */ - static fromValue( val: Long | number | string | {low: number, high: number, unsigned: boolean} ): Long; - - /** - * Returns the sum of this and the specified Long. - */ - add( addend: number | Long | string ): Long; - - /** - * Returns the bitwise AND of this Long and the specified. - */ - and( other: Long | number | string ): Long; - - /** - * Compares this Long's value with the specified's. - */ - compare( other: Long | number | string ): number; - - /** - * Compares this Long's value with the specified's. - */ - comp( other: Long | number | string ): number; - - /** - * Returns this Long divided by the specified. - */ - divide( divisor: Long | number | string ): Long; - - /** - * Returns this Long divided by the specified. - */ - div( divisor: Long | number | string ): Long; - - /** - * Tests if this Long's value equals the specified's. - */ - equals( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value equals the specified's. - */ - eq( other: Long | number | string ): boolean; - - /** - * Gets the high 32 bits as a signed integer. - */ - getHighBits(): number; - - /** - * Gets the high 32 bits as an unsigned integer. - */ - getHighBitsUnsigned(): number; - - /** - * Gets the low 32 bits as a signed integer. - */ - getLowBits(): number; - - /** - * Gets the low 32 bits as an unsigned integer. - */ - getLowBitsUnsigned(): number; - - /** - * Gets the number of bits needed to represent the absolute value of this Long. - */ - getNumBitsAbs(): number; - - /** - * Tests if this Long's value is greater than the specified's. - */ - greaterThan( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value is greater than the specified's. - */ - gt( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value is greater than or equal the specified's. - */ - greaterThanOrEqual( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value is greater than or equal the specified's. - */ - gte( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value is even. - */ - isEven(): boolean; - - /** - * Tests if this Long's value is negative. - */ - isNegative(): boolean; - - /** - * Tests if this Long's value is odd. - */ - isOdd(): boolean; - - /** - * Tests if this Long's value is positive. - */ - isPositive(): boolean; - - /** - * Tests if this Long's value equals zero. - */ - isZero(): boolean; - - /** - * Tests if this Long's value is less than the specified's. - */ - lessThan( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value is less than the specified's. - */ - lt( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value is less than or equal the specified's. - */ - lessThanOrEqual( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value is less than or equal the specified's. - */ - lte( other: Long | number | string ): boolean; - - /** - * Returns this Long modulo the specified. - */ - modulo( other: Long | number | string ): Long; - - /** - * Returns this Long modulo the specified. - */ - mod( other: Long | number | string ): Long; - - /** - * Returns the product of this and the specified Long. - */ - multiply( multiplier: Long | number | string ): Long; - - /** - * Returns the product of this and the specified Long. - */ - mul( multiplier: Long | number | string ): Long; - - /** - * Negates this Long's value. - */ - negate(): Long; - - /** - * Negates this Long's value. - */ - neg(): Long; - - /** - * Returns the bitwise NOT of this Long. - */ - not(): Long; - - /** - * Tests if this Long's value differs from the specified's. - */ - notEquals( other: Long | number | string ): boolean; - - /** - * Tests if this Long's value differs from the specified's. - */ - neq( other: Long | number | string ): boolean; - - /** - * Returns the bitwise OR of this Long and the specified. - */ - or( other: Long | number | string ): Long; - - /** - * Returns this Long with bits shifted to the left by the given amount. - */ - shiftLeft( numBits: number | Long ): Long; - - /** - * Returns this Long with bits shifted to the left by the given amount. - */ - shl( numBits: number | Long ): Long; - - /** - * Returns this Long with bits arithmetically shifted to the right by the given amount. - */ - shiftRight( numBits: number | Long ): Long; - - /** - * Returns this Long with bits arithmetically shifted to the right by the given amount. - */ - shr( numBits: number | Long ): Long; - - /** - * Returns this Long with bits logically shifted to the right by the given amount. - */ - shiftRightUnsigned( numBits: number | Long ): Long; - - /** - * Returns this Long with bits logically shifted to the right by the given amount. - */ - shru( numBits: number | Long ): Long; - - /** - * Returns the difference of this and the specified Long. - */ - subtract( subtrahend: number | Long ): Long; - - /** - * Returns the difference of this and the specified Long. - */ - sub( subtrahend: number | Long ): Long; - - /** - * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. - */ - toInt(): number; - - /** - * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). - */ - toNumber(): number; - - /** - * Converts this Long to signed. - */ - toSigned(): Long; - - /** - * Converts the Long to a string written in the specified radix. - */ - toString( radix?: number ): string; - - /** - * Converts this Long to unsigned. - */ - toUnsigned(): Long; - - /** - * Returns the bitwise XOR of this Long and the given one. - */ - xor( other: Long | number | string ): Long; -} - -declare module 'long' { - export = Long; -} diff --git a/long/long.d.ts b/long/long.d.ts index f059ff565..492dc3362 100644 --- a/long/long.d.ts +++ b/long/long.d.ts @@ -1,8 +1,8 @@ // Type definitions for long.js 3.0.2 // Project: https://github.com/dcodeIO/long.js -// Definitions by: Denis Cappellin -// Definitions: https://github.com/borisyankov/DefinitelyTyped // Definitions by: Peter Kooijmans +// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions by: Denis Cappellin declare class Long { From 1d23a699bae66c613b7e8f68826eeef586b41f5e Mon Sep 17 00:00:00 2001 From: dencap Date: Fri, 20 Nov 2015 15:01:35 +0100 Subject: [PATCH 6/8] Fixed the signature of concat, that takes as input an array --- bytebuffer/bytebuffer.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bytebuffer/bytebuffer.d.ts b/bytebuffer/bytebuffer.d.ts index 0bfaed7c1..8f1a800ea 100644 --- a/bytebuffer/bytebuffer.d.ts +++ b/bytebuffer/bytebuffer.d.ts @@ -131,7 +131,7 @@ declare class ByteBuffer /** * Concatenates multiple ByteBuffers into one. */ - static concat( buffers: Array | ArrayBuffer | Uint8Array | string, encoding?: string | boolean, litteEndian?: boolean, noAssert?: boolean ): ByteBuffer; + static concat( buffers: Array, encoding?: string | boolean, litteEndian?: boolean, noAssert?: boolean ): ByteBuffer; /** * Decodes a base64 encoded string to a ByteBuffer. From 1000b2c823ef215653d60d0a2f66dd9b4c38f183 Mon Sep 17 00:00:00 2001 From: dencap Date: Wed, 25 Nov 2015 17:18:44 +0100 Subject: [PATCH 7/8] First draft of definition for pako --- pako/pako-tests.ts | 26 ++++++++++++++++++++ pako/pako.d.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 pako/pako-tests.ts create mode 100644 pako/pako.d.ts diff --git a/pako/pako-tests.ts b/pako/pako-tests.ts new file mode 100644 index 000000000..b7bb504ca --- /dev/null +++ b/pako/pako-tests.ts @@ -0,0 +1,26 @@ +/// + +import pako = require("pako"); + +var test = { my: 'super', puper: [456, 567], awesome: 'pako' }; + +var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' }); + +// +// Here you can do base64 encode, make xhr requests and so on. +// + +var restored = JSON.parse(pako.inflate(binaryString, { to: 'string' })); + +var pako = require('pako') + , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9]) + , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]); + +var deflate = new pako.Deflate({ level: 3}); + +deflate.push(chunk1, false); +deflate.push(chunk2, true); // true -> last chunk + +if (deflate.err) { throw new Error(deflate.err); } + +console.log(deflate.result); \ No newline at end of file diff --git a/pako/pako.d.ts b/pako/pako.d.ts new file mode 100644 index 000000000..42465cee1 --- /dev/null +++ b/pako/pako.d.ts @@ -0,0 +1,60 @@ +// Type definitions for pako 0.2.8 +// Project: https://github.com/nodeca/pako +// Definitions by: Denis Cappellin +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module Pako { + + /** + * Compress data with deflate algorithm and options. + */ + export function deflate( data: Uint8Array | Array | string, options?: any ): string; + /** + * The same as deflate, but creates raw data, without wrapper (header and adler32 crc). + */ + export function deflateRaw( data: Uint8Array | Array | string, options?: any ): string; + /** + * The same as deflate, but create gzip wrapper instead of deflate one. + */ + export function gzip( data: Uint8Array | Array | string, options?: any ): string; + /** + * Decompress data with inflate/ungzip and options. Autodetect format via wrapper header + * by default. That's why we don't provide separate ungzip method. + */ + export function inflate( data: Uint8Array | Array | string, options?: any ): Uint8Array | Array | string; + /** + * The same as inflate, but creates raw data, without wrapper (header and adler32 crc). + */ + export function inflateRaw( data: Uint8Array | Array | string, options?: any ): Uint8Array | Array | string; + /** + * Just shortcut to inflate, because it autodetects format by header.content. Done for convenience. + */ + export function ungzip( data: Uint8Array | Array | string, options?: any ): Uint8Array | Array | string; + + export interface Deflate { + /** + * + */ + constructor( options?: any ); + err: number; + msg: string; + result: Uint8Array | Array; + onData( chunk: Uint8Array | Array | string ): void; + onEnd( status: number ): void; + push( data: Uint8Array | Array | ArrayBuffer | string, mode?: number | boolean ): boolean; + } + + export interface Inflate { + constructor( options?: any ); + err: number; + msg: string; + result: Uint8Array | Array | string; + onData( chunk: Uint8Array | Array | string ): void; + onEnd( status: number ): void; + push( data: Uint8Array | Array | ArrayBuffer | string, mode?: number | boolean ): boolean; + } +} + +declare module 'pako' { + export = Pako; +} From 82a3b88cdcf3d7832537020c33a30a1d90462e54 Mon Sep 17 00:00:00 2001 From: dencap Date: Wed, 25 Nov 2015 17:23:03 +0100 Subject: [PATCH 8/8] First draft of definition for pako --- pako/pako-tests.ts | 19 +++++-------------- pako/pako.d.ts | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/pako/pako-tests.ts b/pako/pako-tests.ts index b7bb504ca..b364d971f 100644 --- a/pako/pako-tests.ts +++ b/pako/pako-tests.ts @@ -2,25 +2,16 @@ import pako = require("pako"); -var test = { my: 'super', puper: [456, 567], awesome: 'pako' }; - -var binaryString = pako.deflate(JSON.stringify(test), { to: 'string' }); - -// -// Here you can do base64 encode, make xhr requests and so on. -// - -var restored = JSON.parse(pako.inflate(binaryString, { to: 'string' })); - -var pako = require('pako') - , chunk1 = Uint8Array([1,2,3,4,5,6,7,8,9]) - , chunk2 = Uint8Array([10,11,12,13,14,15,16,17,18,19]); +var chunk1 = new Uint8Array([1,2,3,4,5,6,7,8,9]) +var chunk2 = new Uint8Array([10,11,12,13,14,15,16,17,18,19]); var deflate = new pako.Deflate({ level: 3}); deflate.push(chunk1, false); deflate.push(chunk2, true); // true -> last chunk -if (deflate.err) { throw new Error(deflate.err); } +if (deflate.err) { + throw new Error( deflate.err.toString() ); +} console.log(deflate.result); \ No newline at end of file diff --git a/pako/pako.d.ts b/pako/pako.d.ts index 42465cee1..1b86f81fa 100644 --- a/pako/pako.d.ts +++ b/pako/pako.d.ts @@ -21,20 +21,23 @@ declare module Pako { * Decompress data with inflate/ungzip and options. Autodetect format via wrapper header * by default. That's why we don't provide separate ungzip method. */ - export function inflate( data: Uint8Array | Array | string, options?: any ): Uint8Array | Array | string; + export function inflate( data: Uint8Array | Array | string, options?: any ): Uint8Array; + export function inflate( data: Uint8Array | Array | string, options?: any ): Array; + export function inflate( data: Uint8Array | Array | string, options?: any ): String; /** * The same as inflate, but creates raw data, without wrapper (header and adler32 crc). */ - export function inflateRaw( data: Uint8Array | Array | string, options?: any ): Uint8Array | Array | string; + export function inflateRaw( data: Uint8Array | Array | string, options?: any ): Uint8Array; + export function inflateRaw( data: Uint8Array | Array | string, options?: any ): Array; + export function inflateRaw( data: Uint8Array | Array | string, options?: any ): string; /** * Just shortcut to inflate, because it autodetects format by header.content. Done for convenience. */ - export function ungzip( data: Uint8Array | Array | string, options?: any ): Uint8Array | Array | string; + export function ungzip( data: Uint8Array | Array | string, options?: any ): Uint8Array; + export function ungzip( data: Uint8Array | Array | string, options?: any ): Array; + export function ungzip( data: Uint8Array | Array | string, options?: any ): string; - export interface Deflate { - /** - * - */ + export class Deflate { constructor( options?: any ); err: number; msg: string; @@ -44,7 +47,7 @@ declare module Pako { push( data: Uint8Array | Array | ArrayBuffer | string, mode?: number | boolean ): boolean; } - export interface Inflate { + export class Inflate { constructor( options?: any ); err: number; msg: string;