diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7db7b1d7d..21d90bc18 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -205,6 +205,7 @@ All definitions files include a header with the author and editors, so at some p * [localForage](https://github.com/mozilla/localForage) (by [david pichsenmeister](https://github.com/3x14159265)) * [Lodash](http://lodash.com/) (by [Brian Zengel](https://github.com/bczengel)) * [Logg](https://github.com/dpup/node-logg) (by [Bret Little](https://github.com/blittle)) +* [Long.js](https://github.com/dcodeIO/Long.js) (by [Toshihide Hara](https://github.com/kerug)) * [lz-string](https://github.com/pieroxy/lz-string) (by [Roman Nikitin](https://github.com/M0ns1gn0r)) * [Marked](https://github.com/chjj/marked) (by [William Orr](https://github.com/worr)) * [mCustomScrollbar](https://github.com/malihu/malihu-custom-scrollbar-plugin) (by [Sarah Williams](https://github.com/flurg)) diff --git a/long/long-tests.ts b/long/long-tests.ts new file mode 100644 index 000000000..6679a820a --- /dev/null +++ b/long/long-tests.ts @@ -0,0 +1,68 @@ +/// + +// --- commonjs --- +import Long = require("long"); +// --- browser --- +//var Long = dcodeIO.Long; + +var val:Long; +var n:number; +var b:boolean; +var s:string; + +val = new Long(0xFFFFFFFF, 0x7FFFFFFF); + +val = Long.from28Bits(0xFFFFFFF, 0xFFFFFFF, 0xFF); + +val = Long.fromInt(-1, true); +n = val.low; +n = val.high; +b = val.unsigned; +s = val.toString(); + +val = val.add(val); +val = val.and(val); +val = val.clone(); +n = val.compare(val); +val = val.div(val); +b = val.equals(val); +n = val.getHighBits(); +n = val.getHighBitsUnsigned(); +n = val.getLowBits(); +n = val.getLowBitsUnsigned(); +n = val.getNumBitsAbs(); +b = val.greaterThan(val); +b = val.greaterThanOrEqual(val); +b = val.isEven(); +b = val.isNegative(); +b = val.isOdd(); +b = val.isZero(); +b = val.lessThan(val); +b = val.lessThanOrEqual(val); +val = val.modulo(val); +val = val.multiply(val); +val = val.negate(); +val = val.not(); +b = val.notEquals(val); +val = val.or(val); +val = val.shiftLeft(2); +val = val.shiftRight(1); +val = val.shiftRightUnsigned(1); +val = val.subtract(val); +n = val.toInt(); +n = val.toNumber(); +val = val.toSigned(); +val = val.toUnsigned(); +val = val.xor(val); + +val = Long.MAX_SIGNED_VALUE; +val = Long.MAX_UNSIGNED_VALUE; +val = Long.MAX_VALUE; +val = Long.MIN_SIGNED_VALUE; +val = Long.MIN_UNSIGNED_VALUE; +val = Long.MIN_VALUE; +val = Long.NEG_ONE; +val = Long.ONE; +val = Long.ZERO; + + diff --git a/long/long.d.ts b/long/long.d.ts new file mode 100644 index 000000000..98200e0a8 --- /dev/null +++ b/long/long.d.ts @@ -0,0 +1,80 @@ +// Type definitions for Long.js 1.1.2 +// Project: https://github.com/dcodeIO/Long.js +// Definitions by: Toshihide Hara +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface LongStatic { + new(low:number, high:number, unsigned?:boolean):Long; + + MAX_SIGNED_VALUE:Long; + MAX_UNSIGNED_VALUE:Long; + MAX_VALUE:Long; + MIN_SIGNED_VALUE:Long; + MIN_UNSIGNED_VALUE:Long; + MIN_VALUE:Long; + NEG_ONE:Long; + ONE:Long; + ZERO:Long; + + from28Bits(part0:number, part1:number, part2:number, unsigned?:boolean):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, radix?:number):Long; + fromString(str:string, unsigned?:number, radix?:number):Long; + fromString(str:string, unsigned?:any, radix?:number):Long; +} + +interface Long { + high:number; + low:number; + unsigned:boolean; + + add(other:Long):Long; + and(other:Long):Long; + clone():Long; + compare(other:Long):number; + div(other:Long):Long; + equals(other:Long):boolean; + getHighBits():number; + getHighBitsUnsigned():number; + getLowBits():number; + getLowBitsUnsigned():number; + getNumBitsAbs():number; + greaterThan(other:Long):boolean; + greaterThanOrEqual(other:Long):boolean; + isEven():boolean; + isNegative():boolean; + isOdd():boolean; + isZero():boolean; + lessThan(other:Long):boolean; + lessThanOrEqual(other:Long):boolean; + modulo(other:Long):Long; + multiply(other:Long):Long; + negate():Long; + not():Long; + notEquals(other:Long):boolean; + or(other:Long):Long; + shiftLeft(numBits:number):Long; + shiftRight(numBits:number):Long; + shiftRightUnsigned(numBits:number):Long; + subtract(other:Long):Long; + toInt():number; + toNumber():number; + toSigned():Long; + toString(radix?:number):string; + toUnsigned():Long; + xor(other:Long):Long; +} + +// for browser +declare module dcodeIO { + export var Long:LongStatic; +} + +// for node, commonjs +declare module "long" { + export = Long; +} + +declare var Long:LongStatic;