{"name":"integer","version":"2.0.0","description":"Native 64-bit integers with overflow protection.","main":"lib/index.js","scripts":{"install-debug":"node-gyp rebuild --debug","test":"$(npm bin)/mocha --bail --timeout 1000 --slow 500","install":"node-gyp rebuild"},"repository":{"type":"git","url":"git://github.com/JoshuaWise/integer.git"},"keywords":["integer","64-bit","64bit","int","overflow","native"],"author":{"name":"Joshua Wise","email":"joshuathomaswise@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/JoshuaWise/integer/issues"},"homepage":"https://github.com/JoshuaWise/integer#readme","dependencies":{"bindings":"^1.3.0"},"devDependencies":{"chai":"^4.1.2","mocha":"^3.5.3"},"gypfile":true,"gitHead":"2f1c907224036bb77512667a2113ab39ef06de08","_id":"integer@2.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.11.3","_npmUser":{"name":"joshuawise","email":"joshuathomaswise@gmail.com"},"dist":{"integrity":"sha512-zK9YUsxjwxoE40WKv2AfVZ47PQvWFLV20xuVHClgPsz0cXy/mKQUxz2445Jl3WkPe90+IS3qxIlebxxzXN2dRQ==","shasum":"02d3b031ae6e46614e76f5de96c6ddcc5768ea54","tarball":"http://registry-npm.ywwl.com/integer/download/integer-2.0.0.tgz","fileCount":25,"unpackedSize":80149,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbnw2RCRA9TVsSAnZWagAAor4P/A2fnqB0UHknHkNWmONN\niH7En1AXb1p1R3jlFaVw0KmittB37Xp5ba/sy0q8IEd9585XUMA2Zudhylat\ntbhuqRibxZusuI9eR3zeh0LXX4K74T560mjtID4l6XVyeIz1YGd848Qz00s+\nqijeZtQQptVrNxUry/FD/peRQHE3I+kiFNmuk1yRdeRuJjRwJ81S0LKphXyw\niLZnI2g3FHi0bVst433awU9UeEQjttR0sYVA5MssC2NHhWp+rGOt2UaN0gGC\nRarIn2o8iKPhtuEbq5kQhuZ94UYHXT1Z1WZOIIXhtTiwwDrp7cp63/ABiCS1\nskA2CFSibHAIHZK0QRzPK6TQMRRe8afjrcJ+Fw/1GzL+ypHo40y3NJn9vTUR\n80LWoTDYc/L3tck0UBIWY2r2bQwR4N247EBxetrYMvfgv1OVUp96w81CGKEc\nkI4lKxd5d2L79eAMCzagY4Er52NOwGNL5DLc1inyqN2e44g5W39nu6IDh2uw\nSoSzxEnJiGuYJSl550PXw4/j6i6AKHgMc1WRTgiGY3QZo6wxCngpTCFGS0kC\n895WVX7Ls+/0R1zB8Qa3XHZFkkcSAn3cQONQhBvwa9socxO0ugYxVVTrI6M9\nUmWN+1oD5MWY0Jzn808gB+F8ULZA74w2A05JZLSukbvLjk4MZ3Udyn4K/x/K\nJ+FD\r\n=SI+a\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD73kyZcwvn1k4ZGzVEibIoha5yXDcyrwadGuvkx6A3+AIgYlU6pYQFEbKOiSo4RsRQoLAXbIBMIrLc+BS42Uf4A20="}],"size":15660,"noattachment":false,"key":"/integer/-/integer-2.0.0.tgz"},"maintainers":[{"email":"joshuathomaswise@gmail.com","name":"joshuawise"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/integer_2.0.0_1537150352619_0.5272956034066165"},"_hasShrinkwrap":false,"readme":"# integer [![Build Status](https://travis-ci.org/JoshuaWise/integer.svg?branch=master)](https://travis-ci.org/JoshuaWise/integer)\n\nNative 64-bit signed integers in Node.js.\n\n- All standard operators (arithmetic, bitwise, logical)\n- Protection from overflow and unsafe numbers\n- Always immutable\n- Other useful utilities\n\n## Installation\n\n```bash\nnpm install --save integer\n```\n\n> You must be using Node.js v10 or above. Prebuilt binaries are available for [LTS versions](https://nodejs.org/en/about/releases/) + Linux/OSX.\n\n## Usage\n\n```js\nvar Integer = require('integer');\n\nvar a = Integer('7129837312139827189');\nvar b = a.subtract(1).shiftRight(3);\nassert(b.equals('891229664017478398'));\n```\n\n## Overflow protection\n\nWe will not let you perform operations that would result in overflow. If you try to create an `Integer` that cannot be represented in 64-bits (signed), we will throw a `RangeError`.\n\n```js\n// These will each throw a RangeError\nvar tooBig = Integer(13897283129).multiply(13897283129);\nvar tooSmall = Integer.MIN_VALUE.subtract(1);\nvar divideByZero = Integer(123).divide(0);\nvar alsoTooBig = Integer('4029384203948203948923');\n\n// You are also protected against two's complement overflow (this will throw a RangeError)\nvar twosComplement = Integer.MIN_VALUE.divide(-1);\n```\n\n## Unsafe number protection\n\nIt's easy to convert between me and regular JavaScript numbers.\n\n```js\nvar int = Integer(12345);\nassert(int instanceof Integer);\n\nvar num = Number(int); // same as int.toNumber()\nassert(typeof num === 'number');\n```\n\nHowever, we will prevent you from converting an `Integer` to an unsafe number, and vice-versa. To learn more about unsafe numbers, [click here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger).\n\n```js\n// This will throw a RangeError\nvar unsafe = Integer(Number.MAX_SAFE_INTEGER + 1);\n\n// This is okay\nvar int = Integer(Number.MAX_SAFE_INTEGER).plus(1);\n\n// But this will throw a RangeError\nvar unsafe = int.toNumber();\n```\n\n# API\n\n### Integer(*value*) -> *Integer*\n\nCasts a value to an `Integer`. If the value cannot be converted safely and losslessly, a `RangeError` is thrown.\n\n```js\nvar a = Integer();\nvar b = Integer(12345);\nvar c = Integer('12345');\nassert(a.equals(0));\nassert(b.equals(c));\n```\n\n### Integer.fromNumber(*number*, [*defaultValue*]) -> *Integer*\n\nCasts a regular number to an `Integer`.\n\nIf the number is unsafe the `defaultValue` is used instead (or a `RangeError` is thrown if no `defaultValue` was provided).\n\n```js\nInteger.fromNumber(12345, 0); // results in Integer(12345)\nInteger.fromNumber(Number.MAX_SAFE_INTEGER + 1, 0); // results in Integer(0)\n```\n\n### Integer.fromString(*string*, [*radix*, [*defaultValue*]]) -> *Integer*\n\nCasts a string to an `Integer`. The string is assumed to be [base-10](https://en.wikipedia.org/wiki/Radix) unless a different `radix` is specified.\n\nIf conversions fails the `defaultValue` is used instead (or a `RangeError` is thrown if no `defaultValue` was provided).\n\n```js\nvar hexColor = 'ff55dd';\nvar int = Integer.fromString(hexColor, 16, 'ffffff');\n```\n\n### Integer.fromBits(*lowBits*, [*highBits*]) -> *Integer*\n\nCreates an `Integer` by concatenating two regular 32-bit signed integers. The `highBits` are optional and default to `0`.\n\n```js\nvar int = Integer.fromBits(0x40, 0x20);\nint.toString(16); // => '2000000040'\n```\n\n## Arithmetic operations\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.add/plus(*other*) -> *Integer*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.subtract/sub/minus(*other*) -> *Integer*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.multiply/mul/times(*other*) -> *Integer*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.divide/div/divideBy/dividedBy/over(*other*) -> *Integer*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.modulo/mod(*other*) -> *Integer*\n\nPerforms the arithmetic operation and returns a new `Integer`. The argument must either be a number, a base-10 string, or an `Integer`. If the operation results in overflow, a `RangeError` is thrown.\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.negate/neg() -> *Integer*\n\nReturns the unary negation (`-value`) of the `Integer`.\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.abs/absoluteValue() -> *Integer*\n\nReturns the absolute value of the `Integer`.\n\n## Bitwise operations\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.and(*other*) -> *Integer*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.or(*other*) -> *Integer*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.xor(*other*) -> *Integer*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.not() -> *Integer*\n\nPerforms the bitwise operation and returns a new `Integer`. The argument must either be a number, a base-10 string, or an `Integer`.\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.shiftLeft/shl(*numberOfBits*) -> *Integer*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.shiftRight/shr(*numberOfBits*) -> *Integer*\n\nShifts the `Integer` by specified number of bits and returns the result.\n\n## Logical operations\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.equals/eq/isEqualTo(*other*) -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.notEquals/neq/isNotEqualTo/doesNotEqual(*other*) -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.greaterThan/gt/isGreaterThan(*other*) -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.lessThan/lt/isLessThan(*other*) -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.greaterThanOrEquals/gte/isGreaterThanOrEqualTo(*other*) -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.lessThanOrEquals/lte/isLessThanOrEqualTo(*other*) -> *boolean*\n\nPerforms the logical operation and returns `true` or `false`. The argument must either be a number, a base-10 string, or an `Integer`.\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.compare(*other*) -> *number*\n\nCompares the value of the `Integer` and `other`, resulting in:\n- `-1` if `this` is less than `other`\n- `1` if `this` is greater than `other`\n- `0` if `this` is equal to `other`\n\n## Converting to other values\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.toString([*radix*]) -> *string*\n\nConverts the `Integer` to a string. A base-10 string is returned unless a different `radix` is specified.\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.valueOf/toNumber() -> *number*\n\nConverts the `Integer` to a regular number. If the `Integer` is not within the safe range, a `RangeError` is thrown.\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.toNumberUnsafe() -> *number*\n\nConverts the `Integer` to a regular number, **even if the conversion would result in a loss of precision**. This method will never throw an error.\n\n## Other utility\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.bitSizeAbs() -> *number*\n\nReturns the number of bits necessary to hold the absolute value of the `Integer`.\n\n```js\nInteger(0).bitSizeAbs(); // => 1\nInteger(128).bitSizeAbs(); // => 8\nInteger(-255).bitSizeAbs(); // => 8\nInteger.fromString('4fffffffffff', 16).bitSizeAbs(); // => 47\n```\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.isEven() -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.isOdd() -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.isPositive() -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.isNegative() -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.isZero() -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.isNonZero/isNotZero() -> *boolean*\n\nThese methods are self-explanatory.\n\n#### &nbsp;&nbsp;&nbsp;&nbsp;.isSafe() -> *boolean*\n#### &nbsp;&nbsp;&nbsp;&nbsp;.isUnsafe() -> *boolean*\n\nReturns whether or not the `Integer` is within the safe range. If it's not within the safe range, trying to convert it to a regular number would result in a `RangeError` being thrown.\n\nThe safe range is defined as `n >= Number.MIN_SAFE_INTEGER && n <= Number.MAX_SAFE_INTEGER`.\n\n#### Integer.isInstance(*value*) -> *boolean*\n\nDetermines if the given value is an `Integer` object.\n\n#### Getters\n\n- **.low -> _number_** - the lower 32-bits of the `Integer`\n- **.high -> _number_** - the upper 32-bits of the `Integer`\n\n#### Constants\n\n- **Integer.MAX_VALUE** - maximum value of an `Integer`\n- **Integer.MIN_VALUE** - minimum value of an `Integer`\n- **Integer.ZERO** - an `Integer` with a value of `0`\n- **Integer.ONE** - an `Integer` with a value of `1`\n- **Integer.NEG_ONE** - an `Integer` with a value of `-1`\n\n## License\n\n[MIT](https://github.com/JoshuaWise/integer/blob/master/LICENSE)\n","publish_time":1537150352781,"_cnpm_publish_time":1537150352781,"dist-tags":{"latest":"4.0.0"}}