Comparing version 5.1.0 to 5.2.0
@@ -213,3 +213,3 @@ declare class Long { | ||
/** | ||
* Tests if this Long's value is positive. | ||
* Tests if this Long's value is positive or zero. | ||
*/ | ||
@@ -294,2 +294,22 @@ isPositive(): boolean; | ||
/** | ||
* Returns count leading zeros of this Long. | ||
*/ | ||
countLeadingZeros(): number; | ||
/** | ||
* Returns count leading zeros of this Long. | ||
*/ | ||
clz(): number; | ||
/** | ||
* Returns count trailing zeros of this Long. | ||
*/ | ||
countTrailingZeros(): number; | ||
/** | ||
* Returns count trailing zeros of this Long. | ||
*/ | ||
ctz(): number; | ||
/** | ||
* Tests if this Long's value differs from the specified's. | ||
@@ -296,0 +316,0 @@ */ |
49
index.js
@@ -5,3 +5,3 @@ /** | ||
* Copyright 2020 Daniel Wirtz / The long.js Authors. | ||
* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -101,2 +101,13 @@ * you may not use this file except in compliance with the License. | ||
/** | ||
* @function | ||
* @param {*} value number | ||
* @returns {number} | ||
* @inner | ||
*/ | ||
function ctz32(value) { | ||
var c = Math.clz32(value & -value); | ||
return value ? 31 - c : c; | ||
} | ||
/** | ||
* Tests if the specified object is a Long. | ||
@@ -604,3 +615,3 @@ * @function | ||
/** | ||
* Tests if this Long's value is positive. | ||
* Tests if this Long's value is positive or zero. | ||
* @this {!Long} | ||
@@ -1133,2 +1144,36 @@ * @returns {boolean} | ||
/** | ||
* Returns count leading zeros of this Long. | ||
* @this {!Long} | ||
* @returns {!number} | ||
*/ | ||
LongPrototype.countLeadingZeros = function countLeadingZeros() { | ||
return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32; | ||
}; | ||
/** | ||
* Returns count leading zeros. This is an alias of {@link Long#countLeadingZeros}. | ||
* @function | ||
* @param {!Long} | ||
* @returns {!number} | ||
*/ | ||
LongPrototype.clz = LongPrototype.countLeadingZeros; | ||
/** | ||
* Returns count trailing zeros of this Long. | ||
* @this {!Long} | ||
* @returns {!number} | ||
*/ | ||
LongPrototype.countTrailingZeros = function countTrailingZeros() { | ||
return this.low ? ctz32(this.low) : ctz32(this.high) + 32; | ||
}; | ||
/** | ||
* Returns count trailing zeros. This is an alias of {@link Long#countTrailingZeros}. | ||
* @function | ||
* @param {!Long} | ||
* @returns {!number} | ||
*/ | ||
LongPrototype.ctz = LongPrototype.countTrailingZeros; | ||
/** | ||
* Returns the bitwise AND of this Long and the specified. | ||
@@ -1135,0 +1180,0 @@ * @this {!Long} |
{ | ||
"name": "long", | ||
"version": "5.1.0", | ||
"version": "5.2.0", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
@@ -5,0 +5,0 @@ "description": "A Long class for representing a 64-bit two's-complement integer value.", |
@@ -32,13 +32,29 @@ long.js | ||
``` | ||
$> npm install long | ||
``` | ||
```js | ||
import Long from "long"; | ||
var longVal = new Long(0xFFFFFFFF, 0x7FFFFFFF); | ||
console.log(longVal.toString()); | ||
var value = new Long(0xFFFFFFFF, 0x7FFFFFFF); | ||
console.log(value.toString()); | ||
... | ||
``` | ||
Note that mixing ESM and CommonJS is not recommended as it yield different classes with the same functionality. | ||
Note that mixing ESM and CommonJS is not recommended as it yields different classes, albeit with the same functionality. | ||
### Usage with a CDN | ||
* From GitHub via [jsDelivr](https://www.jsdelivr.com):<br /> | ||
`https://cdn.jsdelivr.net/gh/dcodeIO/long.js@TAG/index.js` (ESM) | ||
* From npm via [jsDelivr](https://www.jsdelivr.com):<br /> | ||
`https://cdn.jsdelivr.net/npm/long@VERSION/index.js` (ESM)<br /> | ||
`https://cdn.jsdelivr.net/npm/long@VERSION/umd/index.js` (UMD) | ||
* From npm via [unpkg](https://unpkg.com):<br /> | ||
`https://unpkg.com/long@VERSION/index.js` (ESM)<br /> | ||
`https://unpkg.com/long@VERSION/umd/index.js` (UMD) | ||
Replace `TAG` respectively `VERSION` with a [specific version](https://github.com/dcodeIO/long.js/releases) or omit it (not recommended in production) to use main/latest. | ||
API | ||
@@ -167,3 +183,3 @@ --- | ||
* Long#**isPositive**(): `boolean`<br /> | ||
Tests if this Long's value is positive. | ||
Tests if this Long's value is positive or zero. | ||
@@ -191,2 +207,8 @@ * Long#**isZero**/**eqz**(): `boolean`<br /> | ||
* Long#**countLeadingZeros**/**clz**(): `number`<br /> | ||
Returns count leading zeros of this Long. | ||
* Long#**countTrailingZeros**/**ctz**(): `number`<br /> | ||
Returns count trailing zeros of this Long. | ||
* Long#**notEquals**/**neq**/**ne**(other: `Long | number | string`): `boolean`<br /> | ||
@@ -251,2 +273,8 @@ Tests if this Long's value differs from the specified's. | ||
Building the UMD fallback: | ||
``` | ||
$> npm run build | ||
``` | ||
Running the [tests](./tests): | ||
@@ -253,0 +281,0 @@ |
@@ -14,3 +14,3 @@ // GENERATED FILE. DO NOT EDIT. | ||
* Copyright 2020 Daniel Wirtz / The long.js Authors. | ||
* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
@@ -107,2 +107,14 @@ * you may not use this file except in compliance with the License. | ||
/** | ||
* @function | ||
* @param {*} value number | ||
* @returns {number} | ||
* @inner | ||
*/ | ||
function ctz32(value) { | ||
var c = Math.clz32(value & -value); | ||
return value ? 31 - c : c; | ||
} | ||
/** | ||
* Tests if the specified object is a Long. | ||
@@ -614,3 +626,3 @@ * @function | ||
/** | ||
* Tests if this Long's value is positive. | ||
* Tests if this Long's value is positive or zero. | ||
* @this {!Long} | ||
@@ -1122,2 +1134,39 @@ * @returns {boolean} | ||
/** | ||
* Returns count leading zeros of this Long. | ||
* @this {!Long} | ||
* @returns {!number} | ||
*/ | ||
LongPrototype.countLeadingZeros = function countLeadingZeros() { | ||
return this.high ? Math.clz32(this.high) : Math.clz32(this.low) + 32; | ||
}; | ||
/** | ||
* Returns count leading zeros. This is an alias of {@link Long#countLeadingZeros}. | ||
* @function | ||
* @param {!Long} | ||
* @returns {!number} | ||
*/ | ||
LongPrototype.clz = LongPrototype.countLeadingZeros; | ||
/** | ||
* Returns count trailing zeros of this Long. | ||
* @this {!Long} | ||
* @returns {!number} | ||
*/ | ||
LongPrototype.countTrailingZeros = function countTrailingZeros() { | ||
return this.low ? ctz32(this.low) : ctz32(this.high) + 32; | ||
}; | ||
/** | ||
* Returns count trailing zeros. This is an alias of {@link Long#countTrailingZeros}. | ||
* @function | ||
* @param {!Long} | ||
* @returns {!number} | ||
*/ | ||
LongPrototype.ctz = LongPrototype.countTrailingZeros; | ||
/** | ||
* Returns the bitwise AND of this Long and the specified. | ||
@@ -1129,3 +1178,2 @@ * @this {!Long} | ||
LongPrototype.and = function and(other) { | ||
@@ -1132,0 +1180,0 @@ if (!isLong(other)) other = fromValue(other); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
118698
2896
281