mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-06-21 07:31:03 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
Vendored
+90
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* @name _0n
|
||||
* @summary BigInt constant for 0.
|
||||
*/
|
||||
export declare const _0n: bigint;
|
||||
/**
|
||||
* @name _1n
|
||||
* @summary BigInt constant for 1.
|
||||
*/
|
||||
export declare const _1n: bigint;
|
||||
/**
|
||||
* @name _2n
|
||||
* @summary BigInt constant for 2.
|
||||
*/
|
||||
export declare const _2n: bigint;
|
||||
/**
|
||||
* @name _3n
|
||||
* @summary BigInt constant for 3.
|
||||
*/
|
||||
export declare const _3n: bigint;
|
||||
/**
|
||||
* @name _4n
|
||||
* @summary BigInt constant for 4.
|
||||
*/
|
||||
export declare const _4n: bigint;
|
||||
/**
|
||||
* @name _5n
|
||||
* @summary BigInt constant for 5.
|
||||
*/
|
||||
export declare const _5n: bigint;
|
||||
/**
|
||||
* @name _6n
|
||||
* @summary BigInt constant for 6.
|
||||
*/
|
||||
export declare const _6n: bigint;
|
||||
/**
|
||||
* @name _7n
|
||||
* @summary BigInt constant for 7.
|
||||
*/
|
||||
export declare const _7n: bigint;
|
||||
/**
|
||||
* @name _8n
|
||||
* @summary BigInt constant for 8.
|
||||
*/
|
||||
export declare const _8n: bigint;
|
||||
/**
|
||||
* @name _9n
|
||||
* @summary BigInt constant for 9.
|
||||
*/
|
||||
export declare const _9n: bigint;
|
||||
/**
|
||||
* @name _10n
|
||||
* @summary BigInt constant for 10.
|
||||
*/
|
||||
export declare const _10n: bigint;
|
||||
/**
|
||||
* @name _100n
|
||||
* @summary BigInt constant for 100.
|
||||
*/
|
||||
export declare const _100n: bigint;
|
||||
/**
|
||||
* @name _1000n
|
||||
* @summary BigInt constant for 1000.
|
||||
*/
|
||||
export declare const _1000n: bigint;
|
||||
/**
|
||||
* @name _1Mn
|
||||
* @summary BigInt constant for 1,000,000 (million).
|
||||
*/
|
||||
export declare const _1Mn: bigint;
|
||||
/**
|
||||
* @name _1Bn
|
||||
* @summary BigInt constant for 1,000,000,000 (billion).
|
||||
*/
|
||||
export declare const _1Bn: bigint;
|
||||
/**
|
||||
* @name _1Qn
|
||||
* @summary BigInt constant for 1,000,000,000,000,000,000 (quitillion).
|
||||
*/
|
||||
export declare const _1Qn: bigint;
|
||||
/**
|
||||
* @name _2pow53n
|
||||
* @summary BigInt constant for MAX_SAFE_INTEGER
|
||||
*/
|
||||
export declare const _2pow53n: bigint;
|
||||
/**
|
||||
* @name _sqrt2pow53n
|
||||
* @summary BigInt constant for Math.sqrt(MAX_SAFE_INTEGER)
|
||||
*/
|
||||
export declare const _sqrt2pow53n: bigint;
|
||||
@@ -0,0 +1,94 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports._sqrt2pow53n = exports._2pow53n = exports._1Qn = exports._1Bn = exports._1Mn = exports._1000n = exports._100n = exports._10n = exports._9n = exports._8n = exports._7n = exports._6n = exports._5n = exports._4n = exports._3n = exports._2n = exports._1n = exports._0n = void 0;
|
||||
const x_bigint_1 = require("@pezkuwi/x-bigint");
|
||||
/**
|
||||
* @name _0n
|
||||
* @summary BigInt constant for 0.
|
||||
*/
|
||||
exports._0n = (0, x_bigint_1.BigInt)(0);
|
||||
/**
|
||||
* @name _1n
|
||||
* @summary BigInt constant for 1.
|
||||
*/
|
||||
exports._1n = (0, x_bigint_1.BigInt)(1);
|
||||
/**
|
||||
* @name _2n
|
||||
* @summary BigInt constant for 2.
|
||||
*/
|
||||
exports._2n = (0, x_bigint_1.BigInt)(2);
|
||||
/**
|
||||
* @name _3n
|
||||
* @summary BigInt constant for 3.
|
||||
*/
|
||||
exports._3n = (0, x_bigint_1.BigInt)(3);
|
||||
/**
|
||||
* @name _4n
|
||||
* @summary BigInt constant for 4.
|
||||
*/
|
||||
exports._4n = (0, x_bigint_1.BigInt)(4);
|
||||
/**
|
||||
* @name _5n
|
||||
* @summary BigInt constant for 5.
|
||||
*/
|
||||
exports._5n = (0, x_bigint_1.BigInt)(5);
|
||||
/**
|
||||
* @name _6n
|
||||
* @summary BigInt constant for 6.
|
||||
*/
|
||||
exports._6n = (0, x_bigint_1.BigInt)(6);
|
||||
/**
|
||||
* @name _7n
|
||||
* @summary BigInt constant for 7.
|
||||
*/
|
||||
exports._7n = (0, x_bigint_1.BigInt)(7);
|
||||
/**
|
||||
* @name _8n
|
||||
* @summary BigInt constant for 8.
|
||||
*/
|
||||
exports._8n = (0, x_bigint_1.BigInt)(8);
|
||||
/**
|
||||
* @name _9n
|
||||
* @summary BigInt constant for 9.
|
||||
*/
|
||||
exports._9n = (0, x_bigint_1.BigInt)(9);
|
||||
/**
|
||||
* @name _10n
|
||||
* @summary BigInt constant for 10.
|
||||
*/
|
||||
exports._10n = (0, x_bigint_1.BigInt)(10);
|
||||
/**
|
||||
* @name _100n
|
||||
* @summary BigInt constant for 100.
|
||||
*/
|
||||
exports._100n = (0, x_bigint_1.BigInt)(100);
|
||||
/**
|
||||
* @name _1000n
|
||||
* @summary BigInt constant for 1000.
|
||||
*/
|
||||
exports._1000n = (0, x_bigint_1.BigInt)(1_000);
|
||||
/**
|
||||
* @name _1Mn
|
||||
* @summary BigInt constant for 1,000,000 (million).
|
||||
*/
|
||||
exports._1Mn = (0, x_bigint_1.BigInt)(1_000_000);
|
||||
/**
|
||||
* @name _1Bn
|
||||
* @summary BigInt constant for 1,000,000,000 (billion).
|
||||
*/
|
||||
exports._1Bn = (0, x_bigint_1.BigInt)(1_000_000_000);
|
||||
/**
|
||||
* @name _1Qn
|
||||
* @summary BigInt constant for 1,000,000,000,000,000,000 (quitillion).
|
||||
*/
|
||||
exports._1Qn = exports._1Bn * exports._1Bn;
|
||||
/**
|
||||
* @name _2pow53n
|
||||
* @summary BigInt constant for MAX_SAFE_INTEGER
|
||||
*/
|
||||
exports._2pow53n = (0, x_bigint_1.BigInt)(Number.MAX_SAFE_INTEGER);
|
||||
/**
|
||||
* @name _sqrt2pow53n
|
||||
* @summary BigInt constant for Math.sqrt(MAX_SAFE_INTEGER)
|
||||
*/
|
||||
exports._sqrt2pow53n = (0, x_bigint_1.BigInt)(94906265);
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
/** @internal */
|
||||
export declare function createCmp<T>(cmp: (a: T, b: T) => boolean): (...items: T[]) => T;
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createCmp = createCmp;
|
||||
/** @internal */
|
||||
function createCmp(cmp) {
|
||||
return (...items) => {
|
||||
const count = items.length;
|
||||
if (count === 0) {
|
||||
throw new Error('Must provide one or more arguments');
|
||||
}
|
||||
let result = items[0];
|
||||
for (let i = 1; i < count; i++) {
|
||||
if (cmp(items[i], result)) {
|
||||
result = items[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @summary Utility methods to convert to and from `bigint` objects
|
||||
*/
|
||||
export { nMax, nMin } from './min.js';
|
||||
export { nSqrt } from './sqrt.js';
|
||||
export { nToBigInt } from './toBigInt.js';
|
||||
export { nToHex } from './toHex.js';
|
||||
export { nToU8a } from './toU8a.js';
|
||||
export * from './consts.js';
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.nToU8a = exports.nToHex = exports.nToBigInt = exports.nSqrt = exports.nMin = exports.nMax = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
/**
|
||||
* @summary Utility methods to convert to and from `bigint` objects
|
||||
*/
|
||||
var min_js_1 = require("./min.js");
|
||||
Object.defineProperty(exports, "nMax", { enumerable: true, get: function () { return min_js_1.nMax; } });
|
||||
Object.defineProperty(exports, "nMin", { enumerable: true, get: function () { return min_js_1.nMin; } });
|
||||
var sqrt_js_1 = require("./sqrt.js");
|
||||
Object.defineProperty(exports, "nSqrt", { enumerable: true, get: function () { return sqrt_js_1.nSqrt; } });
|
||||
var toBigInt_js_1 = require("./toBigInt.js");
|
||||
Object.defineProperty(exports, "nToBigInt", { enumerable: true, get: function () { return toBigInt_js_1.nToBigInt; } });
|
||||
var toHex_js_1 = require("./toHex.js");
|
||||
Object.defineProperty(exports, "nToHex", { enumerable: true, get: function () { return toHex_js_1.nToHex; } });
|
||||
var toU8a_js_1 = require("./toU8a.js");
|
||||
Object.defineProperty(exports, "nToU8a", { enumerable: true, get: function () { return toU8a_js_1.nToU8a; } });
|
||||
tslib_1.__exportStar(require("./consts.js"), exports);
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @name nMax
|
||||
* @summary Finds and returns the highest value in an array of bigint.
|
||||
*/
|
||||
export declare const nMax: (...items: bigint[]) => bigint;
|
||||
/**
|
||||
* @name nMin
|
||||
* @summary Finds and returns the lowest value in an array of bigint.
|
||||
*/
|
||||
export declare const nMin: (...items: bigint[]) => bigint;
|
||||
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.nMin = exports.nMax = void 0;
|
||||
const helpers_js_1 = require("./helpers.js");
|
||||
/**
|
||||
* @name nMax
|
||||
* @summary Finds and returns the highest value in an array of bigint.
|
||||
*/
|
||||
exports.nMax = (0, helpers_js_1.createCmp)((a, b) => a > b);
|
||||
/**
|
||||
* @name nMin
|
||||
* @summary Finds and returns the lowest value in an array of bigint.
|
||||
*/
|
||||
exports.nMin = (0, helpers_js_1.createCmp)((a, b) => a < b);
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import type { BN } from '../bn/index.js';
|
||||
import type { ToBigInt, ToBn } from '../types.js';
|
||||
/**
|
||||
* @name nSqrt
|
||||
* @summary Calculates the integer square root of a bigint
|
||||
*/
|
||||
export declare function nSqrt<ExtToBn extends ToBn | ToBigInt>(value: ExtToBn | BN | bigint | string | number | null): bigint;
|
||||
@@ -0,0 +1,32 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.nSqrt = nSqrt;
|
||||
const x_bigint_1 = require("@pezkuwi/x-bigint");
|
||||
const consts_js_1 = require("./consts.js");
|
||||
const toBigInt_js_1 = require("./toBigInt.js");
|
||||
/**
|
||||
* @name nSqrt
|
||||
* @summary Calculates the integer square root of a bigint
|
||||
*/
|
||||
function nSqrt(value) {
|
||||
const n = (0, toBigInt_js_1.nToBigInt)(value);
|
||||
if (n < consts_js_1._0n) {
|
||||
throw new Error('square root of negative numbers is not supported');
|
||||
}
|
||||
// https://stackoverflow.com/questions/53683995/javascript-big-integer-square-root/
|
||||
// shortcut <= 2^53 - 1 to use the JS utils
|
||||
if (n <= consts_js_1._2pow53n) {
|
||||
// ~~ is more performant that Math.floor
|
||||
return (0, x_bigint_1.BigInt)(~~Math.sqrt(Number(n)));
|
||||
}
|
||||
// Use sqrt(MAX_SAFE_INTEGER) as starting point. since we already know the
|
||||
// output will be larger than this, we expect this to be a safe start
|
||||
let x0 = consts_js_1._sqrt2pow53n;
|
||||
while (true) {
|
||||
const x1 = ((n / x0) + x0) >> consts_js_1._1n;
|
||||
if (x0 === x1 || (x0 === (x1 - consts_js_1._1n))) {
|
||||
return x0;
|
||||
}
|
||||
x0 = x1;
|
||||
}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import type { BN } from '../bn/bn.js';
|
||||
import type { ToBigInt, ToBn } from '../types.js';
|
||||
/**
|
||||
* @name nToBigInt
|
||||
* @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
|
||||
*/
|
||||
export declare function nToBigInt<ExtToBn extends ToBigInt | ToBn>(value?: ExtToBn | BN | bigint | string | number | null): bigint;
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.nToBigInt = nToBigInt;
|
||||
const x_bigint_1 = require("@pezkuwi/x-bigint");
|
||||
const toBigInt_js_1 = require("../hex/toBigInt.js");
|
||||
const bn_js_1 = require("../is/bn.js");
|
||||
const hex_js_1 = require("../is/hex.js");
|
||||
const toBigInt_js_2 = require("../is/toBigInt.js");
|
||||
const toBn_js_1 = require("../is/toBn.js");
|
||||
/**
|
||||
* @name nToBigInt
|
||||
* @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
|
||||
*/
|
||||
function nToBigInt(value) {
|
||||
return typeof value === 'bigint'
|
||||
? value
|
||||
: !value
|
||||
? (0, x_bigint_1.BigInt)(0)
|
||||
: (0, hex_js_1.isHex)(value)
|
||||
? (0, toBigInt_js_1.hexToBigInt)(value.toString())
|
||||
: (0, bn_js_1.isBn)(value)
|
||||
? (0, x_bigint_1.BigInt)(value.toString())
|
||||
: (0, toBigInt_js_2.isToBigInt)(value)
|
||||
? value.toBigInt()
|
||||
: (0, toBn_js_1.isToBn)(value)
|
||||
? (0, x_bigint_1.BigInt)(value.toBn().toString())
|
||||
: (0, x_bigint_1.BigInt)(value);
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import type { BN } from '../bn/bn.js';
|
||||
import type { HexString, NumberOptions, ToBigInt, ToBn } from '../types.js';
|
||||
/**
|
||||
* @name nToHex
|
||||
* @summary Creates a hex value from a bigint object.
|
||||
*/
|
||||
export declare function nToHex<ExtToBn extends ToBn | ToBigInt>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): HexString;
|
||||
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.nToHex = nToHex;
|
||||
const index_js_1 = require("../u8a/index.js");
|
||||
const toU8a_js_1 = require("./toU8a.js");
|
||||
/**
|
||||
* @name nToHex
|
||||
* @summary Creates a hex value from a bigint object.
|
||||
*/
|
||||
function nToHex(value, { bitLength = -1, isLe = false, isNegative = false } = {}) {
|
||||
return (0, index_js_1.u8aToHex)((0, toU8a_js_1.nToU8a)(value || 0, { bitLength, isLe, isNegative }));
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
import type { BN } from '../bn/bn.js';
|
||||
import type { NumberOptions, ToBigInt, ToBn } from '../types.js';
|
||||
/**
|
||||
* @name nToU8a
|
||||
* @summary Creates a Uint8Array object from a bigint.
|
||||
*/
|
||||
export declare function nToU8a<ExtToBn extends ToBn | ToBigInt>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): Uint8Array;
|
||||
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.nToU8a = nToU8a;
|
||||
const x_bigint_1 = require("@pezkuwi/x-bigint");
|
||||
const consts_js_1 = require("./consts.js");
|
||||
const toBigInt_js_1 = require("./toBigInt.js");
|
||||
const DIV = (0, x_bigint_1.BigInt)(256);
|
||||
const NEG_MASK = (0, x_bigint_1.BigInt)(0xff);
|
||||
function toU8a(value, isLe, isNegative) {
|
||||
const arr = [];
|
||||
const withSigned = isNegative && (value < consts_js_1._0n);
|
||||
if (withSigned) {
|
||||
value = (value + consts_js_1._1n) * -consts_js_1._1n;
|
||||
}
|
||||
while (value !== consts_js_1._0n) {
|
||||
const mod = value % DIV;
|
||||
const val = Number(withSigned
|
||||
? mod ^ NEG_MASK
|
||||
: mod);
|
||||
if (isLe) {
|
||||
arr.push(val);
|
||||
}
|
||||
else {
|
||||
arr.unshift(val);
|
||||
}
|
||||
value = (value - mod) / DIV;
|
||||
}
|
||||
return Uint8Array.from(arr);
|
||||
}
|
||||
/**
|
||||
* @name nToU8a
|
||||
* @summary Creates a Uint8Array object from a bigint.
|
||||
*/
|
||||
function nToU8a(value, { bitLength = -1, isLe = true, isNegative = false } = {}) {
|
||||
const valueBi = (0, toBigInt_js_1.nToBigInt)(value);
|
||||
if (valueBi === consts_js_1._0n) {
|
||||
return bitLength === -1
|
||||
? new Uint8Array(1)
|
||||
: new Uint8Array(Math.ceil((bitLength || 0) / 8));
|
||||
}
|
||||
const u8a = toU8a(valueBi, isLe, isNegative);
|
||||
if (bitLength === -1) {
|
||||
return u8a;
|
||||
}
|
||||
const byteLength = Math.ceil((bitLength || 0) / 8);
|
||||
const output = new Uint8Array(byteLength);
|
||||
if (isNegative) {
|
||||
output.fill(0xff);
|
||||
}
|
||||
output.set(u8a, isLe ? 0 : byteLength - u8a.length);
|
||||
return output;
|
||||
}
|
||||
Reference in New Issue
Block a user