@polkadot/util
Advanced tools
Comparing version 9.2.2-14 to 9.2.2-15
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.compactFromU8a = compactFromU8a; | ||
exports.compactFromU8aStrict = compactFromU8aStrict; | ||
exports.compactFromU8aLim = compactFromU8aLim; | ||
@@ -32,13 +32,5 @@ var _bn = require("../bn"); | ||
function compactFromU8a(input) { | ||
return compactFromU8aStrict((0, _u8a.u8aToU8a)(input)); | ||
} | ||
/** | ||
* @name compactFromU8aStrict | ||
* @description A strict version of [[compactFromU8a]], accepting only Uint8Array inputs | ||
*/ | ||
const u8a = (0, _u8a.u8aToU8a)(input); // The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster | ||
// than doing an additional call to u8aToBn (as with variable length) | ||
function compactFromU8aStrict(u8a) { | ||
// The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster | ||
// than doing an additional call to u8aToBn (as with variable length) | ||
switch (u8a[0] & 0b11) { | ||
@@ -78,2 +70,46 @@ case 0b00: | ||
} | ||
} | ||
/** | ||
* @name compactFromU8aLim | ||
* @description A limited version of [[compactFromU8a]], accepting only Uint8Array inputs for values <= 48 bits | ||
*/ | ||
function compactFromU8aLim(u8a) { | ||
// The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster | ||
// than doing an additional call to u8aToBn (as with variable length) | ||
switch (u8a[0] & 0b11) { | ||
case 0b00: | ||
return [1, u8a[0] >>> 2]; | ||
case 0b01: | ||
return [2, u8a[0] + u8a[1] * 0x100 >>> 2]; | ||
case 0b10: | ||
return [4, u8a[0] + u8a[1] * 0x100 + u8a[2] * 0x10000 + u8a[3] * 0x1000000 >>> 2]; | ||
// 0b11 | ||
default: | ||
break; | ||
} // add 5 to shifted (4 for base length, 1 for this byte) | ||
const offset = (u8a[0] >>> 2) + 5; // we unroll the loop | ||
switch (offset) { | ||
// there still could be 4 bytes data, similar to 0b10 above (with offsets) | ||
case 5: | ||
return [5, u8a[1] + u8a[2] * 0x100 + u8a[3] * 0x10000 + u8a[4] * 0x1000000]; | ||
case 6: | ||
return [6, u8a[1] + u8a[2] * 0x100 + u8a[3] * 0x10000 + u8a[4] * 0x1000000 + u8a[5] * 0x100000000]; | ||
// 6 bytes data is the maximum, 48 bits (56 would overflow) | ||
case 7: | ||
return [7, u8a[1] + u8a[2] * 0x100 + u8a[3] * 0x10000 + u8a[4] * 0x1000000 + u8a[5] * 0x100000000 + u8a[6] * 0x10000000000]; | ||
// for anything else, use the non-unrolled version | ||
default: | ||
throw new Error('Compact input is > Number.MAX_SAFE_INTEGER'); | ||
} | ||
} |
@@ -18,6 +18,6 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "compactFromU8aStrict", { | ||
Object.defineProperty(exports, "compactFromU8aLim", { | ||
enumerable: true, | ||
get: function () { | ||
return _fromU8a.compactFromU8aStrict; | ||
return _fromU8a.compactFromU8aLim; | ||
} | ||
@@ -24,0 +24,0 @@ }); |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.isAscii = isAscii; | ||
exports.isAsciiStrict = isAsciiStrict; | ||
@@ -40,15 +39,6 @@ var _toU8a = require("../u8a/toU8a"); | ||
if (value) { | ||
return isStringIn && !(0, _hex.isHex)(value) ? value.toString().split('').every(isAsciiChar) : isAsciiStrict((0, _toU8a.u8aToU8a)(value)); | ||
return isStringIn && !(0, _hex.isHex)(value) ? value.toString().split('').every(isAsciiChar) : (0, _toU8a.u8aToU8a)(value).every(isAsciiByte); | ||
} | ||
return isStringIn; | ||
} | ||
/** | ||
* @name isAsciiStrict | ||
* @description A strict version of [[isAscii]], accepting only Uint8Array inputs | ||
*/ | ||
function isAsciiStrict(u8a) { | ||
return u8a.every(isAsciiByte); | ||
} |
@@ -18,8 +18,2 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "isAsciiStrict", { | ||
enumerable: true, | ||
get: function () { | ||
return _ascii.isAsciiStrict; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isBigInt", { | ||
@@ -175,8 +169,2 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "isUtf8Strict", { | ||
enumerable: true, | ||
get: function () { | ||
return _utf.isUtf8Strict; | ||
} | ||
}); | ||
Object.defineProperty(exports, "isWasm", { | ||
@@ -183,0 +171,0 @@ enumerable: true, |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.isUtf8 = isUtf8; | ||
exports.isUtf8Strict = isUtf8Strict; | ||
@@ -29,11 +28,3 @@ var _toU8a = require("../u8a/toU8a"); | ||
return isUtf8Strict((0, _toU8a.u8aToU8a)(value)); | ||
} | ||
/** | ||
* @name isUtf8Strict | ||
* @description A strict version of [[isUtf8]], acception only Uint8Array inpouts | ||
*/ | ||
function isUtf8Strict(u8a) { | ||
const u8a = (0, _toU8a.u8aToU8a)(value); | ||
const len = u8a.length; | ||
@@ -40,0 +31,0 @@ let i = 0; |
@@ -14,4 +14,4 @@ "use strict"; | ||
type: 'cjs', | ||
version: '9.2.2-14' | ||
version: '9.2.2-15' | ||
}; | ||
exports.packageInfo = packageInfo; |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.u8aCmp = u8aCmp; | ||
exports.u8aCmpStrict = u8aCmpStrict; | ||
@@ -32,11 +31,4 @@ var _toU8a = require("./toU8a"); | ||
function u8aCmp(a, b) { | ||
return u8aCmpStrict((0, _toU8a.u8aToU8a)(a), (0, _toU8a.u8aToU8a)(b)); | ||
} | ||
/** | ||
* @name u8aCmpStrict | ||
* @description A strict version of [[u8aCmp]], accepting only Uint8Array inputs | ||
*/ | ||
function u8aCmpStrict(u8aa, u8ab) { | ||
const u8aa = (0, _toU8a.u8aToU8a)(a); | ||
const u8ab = (0, _toU8a.u8aToU8a)(b); | ||
let i = 0; | ||
@@ -43,0 +35,0 @@ |
@@ -7,3 +7,2 @@ "use strict"; | ||
exports.u8aEq = u8aEq; | ||
exports.u8aEqStrict = u8aEqStrict; | ||
@@ -30,11 +29,5 @@ var _toU8a = require("./toU8a"); | ||
function u8aEq(a, b) { | ||
return u8aEqStrict((0, _toU8a.u8aToU8a)(a), (0, _toU8a.u8aToU8a)(b)); | ||
} | ||
/** | ||
* @name u8aEqStrict | ||
* @description A strict version of [[u8aCmp]], accepting only Uint8Array inputs | ||
*/ | ||
const u8aa = (0, _toU8a.u8aToU8a)(a); | ||
const u8ab = (0, _toU8a.u8aToU8a)(b); | ||
function u8aEqStrict(u8aa, u8ab) { | ||
if (u8aa.length === u8ab.length) { | ||
@@ -41,0 +34,0 @@ const dvA = new DataView(u8aa.buffer, u8aa.byteOffset); |
@@ -30,8 +30,2 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "u8aCmpStrict", { | ||
enumerable: true, | ||
get: function () { | ||
return _cmp.u8aCmpStrict; | ||
} | ||
}); | ||
Object.defineProperty(exports, "u8aConcat", { | ||
@@ -61,8 +55,2 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, "u8aEqStrict", { | ||
enumerable: true, | ||
get: function () { | ||
return _eq.u8aEqStrict; | ||
} | ||
}); | ||
Object.defineProperty(exports, "u8aFixLength", { | ||
@@ -69,0 +57,0 @@ enumerable: true, |
@@ -20,5 +20,5 @@ /// <reference types="bn.js" /> | ||
/** | ||
* @name compactFromU8aStrict | ||
* @description A strict version of [[compactFromU8a]], accepting only Uint8Array inputs | ||
* @name compactFromU8aLim | ||
* @description A limited version of [[compactFromU8a]], accepting only Uint8Array inputs for values <= 48 bits | ||
*/ | ||
export declare function compactFromU8aStrict(u8a: Uint8Array): [number, BN]; | ||
export declare function compactFromU8aLim(u8a: Uint8Array): [number, number]; |
@@ -21,12 +21,5 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
export function compactFromU8a(input) { | ||
return compactFromU8aStrict(u8aToU8a(input)); | ||
} | ||
/** | ||
* @name compactFromU8aStrict | ||
* @description A strict version of [[compactFromU8a]], accepting only Uint8Array inputs | ||
*/ | ||
const u8a = u8aToU8a(input); // The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster | ||
// than doing an additional call to u8aToBn (as with variable length) | ||
export function compactFromU8aStrict(u8a) { | ||
// The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster | ||
// than doing an additional call to u8aToBn (as with variable length) | ||
switch (u8a[0] & 0b11) { | ||
@@ -66,2 +59,45 @@ case 0b00: | ||
} | ||
} | ||
/** | ||
* @name compactFromU8aLim | ||
* @description A limited version of [[compactFromU8a]], accepting only Uint8Array inputs for values <= 48 bits | ||
*/ | ||
export function compactFromU8aLim(u8a) { | ||
// The u8a is manually converted here for 1, 2 & 4 lengths, it is 2x faster | ||
// than doing an additional call to u8aToBn (as with variable length) | ||
switch (u8a[0] & 0b11) { | ||
case 0b00: | ||
return [1, u8a[0] >>> 2]; | ||
case 0b01: | ||
return [2, u8a[0] + u8a[1] * 0x100 >>> 2]; | ||
case 0b10: | ||
return [4, u8a[0] + u8a[1] * 0x100 + u8a[2] * 0x10000 + u8a[3] * 0x1000000 >>> 2]; | ||
// 0b11 | ||
default: | ||
break; | ||
} // add 5 to shifted (4 for base length, 1 for this byte) | ||
const offset = (u8a[0] >>> 2) + 5; // we unroll the loop | ||
switch (offset) { | ||
// there still could be 4 bytes data, similar to 0b10 above (with offsets) | ||
case 5: | ||
return [5, u8a[1] + u8a[2] * 0x100 + u8a[3] * 0x10000 + u8a[4] * 0x1000000]; | ||
case 6: | ||
return [6, u8a[1] + u8a[2] * 0x100 + u8a[3] * 0x10000 + u8a[4] * 0x1000000 + u8a[5] * 0x100000000]; | ||
// 6 bytes data is the maximum, 48 bits (56 would overflow) | ||
case 7: | ||
return [7, u8a[1] + u8a[2] * 0x100 + u8a[3] * 0x10000 + u8a[4] * 0x1000000 + u8a[5] * 0x100000000 + u8a[6] * 0x10000000000]; | ||
// for anything else, use the non-unrolled version | ||
default: | ||
throw new Error('Compact input is > Number.MAX_SAFE_INTEGER'); | ||
} | ||
} |
@@ -23,3 +23,3 @@ /** | ||
export { compactStripLength } from './stripLength'; | ||
export { compactFromU8a, compactFromU8aStrict } from './fromU8a'; | ||
export { compactFromU8a, compactFromU8aLim } from './fromU8a'; | ||
export { compactToU8a } from './toU8a'; |
@@ -26,3 +26,3 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
export { compactStripLength } from "./stripLength.js"; | ||
export { compactFromU8a, compactFromU8aStrict } from "./fromU8a.js"; | ||
export { compactFromU8a, compactFromU8aLim } from "./fromU8a.js"; | ||
export { compactToU8a } from "./toU8a.js"; |
@@ -9,6 +9,1 @@ import type { U8aLike } from '../types'; | ||
export declare function isAscii(value?: U8aLike | null): boolean; | ||
/** | ||
* @name isAsciiStrict | ||
* @description A strict version of [[isAscii]], accepting only Uint8Array inputs | ||
*/ | ||
export declare function isAsciiStrict(u8a: Uint8Array): boolean; |
@@ -28,14 +28,6 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
if (value) { | ||
return isStringIn && !isHex(value) ? value.toString().split('').every(isAsciiChar) : isAsciiStrict(u8aToU8a(value)); | ||
return isStringIn && !isHex(value) ? value.toString().split('').every(isAsciiChar) : u8aToU8a(value).every(isAsciiByte); | ||
} | ||
return isStringIn; | ||
} | ||
/** | ||
* @name isAsciiStrict | ||
* @description A strict version of [[isAscii]], accepting only Uint8Array inputs | ||
*/ | ||
export function isAsciiStrict(u8a) { | ||
return u8a.every(isAsciiByte); | ||
} |
@@ -5,3 +5,3 @@ /** | ||
export { isArray } from './array'; | ||
export { isAscii, isAsciiStrict } from './ascii'; | ||
export { isAscii } from './ascii'; | ||
export { isBigInt } from './bigInt'; | ||
@@ -31,3 +31,3 @@ export { isBn } from './bn'; | ||
export { isUndefined } from './undefined'; | ||
export { isUtf8, isUtf8Strict } from './utf8'; | ||
export { isUtf8 } from './utf8'; | ||
export { isWasm } from './wasm'; |
@@ -8,3 +8,3 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
export { isArray } from "./array.js"; | ||
export { isAscii, isAsciiStrict } from "./ascii.js"; | ||
export { isAscii } from "./ascii.js"; | ||
export { isBigInt } from "./bigInt.js"; | ||
@@ -34,3 +34,3 @@ export { isBn } from "./bn.js"; | ||
export { isUndefined } from "./undefined.js"; | ||
export { isUtf8, isUtf8Strict } from "./utf8.js"; | ||
export { isUtf8 } from "./utf8.js"; | ||
export { isWasm } from "./wasm.js"; |
@@ -10,6 +10,1 @@ /// <reference types="node" /> | ||
export declare function isUtf8(value?: HexString | number[] | Buffer | Uint8Array | string | null): boolean; | ||
/** | ||
* @name isUtf8Strict | ||
* @description A strict version of [[isUtf8]], acception only Uint8Array inpouts | ||
*/ | ||
export declare function isUtf8Strict(u8a: Uint8Array): boolean; |
@@ -18,10 +18,3 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
return isUtf8Strict(u8aToU8a(value)); | ||
} | ||
/** | ||
* @name isUtf8Strict | ||
* @description A strict version of [[isUtf8]], acception only Uint8Array inpouts | ||
*/ | ||
export function isUtf8Strict(u8a) { | ||
const u8a = u8aToU8a(value); | ||
const len = u8a.length; | ||
@@ -28,0 +21,0 @@ let i = 0; |
@@ -23,3 +23,3 @@ { | ||
"type": "module", | ||
"version": "9.2.2-14", | ||
"version": "9.2.2-15", | ||
"main": "./cjs/index.js", | ||
@@ -693,6 +693,6 @@ "module": "./index.js", | ||
"@babel/runtime": "^7.18.0", | ||
"@polkadot/x-bigint": "9.2.2-14", | ||
"@polkadot/x-global": "9.2.2-14", | ||
"@polkadot/x-textdecoder": "9.2.2-14", | ||
"@polkadot/x-textencoder": "9.2.2-14", | ||
"@polkadot/x-bigint": "9.2.2-15", | ||
"@polkadot/x-global": "9.2.2-15", | ||
"@polkadot/x-textdecoder": "9.2.2-15", | ||
"@polkadot/x-textencoder": "9.2.2-15", | ||
"@types/bn.js": "^5.1.0", | ||
@@ -699,0 +699,0 @@ "bn.js": "^5.2.0", |
@@ -8,3 +8,3 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
type: 'esm', | ||
version: '9.2.2-14' | ||
version: '9.2.2-15' | ||
}; |
@@ -19,6 +19,1 @@ import type { HexString } from '../types'; | ||
export declare function u8aCmp(a: HexString | Uint8Array | string, b: HexString | Uint8Array | string): number; | ||
/** | ||
* @name u8aCmpStrict | ||
* @description A strict version of [[u8aCmp]], accepting only Uint8Array inputs | ||
*/ | ||
export declare function u8aCmpStrict(u8aa: Uint8Array, u8ab: Uint8Array): number; |
@@ -22,10 +22,4 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
export function u8aCmp(a, b) { | ||
return u8aCmpStrict(u8aToU8a(a), u8aToU8a(b)); | ||
} | ||
/** | ||
* @name u8aCmpStrict | ||
* @description A strict version of [[u8aCmp]], accepting only Uint8Array inputs | ||
*/ | ||
export function u8aCmpStrict(u8aa, u8ab) { | ||
const u8aa = u8aToU8a(a); | ||
const u8ab = u8aToU8a(b); | ||
let i = 0; | ||
@@ -32,0 +26,0 @@ |
@@ -17,6 +17,1 @@ import type { HexString } from '../types'; | ||
export declare function u8aEq(a: HexString | Uint8Array | string, b: HexString | Uint8Array | string): boolean; | ||
/** | ||
* @name u8aEqStrict | ||
* @description A strict version of [[u8aCmp]], accepting only Uint8Array inputs | ||
*/ | ||
export declare function u8aEqStrict(u8aa: Uint8Array, u8ab: Uint8Array): boolean; |
@@ -20,10 +20,5 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
export function u8aEq(a, b) { | ||
return u8aEqStrict(u8aToU8a(a), u8aToU8a(b)); | ||
} | ||
/** | ||
* @name u8aEqStrict | ||
* @description A strict version of [[u8aCmp]], accepting only Uint8Array inputs | ||
*/ | ||
const u8aa = u8aToU8a(a); | ||
const u8ab = u8aToU8a(b); | ||
export function u8aEqStrict(u8aa, u8ab) { | ||
if (u8aa.length === u8ab.length) { | ||
@@ -30,0 +25,0 @@ const dvA = new DataView(u8aa.buffer, u8aa.byteOffset); |
/** | ||
* @summary Utility methods to convert to and from `Uint8Array` objects | ||
*/ | ||
export { u8aCmp, u8aCmpStrict } from './cmp'; | ||
export { u8aCmp } from './cmp'; | ||
export { u8aConcat, u8aConcatStrict } from './concat'; | ||
export { u8aEmpty } from './empty'; | ||
export { u8aEq, u8aEqStrict } from './eq'; | ||
export { u8aEq } from './eq'; | ||
export { u8aFixLength } from './fixLength'; | ||
@@ -9,0 +9,0 @@ export { u8aSorted } from './sorted'; |
@@ -7,6 +7,6 @@ // Copyright 2017-2022 @polkadot/util authors & contributors | ||
*/ | ||
export { u8aCmp, u8aCmpStrict } from "./cmp.js"; | ||
export { u8aCmp } from "./cmp.js"; | ||
export { u8aConcat, u8aConcatStrict } from "./concat.js"; | ||
export { u8aEmpty } from "./empty.js"; | ||
export { u8aEq, u8aEqStrict } from "./eq.js"; | ||
export { u8aEq } from "./eq.js"; | ||
export { u8aFixLength } from "./fixLength.js"; | ||
@@ -13,0 +13,0 @@ export { u8aSorted } from "./sorted.js"; |
Sorry, the diff of this file is too big to display
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
502794
14436
+ Added@polkadot/x-bigint@9.2.2-15(transitive)
+ Added@polkadot/x-global@9.2.2-15(transitive)
+ Added@polkadot/x-textdecoder@9.2.2-15(transitive)
+ Added@polkadot/x-textencoder@9.2.2-15(transitive)
- Removed@polkadot/x-bigint@9.2.2-14(transitive)
- Removed@polkadot/x-global@9.2.2-14(transitive)
- Removed@polkadot/x-textdecoder@9.2.2-14(transitive)
- Removed@polkadot/x-textencoder@9.2.2-14(transitive)
Updated@polkadot/x-bigint@9.2.2-15
Updated@polkadot/x-global@9.2.2-15