mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 02:07:56 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name arrayChunk
|
||||
* @summary Split T[] into T[][] based on the defind size
|
||||
* @description
|
||||
* Returns a set ao arrays based on the chunksize
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayChunk } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
|
||||
* ```
|
||||
*/
|
||||
export declare function arrayChunk<T>(array: T[], chunkSize: number): T[][];
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @name arrayChunk
|
||||
* @summary Split T[] into T[][] based on the defind size
|
||||
* @description
|
||||
* Returns a set ao arrays based on the chunksize
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayChunk } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
|
||||
* ```
|
||||
*/
|
||||
export function arrayChunk(array, chunkSize) {
|
||||
const outputSize = Math.ceil(array.length / chunkSize);
|
||||
// shortcut for the single-split case
|
||||
if (outputSize === 1) {
|
||||
return [array];
|
||||
}
|
||||
const output = Array(outputSize);
|
||||
for (let i = 0; i < outputSize; i++) {
|
||||
const offset = i * chunkSize;
|
||||
output[i] = array.slice(offset, offset + chunkSize);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @name arrayFilter
|
||||
* @summary Filters undefined and (optionally) null values from an array
|
||||
* @description
|
||||
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayFilter } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
|
||||
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
|
||||
* ```
|
||||
*/
|
||||
export declare function arrayFilter<T = unknown>(array: readonly (T | null | undefined)[], allowNulls?: boolean): T[];
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @name arrayFilter
|
||||
* @summary Filters undefined and (optionally) null values from an array
|
||||
* @description
|
||||
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayFilter } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
|
||||
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
|
||||
* ```
|
||||
*/
|
||||
export function arrayFilter(array, allowNulls = true) {
|
||||
return array.filter((v) => v !== undefined &&
|
||||
(allowNulls || v !== null));
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name arrayFlatten
|
||||
* @summary Merge T[][] into T[]
|
||||
* @description
|
||||
* Returns a new array with all arrays merged into one
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayFlatten } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
|
||||
* ```
|
||||
*/
|
||||
export declare function arrayFlatten<T>(arrays: readonly T[][]): T[];
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @name arrayFlatten
|
||||
* @summary Merge T[][] into T[]
|
||||
* @description
|
||||
* Returns a new array with all arrays merged into one
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayFlatten } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
|
||||
* ```
|
||||
*/
|
||||
export function arrayFlatten(arrays) {
|
||||
const num = arrays.length;
|
||||
// shortcuts for the empty & single-entry case
|
||||
if (num === 0) {
|
||||
return [];
|
||||
}
|
||||
else if (num === 1) {
|
||||
return arrays[0];
|
||||
}
|
||||
// pre-allocate based on the combined size
|
||||
let size = 0;
|
||||
for (let i = 0; i < num; i++) {
|
||||
size += arrays[i].length;
|
||||
}
|
||||
const output = new Array(size);
|
||||
let i = -1;
|
||||
for (let j = 0; j < num; j++) {
|
||||
const a = arrays[j];
|
||||
// instead of pushing, we just set the entries
|
||||
for (let e = 0, count = a.length; e < count; e++) {
|
||||
output[++i] = a[e];
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @summary Utility methods that operates on arrays
|
||||
*/
|
||||
export { arrayChunk } from './chunk.js';
|
||||
export { arrayFilter } from './filter.js';
|
||||
export { arrayFlatten } from './flatten.js';
|
||||
export { arrayRange } from './range.js';
|
||||
export { arrayShuffle } from './shuffle.js';
|
||||
export { arrayUnzip } from './unzip.js';
|
||||
export { arrayZip } from './zip.js';
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @summary Utility methods that operates on arrays
|
||||
*/
|
||||
export { arrayChunk } from './chunk.js';
|
||||
export { arrayFilter } from './filter.js';
|
||||
export { arrayFlatten } from './flatten.js';
|
||||
export { arrayRange } from './range.js';
|
||||
export { arrayShuffle } from './shuffle.js';
|
||||
export { arrayUnzip } from './unzip.js';
|
||||
export { arrayZip } from './zip.js';
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @name arrayRange
|
||||
* @summary Returns a range of numbers ith the size and the specified offset
|
||||
* @description
|
||||
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayRange } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayRange(5); // [0, 1, 2, 3, 4]
|
||||
* arrayRange(3, 5); // [5, 6, 7]
|
||||
* ```
|
||||
*/
|
||||
export declare function arrayRange(size: number, startAt?: number): number[];
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @name arrayRange
|
||||
* @summary Returns a range of numbers ith the size and the specified offset
|
||||
* @description
|
||||
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayRange } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayRange(5); // [0, 1, 2, 3, 4]
|
||||
* arrayRange(3, 5); // [5, 6, 7]
|
||||
* ```
|
||||
*/
|
||||
export function arrayRange(size, startAt = 0) {
|
||||
if (size <= 0) {
|
||||
throw new Error('Expected non-zero, positive number as a range size');
|
||||
}
|
||||
const result = new Array(size);
|
||||
for (let i = 0; i < size; i++) {
|
||||
result[i] = i + startAt;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name arrayShuffle
|
||||
* @description Shuffles the input array (unlike sort, this is not done in-place)
|
||||
*/
|
||||
export declare function arrayShuffle<T>(input: readonly T[]): T[];
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @name arrayShuffle
|
||||
* @description Shuffles the input array (unlike sort, this is not done in-place)
|
||||
*/
|
||||
export function arrayShuffle(input) {
|
||||
const result = input.slice();
|
||||
let curr = result.length;
|
||||
// noop for the single entry
|
||||
if (curr === 1) {
|
||||
return result;
|
||||
}
|
||||
while (curr !== 0) {
|
||||
// ~~ is more performant than Math.floor
|
||||
const rand = ~~(Math.random() * curr);
|
||||
curr--;
|
||||
[result[curr], result[rand]] = [result[rand], result[curr]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name arrayUnzip
|
||||
* @description Splits a single [K, V][] into [K[], V[]]
|
||||
*/
|
||||
export declare function arrayUnzip<K, V>(entries: readonly [K, V][]): [K[], V[]];
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @name arrayUnzip
|
||||
* @description Splits a single [K, V][] into [K[], V[]]
|
||||
*/
|
||||
export function arrayUnzip(entries) {
|
||||
const count = entries.length;
|
||||
const keys = new Array(count);
|
||||
const values = new Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
[keys[i], values[i]] = entries[i];
|
||||
}
|
||||
return [keys, values];
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name arrayZip
|
||||
* @description Combines 2 distinct key/value arrays into a single [K, V] array
|
||||
*/
|
||||
export declare function arrayZip<K, V>(keys: readonly K[], values: readonly V[]): [K, V][];
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @name arrayZip
|
||||
* @description Combines 2 distinct key/value arrays into a single [K, V] array
|
||||
*/
|
||||
export function arrayZip(keys, values) {
|
||||
const count = keys.length;
|
||||
const result = new Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
result[i] = [keys[i], values[i]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
type MessageFn = () => string;
|
||||
/**
|
||||
* @name assert
|
||||
* @summary Checks for a valid test, if not Error is thrown.
|
||||
* @description
|
||||
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const { assert } from '@pezkuwi/util';
|
||||
*
|
||||
* assert(true, 'True should be true'); // passes
|
||||
* assert(false, 'False should not be true'); // Error thrown
|
||||
* assert(false, () => 'message'); // Error with 'message'
|
||||
* ```
|
||||
*/
|
||||
export declare function assert(condition: unknown, message: string | MessageFn): asserts condition;
|
||||
/**
|
||||
* @name assertReturn
|
||||
* @description Returns when the value is not undefined/null, otherwise throws assertion error
|
||||
*/
|
||||
export declare function assertReturn<T>(value: T | undefined | null, message: string | MessageFn): T;
|
||||
/**
|
||||
* @name assertUnreachable
|
||||
* @description An assertion helper that ensures all codepaths are followed
|
||||
*/
|
||||
export declare function assertUnreachable(x: never): never;
|
||||
export {};
|
||||
@@ -0,0 +1,39 @@
|
||||
import { isFunction } from './is/function.js';
|
||||
/**
|
||||
* @name assert
|
||||
* @summary Checks for a valid test, if not Error is thrown.
|
||||
* @description
|
||||
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const { assert } from '@pezkuwi/util';
|
||||
*
|
||||
* assert(true, 'True should be true'); // passes
|
||||
* assert(false, 'False should not be true'); // Error thrown
|
||||
* assert(false, () => 'message'); // Error with 'message'
|
||||
* ```
|
||||
*/
|
||||
export function assert(condition, message) {
|
||||
if (!condition) {
|
||||
throw new Error(isFunction(message)
|
||||
? message()
|
||||
: message);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @name assertReturn
|
||||
* @description Returns when the value is not undefined/null, otherwise throws assertion error
|
||||
*/
|
||||
export function assertReturn(value, message) {
|
||||
assert(value !== undefined && value !== null, message);
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* @name assertUnreachable
|
||||
* @description An assertion helper that ensures all codepaths are followed
|
||||
*/
|
||||
export function assertUnreachable(x) {
|
||||
throw new Error(`This codepath should be unreachable. Unhandled input: ${x}`);
|
||||
}
|
||||
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,91 @@
|
||||
import { BigInt } from '@pezkuwi/x-bigint';
|
||||
/**
|
||||
* @name _0n
|
||||
* @summary BigInt constant for 0.
|
||||
*/
|
||||
export const _0n = /*#__PURE__*/ BigInt(0);
|
||||
/**
|
||||
* @name _1n
|
||||
* @summary BigInt constant for 1.
|
||||
*/
|
||||
export const _1n = /*#__PURE__*/ BigInt(1);
|
||||
/**
|
||||
* @name _2n
|
||||
* @summary BigInt constant for 2.
|
||||
*/
|
||||
export const _2n = /*#__PURE__*/ BigInt(2);
|
||||
/**
|
||||
* @name _3n
|
||||
* @summary BigInt constant for 3.
|
||||
*/
|
||||
export const _3n = /*#__PURE__*/ BigInt(3);
|
||||
/**
|
||||
* @name _4n
|
||||
* @summary BigInt constant for 4.
|
||||
*/
|
||||
export const _4n = /*#__PURE__*/ BigInt(4);
|
||||
/**
|
||||
* @name _5n
|
||||
* @summary BigInt constant for 5.
|
||||
*/
|
||||
export const _5n = /*#__PURE__*/ BigInt(5);
|
||||
/**
|
||||
* @name _6n
|
||||
* @summary BigInt constant for 6.
|
||||
*/
|
||||
export const _6n = /*#__PURE__*/ BigInt(6);
|
||||
/**
|
||||
* @name _7n
|
||||
* @summary BigInt constant for 7.
|
||||
*/
|
||||
export const _7n = /*#__PURE__*/ BigInt(7);
|
||||
/**
|
||||
* @name _8n
|
||||
* @summary BigInt constant for 8.
|
||||
*/
|
||||
export const _8n = /*#__PURE__*/ BigInt(8);
|
||||
/**
|
||||
* @name _9n
|
||||
* @summary BigInt constant for 9.
|
||||
*/
|
||||
export const _9n = /*#__PURE__*/ BigInt(9);
|
||||
/**
|
||||
* @name _10n
|
||||
* @summary BigInt constant for 10.
|
||||
*/
|
||||
export const _10n = /*#__PURE__*/ BigInt(10);
|
||||
/**
|
||||
* @name _100n
|
||||
* @summary BigInt constant for 100.
|
||||
*/
|
||||
export const _100n = /*#__PURE__*/ BigInt(100);
|
||||
/**
|
||||
* @name _1000n
|
||||
* @summary BigInt constant for 1000.
|
||||
*/
|
||||
export const _1000n = /*#__PURE__*/ BigInt(1_000);
|
||||
/**
|
||||
* @name _1Mn
|
||||
* @summary BigInt constant for 1,000,000 (million).
|
||||
*/
|
||||
export const _1Mn = /*#__PURE__*/ BigInt(1_000_000);
|
||||
/**
|
||||
* @name _1Bn
|
||||
* @summary BigInt constant for 1,000,000,000 (billion).
|
||||
*/
|
||||
export const _1Bn = /*#__PURE__*/ BigInt(1_000_000_000);
|
||||
/**
|
||||
* @name _1Qn
|
||||
* @summary BigInt constant for 1,000,000,000,000,000,000 (quitillion).
|
||||
*/
|
||||
export const _1Qn = _1Bn * _1Bn;
|
||||
/**
|
||||
* @name _2pow53n
|
||||
* @summary BigInt constant for MAX_SAFE_INTEGER
|
||||
*/
|
||||
export const _2pow53n = /*#__PURE__*/ BigInt(Number.MAX_SAFE_INTEGER);
|
||||
/**
|
||||
* @name _sqrt2pow53n
|
||||
* @summary BigInt constant for Math.sqrt(MAX_SAFE_INTEGER)
|
||||
*/
|
||||
export const _sqrt2pow53n = /*#__PURE__*/ 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,16 @@
|
||||
/** @internal */
|
||||
export 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,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';
|
||||
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,11 @@
|
||||
import { createCmp } from './helpers.js';
|
||||
/**
|
||||
* @name nMax
|
||||
* @summary Finds and returns the highest value in an array of bigint.
|
||||
*/
|
||||
export const nMax = /*#__PURE__*/ createCmp((a, b) => a > b);
|
||||
/**
|
||||
* @name nMin
|
||||
* @summary Finds and returns the lowest value in an array of bigint.
|
||||
*/
|
||||
export const nMin = /*#__PURE__*/ 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,29 @@
|
||||
import { BigInt } from '@pezkuwi/x-bigint';
|
||||
import { _0n, _1n, _2pow53n, _sqrt2pow53n } from './consts.js';
|
||||
import { nToBigInt } from './toBigInt.js';
|
||||
/**
|
||||
* @name nSqrt
|
||||
* @summary Calculates the integer square root of a bigint
|
||||
*/
|
||||
export function nSqrt(value) {
|
||||
const n = nToBigInt(value);
|
||||
if (n < _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 <= _2pow53n) {
|
||||
// ~~ is more performant that Math.floor
|
||||
return 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 = _sqrt2pow53n;
|
||||
while (true) {
|
||||
const x1 = ((n / x0) + x0) >> _1n;
|
||||
if (x0 === x1 || (x0 === (x1 - _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,25 @@
|
||||
import { BigInt } from '@pezkuwi/x-bigint';
|
||||
import { hexToBigInt } from '../hex/toBigInt.js';
|
||||
import { isBn } from '../is/bn.js';
|
||||
import { isHex } from '../is/hex.js';
|
||||
import { isToBigInt } from '../is/toBigInt.js';
|
||||
import { isToBn } from '../is/toBn.js';
|
||||
/**
|
||||
* @name nToBigInt
|
||||
* @summary Creates a bigInt value from a BN, bigint, string (base 10 or hex) or number input.
|
||||
*/
|
||||
export function nToBigInt(value) {
|
||||
return typeof value === 'bigint'
|
||||
? value
|
||||
: !value
|
||||
? BigInt(0)
|
||||
: isHex(value)
|
||||
? hexToBigInt(value.toString())
|
||||
: isBn(value)
|
||||
? BigInt(value.toString())
|
||||
: isToBigInt(value)
|
||||
? value.toBigInt()
|
||||
: isToBn(value)
|
||||
? BigInt(value.toBn().toString())
|
||||
: 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,9 @@
|
||||
import { u8aToHex } from '../u8a/index.js';
|
||||
import { nToU8a } from './toU8a.js';
|
||||
/**
|
||||
* @name nToHex
|
||||
* @summary Creates a hex value from a bigint object.
|
||||
*/
|
||||
export function nToHex(value, { bitLength = -1, isLe = false, isNegative = false } = {}) {
|
||||
return u8aToHex(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,49 @@
|
||||
import { BigInt } from '@pezkuwi/x-bigint';
|
||||
import { _0n, _1n } from './consts.js';
|
||||
import { nToBigInt } from './toBigInt.js';
|
||||
const DIV = BigInt(256);
|
||||
const NEG_MASK = BigInt(0xff);
|
||||
function toU8a(value, isLe, isNegative) {
|
||||
const arr = [];
|
||||
const withSigned = isNegative && (value < _0n);
|
||||
if (withSigned) {
|
||||
value = (value + _1n) * -_1n;
|
||||
}
|
||||
while (value !== _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.
|
||||
*/
|
||||
export function nToU8a(value, { bitLength = -1, isLe = true, isNegative = false } = {}) {
|
||||
const valueBi = nToBigInt(value);
|
||||
if (valueBi === _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;
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import BN from 'bn.js';
|
||||
export { BN };
|
||||
@@ -0,0 +1,2 @@
|
||||
import BN from 'bn.js';
|
||||
export { BN };
|
||||
Vendored
+91
@@ -0,0 +1,91 @@
|
||||
import { BN } from './bn.js';
|
||||
/**
|
||||
* @name BN_ZERO
|
||||
* @summary BN constant for 0.
|
||||
*/
|
||||
export declare const BN_ZERO: BN;
|
||||
/**
|
||||
* @name BN_ONE
|
||||
* @summary BN constant for 1.
|
||||
*/
|
||||
export declare const BN_ONE: BN;
|
||||
/**
|
||||
* @name BN_TWO
|
||||
* @summary BN constant for 2.
|
||||
*/
|
||||
export declare const BN_TWO: BN;
|
||||
/**
|
||||
* @name BN_THREE
|
||||
* @summary BN constant for 3.
|
||||
*/
|
||||
export declare const BN_THREE: BN;
|
||||
/**
|
||||
* @name BN_FOUR
|
||||
* @summary BN constant for 4.
|
||||
*/
|
||||
export declare const BN_FOUR: BN;
|
||||
/**
|
||||
* @name BN_FIVE
|
||||
* @summary BN constant for 5.
|
||||
*/
|
||||
export declare const BN_FIVE: BN;
|
||||
/**
|
||||
* @name BN_SIX
|
||||
* @summary BN constant for 6.
|
||||
*/
|
||||
export declare const BN_SIX: BN;
|
||||
/**
|
||||
* @name BN_SEVEN
|
||||
* @summary BN constant for 7.
|
||||
*/
|
||||
export declare const BN_SEVEN: BN;
|
||||
/**
|
||||
* @name BN_EIGHT
|
||||
* @summary BN constant for 8.
|
||||
*/
|
||||
export declare const BN_EIGHT: BN;
|
||||
/**
|
||||
* @name BN_NINE
|
||||
* @summary BN constant for 9.
|
||||
*/
|
||||
export declare const BN_NINE: BN;
|
||||
/**
|
||||
* @name BN_TEN
|
||||
* @summary BN constant for 10.
|
||||
*/
|
||||
export declare const BN_TEN: BN;
|
||||
/**
|
||||
* @name BN_HUNDRED
|
||||
* @summary BN constant for 100.
|
||||
*/
|
||||
export declare const BN_HUNDRED: BN;
|
||||
/**
|
||||
* @name BN_THOUSAND
|
||||
* @summary BN constant for 1,000.
|
||||
*/
|
||||
export declare const BN_THOUSAND: BN;
|
||||
/**
|
||||
* @name BN_MILLION
|
||||
* @summary BN constant for 1,000,000.
|
||||
*/
|
||||
export declare const BN_MILLION: BN;
|
||||
/**
|
||||
* @name BN_BILLION
|
||||
* @summary BN constant for 1,000,000,000.
|
||||
*/
|
||||
export declare const BN_BILLION: BN;
|
||||
/**
|
||||
* @name BN_QUINTILL
|
||||
* @summary BN constant for 1,000,000,000,000,000,000.
|
||||
*/
|
||||
export declare const BN_QUINTILL: BN;
|
||||
/**
|
||||
* @name BN_MAX_INTEGER
|
||||
* @summary BN constant for MAX_SAFE_INTEGER
|
||||
*/
|
||||
export declare const BN_MAX_INTEGER: BN;
|
||||
/**
|
||||
* @name BN_SQRT_MAX_INTEGER
|
||||
* @summary BN constant for Math.sqrt(MAX_SAFE_INTEGER)
|
||||
*/
|
||||
export declare const BN_SQRT_MAX_INTEGER: BN;
|
||||
@@ -0,0 +1,91 @@
|
||||
import { BN } from './bn.js';
|
||||
/**
|
||||
* @name BN_ZERO
|
||||
* @summary BN constant for 0.
|
||||
*/
|
||||
export const BN_ZERO = /*#__PURE__*/ new BN(0);
|
||||
/**
|
||||
* @name BN_ONE
|
||||
* @summary BN constant for 1.
|
||||
*/
|
||||
export const BN_ONE = /*#__PURE__*/ new BN(1);
|
||||
/**
|
||||
* @name BN_TWO
|
||||
* @summary BN constant for 2.
|
||||
*/
|
||||
export const BN_TWO = /*#__PURE__*/ new BN(2);
|
||||
/**
|
||||
* @name BN_THREE
|
||||
* @summary BN constant for 3.
|
||||
*/
|
||||
export const BN_THREE = /*#__PURE__*/ new BN(3);
|
||||
/**
|
||||
* @name BN_FOUR
|
||||
* @summary BN constant for 4.
|
||||
*/
|
||||
export const BN_FOUR = /*#__PURE__*/ new BN(4);
|
||||
/**
|
||||
* @name BN_FIVE
|
||||
* @summary BN constant for 5.
|
||||
*/
|
||||
export const BN_FIVE = /*#__PURE__*/ new BN(5);
|
||||
/**
|
||||
* @name BN_SIX
|
||||
* @summary BN constant for 6.
|
||||
*/
|
||||
export const BN_SIX = /*#__PURE__*/ new BN(6);
|
||||
/**
|
||||
* @name BN_SEVEN
|
||||
* @summary BN constant for 7.
|
||||
*/
|
||||
export const BN_SEVEN = /*#__PURE__*/ new BN(7);
|
||||
/**
|
||||
* @name BN_EIGHT
|
||||
* @summary BN constant for 8.
|
||||
*/
|
||||
export const BN_EIGHT = /*#__PURE__*/ new BN(8);
|
||||
/**
|
||||
* @name BN_NINE
|
||||
* @summary BN constant for 9.
|
||||
*/
|
||||
export const BN_NINE = /*#__PURE__*/ new BN(9);
|
||||
/**
|
||||
* @name BN_TEN
|
||||
* @summary BN constant for 10.
|
||||
*/
|
||||
export const BN_TEN = /*#__PURE__*/ new BN(10);
|
||||
/**
|
||||
* @name BN_HUNDRED
|
||||
* @summary BN constant for 100.
|
||||
*/
|
||||
export const BN_HUNDRED = /*#__PURE__*/ new BN(100);
|
||||
/**
|
||||
* @name BN_THOUSAND
|
||||
* @summary BN constant for 1,000.
|
||||
*/
|
||||
export const BN_THOUSAND = /*#__PURE__*/ new BN(1_000);
|
||||
/**
|
||||
* @name BN_MILLION
|
||||
* @summary BN constant for 1,000,000.
|
||||
*/
|
||||
export const BN_MILLION = /*#__PURE__*/ new BN(1_000_000);
|
||||
/**
|
||||
* @name BN_BILLION
|
||||
* @summary BN constant for 1,000,000,000.
|
||||
*/
|
||||
export const BN_BILLION = /*#__PURE__*/ new BN(1_000_000_000);
|
||||
/**
|
||||
* @name BN_QUINTILL
|
||||
* @summary BN constant for 1,000,000,000,000,000,000.
|
||||
*/
|
||||
export const BN_QUINTILL = BN_BILLION.mul(BN_BILLION);
|
||||
/**
|
||||
* @name BN_MAX_INTEGER
|
||||
* @summary BN constant for MAX_SAFE_INTEGER
|
||||
*/
|
||||
export const BN_MAX_INTEGER = /*#__PURE__*/ new BN(Number.MAX_SAFE_INTEGER);
|
||||
/**
|
||||
* @name BN_SQRT_MAX_INTEGER
|
||||
* @summary BN constant for Math.sqrt(MAX_SAFE_INTEGER)
|
||||
*/
|
||||
export const BN_SQRT_MAX_INTEGER = /*#__PURE__*/ new BN(94906265);
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export { hexToBn as bnFromHex } from '../hex/toBn.js';
|
||||
@@ -0,0 +1 @@
|
||||
export { hexToBn as bnFromHex } from '../hex/toBn.js';
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @summary Utility methods to convert to and from `BN` objects
|
||||
*/
|
||||
export { BN } from './bn.js';
|
||||
export { bnFromHex } from './fromHex.js';
|
||||
export { bnMax, bnMin } from './min.js';
|
||||
export { bnSqrt } from './sqrt.js';
|
||||
export { bnToBn } from './toBn.js';
|
||||
export { bnToHex } from './toHex.js';
|
||||
export { bnToU8a } from './toU8a.js';
|
||||
export * from './consts.js';
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @summary Utility methods to convert to and from `BN` objects
|
||||
*/
|
||||
export { BN } from './bn.js';
|
||||
export { bnFromHex } from './fromHex.js';
|
||||
export { bnMax, bnMin } from './min.js';
|
||||
export { bnSqrt } from './sqrt.js';
|
||||
export { bnToBn } from './toBn.js';
|
||||
export { bnToHex } from './toHex.js';
|
||||
export { bnToU8a } from './toU8a.js';
|
||||
export * from './consts.js';
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
import type { BN } from './bn.js';
|
||||
/**
|
||||
* @name bnMax
|
||||
* @summary Finds and returns the highest value in an array of BNs.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnMax } from '@pezkuwi/util';
|
||||
*
|
||||
* bnMax([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
|
||||
* ```
|
||||
*/
|
||||
export declare const bnMax: (...items: BN[]) => BN;
|
||||
/**
|
||||
* @name bnMin
|
||||
* @summary Finds and returns the smallest value in an array of BNs.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnMin } from '@pezkuwi/util';
|
||||
*
|
||||
* bnMin([new BN(1), new BN(3), new BN(2)]).toString(); // => '1'
|
||||
* ```
|
||||
*/
|
||||
export declare const bnMin: (...items: BN[]) => BN;
|
||||
@@ -0,0 +1,29 @@
|
||||
import { createCmp } from '../bi/helpers.js';
|
||||
/**
|
||||
* @name bnMax
|
||||
* @summary Finds and returns the highest value in an array of BNs.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnMax } from '@pezkuwi/util';
|
||||
*
|
||||
* bnMax([new BN(1), new BN(3), new BN(2)]).toString(); // => '3'
|
||||
* ```
|
||||
*/
|
||||
export const bnMax = /*#__PURE__*/ createCmp((a, b) => a.gt(b));
|
||||
/**
|
||||
* @name bnMin
|
||||
* @summary Finds and returns the smallest value in an array of BNs.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnMin } from '@pezkuwi/util';
|
||||
*
|
||||
* bnMin([new BN(1), new BN(3), new BN(2)]).toString(); // => '1'
|
||||
* ```
|
||||
*/
|
||||
export const bnMin = /*#__PURE__*/ createCmp((a, b) => a.lt(b));
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
import type { ToBn } from '../types.js';
|
||||
import { BN } from './bn.js';
|
||||
/**
|
||||
* @name bnSqrt
|
||||
* @summary Calculates the integer square root of a BN
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnSqrt } from '@pezkuwi/util';
|
||||
*
|
||||
* bnSqrt(new BN(16)).toString(); // => '4'
|
||||
* ```
|
||||
*/
|
||||
export declare function bnSqrt<ExtToBn extends ToBn>(value: ExtToBn | BN | bigint | string | number | null): BN;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { BN } from './bn.js';
|
||||
import { BN_MAX_INTEGER, BN_ONE, BN_SQRT_MAX_INTEGER } from './consts.js';
|
||||
import { bnToBn } from './toBn.js';
|
||||
/**
|
||||
* @name bnSqrt
|
||||
* @summary Calculates the integer square root of a BN
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnSqrt } from '@pezkuwi/util';
|
||||
*
|
||||
* bnSqrt(new BN(16)).toString(); // => '4'
|
||||
* ```
|
||||
*/
|
||||
export function bnSqrt(value) {
|
||||
const n = bnToBn(value);
|
||||
if (n.isNeg()) {
|
||||
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.lte(BN_MAX_INTEGER)) {
|
||||
// ~~ More performant version of Math.floor
|
||||
return new BN(~~Math.sqrt(n.toNumber()));
|
||||
}
|
||||
// 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 = BN_SQRT_MAX_INTEGER.clone();
|
||||
while (true) {
|
||||
const x1 = n.div(x0).iadd(x0).ishrn(1);
|
||||
if (x0.eq(x1) || x0.eq(x1.sub(BN_ONE))) {
|
||||
return x0;
|
||||
}
|
||||
x0 = x1;
|
||||
}
|
||||
}
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
import type { ToBigInt, ToBn } from '../types.js';
|
||||
import { BN } from './bn.js';
|
||||
/**
|
||||
* @name bnToBn
|
||||
* @summary Creates a BN value from a BN, bigint, string (base 10 or hex) or number input.
|
||||
* @description
|
||||
* `null` inputs returns a `0x0` result, BN values returns the value, numbers returns a BN representation.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnToBn } from '@pezkuwi/util';
|
||||
*
|
||||
* bnToBn(0x1234); // => BN(0x1234)
|
||||
* bnToBn(new BN(0x1234)); // => BN(0x1234)
|
||||
* ```
|
||||
*/
|
||||
export declare function bnToBn<ExtToBn extends ToBigInt | ToBn>(value?: ExtToBn | BN | bigint | string | number | null): BN;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { hexToBn } from '../hex/toBn.js';
|
||||
import { isBigInt } from '../is/bigInt.js';
|
||||
import { isHex } from '../is/hex.js';
|
||||
import { isToBigInt } from '../is/toBigInt.js';
|
||||
import { isToBn } from '../is/toBn.js';
|
||||
import { BN } from './bn.js';
|
||||
/**
|
||||
* @name bnToBn
|
||||
* @summary Creates a BN value from a BN, bigint, string (base 10 or hex) or number input.
|
||||
* @description
|
||||
* `null` inputs returns a `0x0` result, BN values returns the value, numbers returns a BN representation.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnToBn } from '@pezkuwi/util';
|
||||
*
|
||||
* bnToBn(0x1234); // => BN(0x1234)
|
||||
* bnToBn(new BN(0x1234)); // => BN(0x1234)
|
||||
* ```
|
||||
*/
|
||||
export function bnToBn(value) {
|
||||
return value
|
||||
? BN.isBN(value)
|
||||
? value
|
||||
: isHex(value)
|
||||
? hexToBn(value.toString())
|
||||
: isBigInt(value)
|
||||
? new BN(value.toString())
|
||||
: isToBn(value)
|
||||
? value.toBn()
|
||||
: isToBigInt(value)
|
||||
? new BN(value.toBigInt().toString())
|
||||
: new BN(value)
|
||||
: new BN(0);
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
import type { HexString, NumberOptions, ToBn } from '../types.js';
|
||||
import type { BN } from './bn.js';
|
||||
/**
|
||||
* @name bnToHex
|
||||
* @summary Creates a hex value from a BN.js bignumber object.
|
||||
* @description
|
||||
* `null` inputs returns a `0x` result, BN values return the actual value as a `0x` prefixed hex value. Anything that is not a BN object throws an error. With `bitLength` set, it fixes the number to the specified length.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnToHex } from '@pezkuwi/util';
|
||||
*
|
||||
* bnToHex(new BN(0x123456)); // => '0x123456'
|
||||
* ```
|
||||
*/
|
||||
export declare function bnToHex<ExtToBn extends ToBn>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): HexString;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { u8aToHex } from '../u8a/index.js';
|
||||
import { bnToU8a } from './toU8a.js';
|
||||
/**
|
||||
* @name bnToHex
|
||||
* @summary Creates a hex value from a BN.js bignumber object.
|
||||
* @description
|
||||
* `null` inputs returns a `0x` result, BN values return the actual value as a `0x` prefixed hex value. Anything that is not a BN object throws an error. With `bitLength` set, it fixes the number to the specified length.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import BN from 'bn.js';
|
||||
* import { bnToHex } from '@pezkuwi/util';
|
||||
*
|
||||
* bnToHex(new BN(0x123456)); // => '0x123456'
|
||||
* ```
|
||||
*/
|
||||
export function bnToHex(value, { bitLength = -1, isLe = false, isNegative = false } = {}) {
|
||||
return u8aToHex(bnToU8a(value, { bitLength, isLe, isNegative }));
|
||||
}
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
import type { NumberOptions, ToBn } from '../types.js';
|
||||
import type { BN } from './bn.js';
|
||||
/**
|
||||
* @name bnToU8a
|
||||
* @summary Creates a Uint8Array object from a BN.
|
||||
* @description
|
||||
* `null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `BN` input values return the actual bytes value converted to a `Uint8Array`. Optionally convert using little-endian format if `isLE` is set.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { bnToU8a } from '@pezkuwi/util';
|
||||
*
|
||||
* bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
|
||||
* ```
|
||||
*/
|
||||
export declare function bnToU8a<ExtToBn extends ToBn>(value?: ExtToBn | BN | bigint | number | null, { bitLength, isLe, isNegative }?: NumberOptions): Uint8Array;
|
||||
@@ -0,0 +1,33 @@
|
||||
import { bnToBn } from './toBn.js';
|
||||
const DEFAULT_OPTS = { bitLength: -1, isLe: true, isNegative: false };
|
||||
/**
|
||||
* @name bnToU8a
|
||||
* @summary Creates a Uint8Array object from a BN.
|
||||
* @description
|
||||
* `null`/`undefined`/`NaN` inputs returns an empty `Uint8Array` result. `BN` input values return the actual bytes value converted to a `Uint8Array`. Optionally convert using little-endian format if `isLE` is set.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { bnToU8a } from '@pezkuwi/util';
|
||||
*
|
||||
* bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
|
||||
* ```
|
||||
*/
|
||||
export function bnToU8a(value, { bitLength = -1, isLe = true, isNegative = false } = DEFAULT_OPTS) {
|
||||
const valueBn = bnToBn(value);
|
||||
const byteLength = bitLength === -1
|
||||
? Math.ceil(valueBn.bitLength() / 8)
|
||||
: Math.ceil((bitLength || 0) / 8);
|
||||
if (!value) {
|
||||
return bitLength === -1
|
||||
? new Uint8Array(1)
|
||||
: new Uint8Array(byteLength);
|
||||
}
|
||||
const output = new Uint8Array(byteLength);
|
||||
const bn = isNegative
|
||||
? valueBn.toTwos(byteLength * 8)
|
||||
: valueBn;
|
||||
output.set(bn.toArray(isLe ? 'le' : 'be', byteLength), 0);
|
||||
return output;
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* @summary Utility methods to convert to and from `Buffer` objects
|
||||
*/
|
||||
export { bufferToU8a } from './toU8a.js';
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* @summary Utility methods to convert to and from `Buffer` objects
|
||||
*/
|
||||
export { bufferToU8a } from './toU8a.js';
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name bufferToU8a
|
||||
* @summary Creates a Uint8Array value from a Buffer object.
|
||||
* @description
|
||||
* `null` inputs returns an empty result, `Buffer` values return the actual value as a `Uint8Array`. Anything that is not a `Buffer` object throws an error.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { bufferToU8a } from '@pezkuwi/util';
|
||||
*
|
||||
* bufferToU8a(Buffer.from([1, 2, 3]));
|
||||
* ```
|
||||
*/
|
||||
export declare function bufferToU8a(buffer?: Uint8Array | number[] | null): Uint8Array;
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @name bufferToU8a
|
||||
* @summary Creates a Uint8Array value from a Buffer object.
|
||||
* @description
|
||||
* `null` inputs returns an empty result, `Buffer` values return the actual value as a `Uint8Array`. Anything that is not a `Buffer` object throws an error.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { bufferToU8a } from '@pezkuwi/util';
|
||||
*
|
||||
* bufferToU8a(Buffer.from([1, 2, 3]));
|
||||
* ```
|
||||
*/
|
||||
export function bufferToU8a(buffer) {
|
||||
return new Uint8Array(buffer || []);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @summary Utility methods for this package are split into groups
|
||||
*/
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
export * from './array/index.js';
|
||||
export * from './assert.js';
|
||||
export * from './bi/index.js';
|
||||
export * from './bn/index.js';
|
||||
export * from './buffer/index.js';
|
||||
export * from './compact/index.js';
|
||||
export * from './detectPackage.js';
|
||||
export * from './extractTime.js';
|
||||
export * from './float/index.js';
|
||||
export * from './format/index.js';
|
||||
export * from './has.js';
|
||||
export * from './hex/index.js';
|
||||
export * from './is/index.js';
|
||||
export * from './lazy.js';
|
||||
export * from './logger.js';
|
||||
export * from './memoize.js';
|
||||
export * from './nextTick.js';
|
||||
export * from './noop.js';
|
||||
export * from './number/index.js';
|
||||
export * from './object/index.js';
|
||||
export * from './promisify.js';
|
||||
export * from './string/index.js';
|
||||
export * from './stringify.js';
|
||||
export * from './u8a/index.js';
|
||||
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @summary Utility methods for this package are split into groups
|
||||
*/
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
export * from './array/index.js';
|
||||
export * from './assert.js';
|
||||
export * from './bi/index.js';
|
||||
export * from './bn/index.js';
|
||||
export * from './buffer/index.js';
|
||||
export * from './compact/index.js';
|
||||
export * from './detectPackage.js';
|
||||
export * from './extractTime.js';
|
||||
export * from './float/index.js';
|
||||
export * from './format/index.js';
|
||||
export * from './has.js';
|
||||
export * from './hex/index.js';
|
||||
export * from './is/index.js';
|
||||
export * from './lazy.js';
|
||||
export * from './logger.js';
|
||||
export * from './memoize.js';
|
||||
export * from './nextTick.js';
|
||||
export * from './noop.js';
|
||||
export * from './number/index.js';
|
||||
export * from './object/index.js';
|
||||
export * from './promisify.js';
|
||||
export * from './string/index.js';
|
||||
export * from './stringify.js';
|
||||
export * from './u8a/index.js';
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name arrayChunk
|
||||
* @summary Split T[] into T[][] based on the defind size
|
||||
* @description
|
||||
* Returns a set ao arrays based on the chunksize
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayChunk } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
|
||||
* ```
|
||||
*/
|
||||
export declare function arrayChunk<T>(array: T[], chunkSize: number): T[][];
|
||||
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.arrayChunk = arrayChunk;
|
||||
/**
|
||||
* @name arrayChunk
|
||||
* @summary Split T[] into T[][] based on the defind size
|
||||
* @description
|
||||
* Returns a set ao arrays based on the chunksize
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayChunk } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayChunk([1, 2, 3, 4, 5]); // [[1, 2], [3, 4], [5]]
|
||||
* ```
|
||||
*/
|
||||
function arrayChunk(array, chunkSize) {
|
||||
const outputSize = Math.ceil(array.length / chunkSize);
|
||||
// shortcut for the single-split case
|
||||
if (outputSize === 1) {
|
||||
return [array];
|
||||
}
|
||||
const output = Array(outputSize);
|
||||
for (let i = 0; i < outputSize; i++) {
|
||||
const offset = i * chunkSize;
|
||||
output[i] = array.slice(offset, offset + chunkSize);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @name arrayFilter
|
||||
* @summary Filters undefined and (optionally) null values from an array
|
||||
* @description
|
||||
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayFilter } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
|
||||
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
|
||||
* ```
|
||||
*/
|
||||
export declare function arrayFilter<T = unknown>(array: readonly (T | null | undefined)[], allowNulls?: boolean): T[];
|
||||
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.arrayFilter = arrayFilter;
|
||||
/**
|
||||
* @name arrayFilter
|
||||
* @summary Filters undefined and (optionally) null values from an array
|
||||
* @description
|
||||
* Returns a new array with all `undefined` values removed. Optionally, when `allowNulls = false`, it removes the `null` values as well
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayFilter } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayFilter([0, void 0, true, null, false, '']); // [0, true, null, false, '']
|
||||
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
|
||||
* ```
|
||||
*/
|
||||
function arrayFilter(array, allowNulls = true) {
|
||||
return array.filter((v) => v !== undefined &&
|
||||
(allowNulls || v !== null));
|
||||
}
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name arrayFlatten
|
||||
* @summary Merge T[][] into T[]
|
||||
* @description
|
||||
* Returns a new array with all arrays merged into one
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayFlatten } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
|
||||
* ```
|
||||
*/
|
||||
export declare function arrayFlatten<T>(arrays: readonly T[][]): T[];
|
||||
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.arrayFlatten = arrayFlatten;
|
||||
/**
|
||||
* @name arrayFlatten
|
||||
* @summary Merge T[][] into T[]
|
||||
* @description
|
||||
* Returns a new array with all arrays merged into one
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayFlatten } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
|
||||
* ```
|
||||
*/
|
||||
function arrayFlatten(arrays) {
|
||||
const num = arrays.length;
|
||||
// shortcuts for the empty & single-entry case
|
||||
if (num === 0) {
|
||||
return [];
|
||||
}
|
||||
else if (num === 1) {
|
||||
return arrays[0];
|
||||
}
|
||||
// pre-allocate based on the combined size
|
||||
let size = 0;
|
||||
for (let i = 0; i < num; i++) {
|
||||
size += arrays[i].length;
|
||||
}
|
||||
const output = new Array(size);
|
||||
let i = -1;
|
||||
for (let j = 0; j < num; j++) {
|
||||
const a = arrays[j];
|
||||
// instead of pushing, we just set the entries
|
||||
for (let e = 0, count = a.length; e < count; e++) {
|
||||
output[++i] = a[e];
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @summary Utility methods that operates on arrays
|
||||
*/
|
||||
export { arrayChunk } from './chunk.js';
|
||||
export { arrayFilter } from './filter.js';
|
||||
export { arrayFlatten } from './flatten.js';
|
||||
export { arrayRange } from './range.js';
|
||||
export { arrayShuffle } from './shuffle.js';
|
||||
export { arrayUnzip } from './unzip.js';
|
||||
export { arrayZip } from './zip.js';
|
||||
@@ -0,0 +1,20 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.arrayZip = exports.arrayUnzip = exports.arrayShuffle = exports.arrayRange = exports.arrayFlatten = exports.arrayFilter = exports.arrayChunk = void 0;
|
||||
/**
|
||||
* @summary Utility methods that operates on arrays
|
||||
*/
|
||||
var chunk_js_1 = require("./chunk.js");
|
||||
Object.defineProperty(exports, "arrayChunk", { enumerable: true, get: function () { return chunk_js_1.arrayChunk; } });
|
||||
var filter_js_1 = require("./filter.js");
|
||||
Object.defineProperty(exports, "arrayFilter", { enumerable: true, get: function () { return filter_js_1.arrayFilter; } });
|
||||
var flatten_js_1 = require("./flatten.js");
|
||||
Object.defineProperty(exports, "arrayFlatten", { enumerable: true, get: function () { return flatten_js_1.arrayFlatten; } });
|
||||
var range_js_1 = require("./range.js");
|
||||
Object.defineProperty(exports, "arrayRange", { enumerable: true, get: function () { return range_js_1.arrayRange; } });
|
||||
var shuffle_js_1 = require("./shuffle.js");
|
||||
Object.defineProperty(exports, "arrayShuffle", { enumerable: true, get: function () { return shuffle_js_1.arrayShuffle; } });
|
||||
var unzip_js_1 = require("./unzip.js");
|
||||
Object.defineProperty(exports, "arrayUnzip", { enumerable: true, get: function () { return unzip_js_1.arrayUnzip; } });
|
||||
var zip_js_1 = require("./zip.js");
|
||||
Object.defineProperty(exports, "arrayZip", { enumerable: true, get: function () { return zip_js_1.arrayZip; } });
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @name arrayRange
|
||||
* @summary Returns a range of numbers ith the size and the specified offset
|
||||
* @description
|
||||
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayRange } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayRange(5); // [0, 1, 2, 3, 4]
|
||||
* arrayRange(3, 5); // [5, 6, 7]
|
||||
* ```
|
||||
*/
|
||||
export declare function arrayRange(size: number, startAt?: number): number[];
|
||||
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.arrayRange = arrayRange;
|
||||
/**
|
||||
* @name arrayRange
|
||||
* @summary Returns a range of numbers ith the size and the specified offset
|
||||
* @description
|
||||
* Returns a new array of numbers with the specific size. Optionally, when `startAt`, is provided, it generates the range to start at a specific value.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { arrayRange } from '@pezkuwi/util';
|
||||
*
|
||||
* arrayRange(5); // [0, 1, 2, 3, 4]
|
||||
* arrayRange(3, 5); // [5, 6, 7]
|
||||
* ```
|
||||
*/
|
||||
function arrayRange(size, startAt = 0) {
|
||||
if (size <= 0) {
|
||||
throw new Error('Expected non-zero, positive number as a range size');
|
||||
}
|
||||
const result = new Array(size);
|
||||
for (let i = 0; i < size; i++) {
|
||||
result[i] = i + startAt;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name arrayShuffle
|
||||
* @description Shuffles the input array (unlike sort, this is not done in-place)
|
||||
*/
|
||||
export declare function arrayShuffle<T>(input: readonly T[]): T[];
|
||||
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.arrayShuffle = arrayShuffle;
|
||||
/**
|
||||
* @name arrayShuffle
|
||||
* @description Shuffles the input array (unlike sort, this is not done in-place)
|
||||
*/
|
||||
function arrayShuffle(input) {
|
||||
const result = input.slice();
|
||||
let curr = result.length;
|
||||
// noop for the single entry
|
||||
if (curr === 1) {
|
||||
return result;
|
||||
}
|
||||
while (curr !== 0) {
|
||||
// ~~ is more performant than Math.floor
|
||||
const rand = ~~(Math.random() * curr);
|
||||
curr--;
|
||||
[result[curr], result[rand]] = [result[rand], result[curr]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name arrayUnzip
|
||||
* @description Splits a single [K, V][] into [K[], V[]]
|
||||
*/
|
||||
export declare function arrayUnzip<K, V>(entries: readonly [K, V][]): [K[], V[]];
|
||||
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.arrayUnzip = arrayUnzip;
|
||||
/**
|
||||
* @name arrayUnzip
|
||||
* @description Splits a single [K, V][] into [K[], V[]]
|
||||
*/
|
||||
function arrayUnzip(entries) {
|
||||
const count = entries.length;
|
||||
const keys = new Array(count);
|
||||
const values = new Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
[keys[i], values[i]] = entries[i];
|
||||
}
|
||||
return [keys, values];
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* @name arrayZip
|
||||
* @description Combines 2 distinct key/value arrays into a single [K, V] array
|
||||
*/
|
||||
export declare function arrayZip<K, V>(keys: readonly K[], values: readonly V[]): [K, V][];
|
||||
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.arrayZip = arrayZip;
|
||||
/**
|
||||
* @name arrayZip
|
||||
* @description Combines 2 distinct key/value arrays into a single [K, V] array
|
||||
*/
|
||||
function arrayZip(keys, values) {
|
||||
const count = keys.length;
|
||||
const result = new Array(count);
|
||||
for (let i = 0; i < count; i++) {
|
||||
result[i] = [keys[i], values[i]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
type MessageFn = () => string;
|
||||
/**
|
||||
* @name assert
|
||||
* @summary Checks for a valid test, if not Error is thrown.
|
||||
* @description
|
||||
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const { assert } from '@pezkuwi/util';
|
||||
*
|
||||
* assert(true, 'True should be true'); // passes
|
||||
* assert(false, 'False should not be true'); // Error thrown
|
||||
* assert(false, () => 'message'); // Error with 'message'
|
||||
* ```
|
||||
*/
|
||||
export declare function assert(condition: unknown, message: string | MessageFn): asserts condition;
|
||||
/**
|
||||
* @name assertReturn
|
||||
* @description Returns when the value is not undefined/null, otherwise throws assertion error
|
||||
*/
|
||||
export declare function assertReturn<T>(value: T | undefined | null, message: string | MessageFn): T;
|
||||
/**
|
||||
* @name assertUnreachable
|
||||
* @description An assertion helper that ensures all codepaths are followed
|
||||
*/
|
||||
export declare function assertUnreachable(x: never): never;
|
||||
export {};
|
||||
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.assert = assert;
|
||||
exports.assertReturn = assertReturn;
|
||||
exports.assertUnreachable = assertUnreachable;
|
||||
const function_js_1 = require("./is/function.js");
|
||||
/**
|
||||
* @name assert
|
||||
* @summary Checks for a valid test, if not Error is thrown.
|
||||
* @description
|
||||
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an Error with the supplied `message`. When `test` passes, `true` is returned.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* const { assert } from '@pezkuwi/util';
|
||||
*
|
||||
* assert(true, 'True should be true'); // passes
|
||||
* assert(false, 'False should not be true'); // Error thrown
|
||||
* assert(false, () => 'message'); // Error with 'message'
|
||||
* ```
|
||||
*/
|
||||
function assert(condition, message) {
|
||||
if (!condition) {
|
||||
throw new Error((0, function_js_1.isFunction)(message)
|
||||
? message()
|
||||
: message);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @name assertReturn
|
||||
* @description Returns when the value is not undefined/null, otherwise throws assertion error
|
||||
*/
|
||||
function assertReturn(value, message) {
|
||||
assert(value !== undefined && value !== null, message);
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* @name assertUnreachable
|
||||
* @description An assertion helper that ensures all codepaths are followed
|
||||
*/
|
||||
function assertUnreachable(x) {
|
||||
throw new Error(`This codepath should be unreachable. Unhandled input: ${x}`);
|
||||
}
|
||||
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;
|
||||
}
|
||||
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
import BN from 'bn.js';
|
||||
export { BN };
|
||||
@@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BN = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
|
||||
exports.BN = bn_js_1.default;
|
||||
Vendored
+91
@@ -0,0 +1,91 @@
|
||||
import { BN } from './bn.js';
|
||||
/**
|
||||
* @name BN_ZERO
|
||||
* @summary BN constant for 0.
|
||||
*/
|
||||
export declare const BN_ZERO: BN;
|
||||
/**
|
||||
* @name BN_ONE
|
||||
* @summary BN constant for 1.
|
||||
*/
|
||||
export declare const BN_ONE: BN;
|
||||
/**
|
||||
* @name BN_TWO
|
||||
* @summary BN constant for 2.
|
||||
*/
|
||||
export declare const BN_TWO: BN;
|
||||
/**
|
||||
* @name BN_THREE
|
||||
* @summary BN constant for 3.
|
||||
*/
|
||||
export declare const BN_THREE: BN;
|
||||
/**
|
||||
* @name BN_FOUR
|
||||
* @summary BN constant for 4.
|
||||
*/
|
||||
export declare const BN_FOUR: BN;
|
||||
/**
|
||||
* @name BN_FIVE
|
||||
* @summary BN constant for 5.
|
||||
*/
|
||||
export declare const BN_FIVE: BN;
|
||||
/**
|
||||
* @name BN_SIX
|
||||
* @summary BN constant for 6.
|
||||
*/
|
||||
export declare const BN_SIX: BN;
|
||||
/**
|
||||
* @name BN_SEVEN
|
||||
* @summary BN constant for 7.
|
||||
*/
|
||||
export declare const BN_SEVEN: BN;
|
||||
/**
|
||||
* @name BN_EIGHT
|
||||
* @summary BN constant for 8.
|
||||
*/
|
||||
export declare const BN_EIGHT: BN;
|
||||
/**
|
||||
* @name BN_NINE
|
||||
* @summary BN constant for 9.
|
||||
*/
|
||||
export declare const BN_NINE: BN;
|
||||
/**
|
||||
* @name BN_TEN
|
||||
* @summary BN constant for 10.
|
||||
*/
|
||||
export declare const BN_TEN: BN;
|
||||
/**
|
||||
* @name BN_HUNDRED
|
||||
* @summary BN constant for 100.
|
||||
*/
|
||||
export declare const BN_HUNDRED: BN;
|
||||
/**
|
||||
* @name BN_THOUSAND
|
||||
* @summary BN constant for 1,000.
|
||||
*/
|
||||
export declare const BN_THOUSAND: BN;
|
||||
/**
|
||||
* @name BN_MILLION
|
||||
* @summary BN constant for 1,000,000.
|
||||
*/
|
||||
export declare const BN_MILLION: BN;
|
||||
/**
|
||||
* @name BN_BILLION
|
||||
* @summary BN constant for 1,000,000,000.
|
||||
*/
|
||||
export declare const BN_BILLION: BN;
|
||||
/**
|
||||
* @name BN_QUINTILL
|
||||
* @summary BN constant for 1,000,000,000,000,000,000.
|
||||
*/
|
||||
export declare const BN_QUINTILL: BN;
|
||||
/**
|
||||
* @name BN_MAX_INTEGER
|
||||
* @summary BN constant for MAX_SAFE_INTEGER
|
||||
*/
|
||||
export declare const BN_MAX_INTEGER: BN;
|
||||
/**
|
||||
* @name BN_SQRT_MAX_INTEGER
|
||||
* @summary BN constant for Math.sqrt(MAX_SAFE_INTEGER)
|
||||
*/
|
||||
export declare const BN_SQRT_MAX_INTEGER: BN;
|
||||
@@ -0,0 +1,94 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BN_SQRT_MAX_INTEGER = exports.BN_MAX_INTEGER = exports.BN_QUINTILL = exports.BN_BILLION = exports.BN_MILLION = exports.BN_THOUSAND = exports.BN_HUNDRED = exports.BN_TEN = exports.BN_NINE = exports.BN_EIGHT = exports.BN_SEVEN = exports.BN_SIX = exports.BN_FIVE = exports.BN_FOUR = exports.BN_THREE = exports.BN_TWO = exports.BN_ONE = exports.BN_ZERO = void 0;
|
||||
const bn_js_1 = require("./bn.js");
|
||||
/**
|
||||
* @name BN_ZERO
|
||||
* @summary BN constant for 0.
|
||||
*/
|
||||
exports.BN_ZERO = new bn_js_1.BN(0);
|
||||
/**
|
||||
* @name BN_ONE
|
||||
* @summary BN constant for 1.
|
||||
*/
|
||||
exports.BN_ONE = new bn_js_1.BN(1);
|
||||
/**
|
||||
* @name BN_TWO
|
||||
* @summary BN constant for 2.
|
||||
*/
|
||||
exports.BN_TWO = new bn_js_1.BN(2);
|
||||
/**
|
||||
* @name BN_THREE
|
||||
* @summary BN constant for 3.
|
||||
*/
|
||||
exports.BN_THREE = new bn_js_1.BN(3);
|
||||
/**
|
||||
* @name BN_FOUR
|
||||
* @summary BN constant for 4.
|
||||
*/
|
||||
exports.BN_FOUR = new bn_js_1.BN(4);
|
||||
/**
|
||||
* @name BN_FIVE
|
||||
* @summary BN constant for 5.
|
||||
*/
|
||||
exports.BN_FIVE = new bn_js_1.BN(5);
|
||||
/**
|
||||
* @name BN_SIX
|
||||
* @summary BN constant for 6.
|
||||
*/
|
||||
exports.BN_SIX = new bn_js_1.BN(6);
|
||||
/**
|
||||
* @name BN_SEVEN
|
||||
* @summary BN constant for 7.
|
||||
*/
|
||||
exports.BN_SEVEN = new bn_js_1.BN(7);
|
||||
/**
|
||||
* @name BN_EIGHT
|
||||
* @summary BN constant for 8.
|
||||
*/
|
||||
exports.BN_EIGHT = new bn_js_1.BN(8);
|
||||
/**
|
||||
* @name BN_NINE
|
||||
* @summary BN constant for 9.
|
||||
*/
|
||||
exports.BN_NINE = new bn_js_1.BN(9);
|
||||
/**
|
||||
* @name BN_TEN
|
||||
* @summary BN constant for 10.
|
||||
*/
|
||||
exports.BN_TEN = new bn_js_1.BN(10);
|
||||
/**
|
||||
* @name BN_HUNDRED
|
||||
* @summary BN constant for 100.
|
||||
*/
|
||||
exports.BN_HUNDRED = new bn_js_1.BN(100);
|
||||
/**
|
||||
* @name BN_THOUSAND
|
||||
* @summary BN constant for 1,000.
|
||||
*/
|
||||
exports.BN_THOUSAND = new bn_js_1.BN(1_000);
|
||||
/**
|
||||
* @name BN_MILLION
|
||||
* @summary BN constant for 1,000,000.
|
||||
*/
|
||||
exports.BN_MILLION = new bn_js_1.BN(1_000_000);
|
||||
/**
|
||||
* @name BN_BILLION
|
||||
* @summary BN constant for 1,000,000,000.
|
||||
*/
|
||||
exports.BN_BILLION = new bn_js_1.BN(1_000_000_000);
|
||||
/**
|
||||
* @name BN_QUINTILL
|
||||
* @summary BN constant for 1,000,000,000,000,000,000.
|
||||
*/
|
||||
exports.BN_QUINTILL = exports.BN_BILLION.mul(exports.BN_BILLION);
|
||||
/**
|
||||
* @name BN_MAX_INTEGER
|
||||
* @summary BN constant for MAX_SAFE_INTEGER
|
||||
*/
|
||||
exports.BN_MAX_INTEGER = new bn_js_1.BN(Number.MAX_SAFE_INTEGER);
|
||||
/**
|
||||
* @name BN_SQRT_MAX_INTEGER
|
||||
* @summary BN constant for Math.sqrt(MAX_SAFE_INTEGER)
|
||||
*/
|
||||
exports.BN_SQRT_MAX_INTEGER = new bn_js_1.BN(94906265);
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
export { hexToBn as bnFromHex } from '../hex/toBn.js';
|
||||
@@ -0,0 +1,5 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.bnFromHex = void 0;
|
||||
var toBn_js_1 = require("../hex/toBn.js");
|
||||
Object.defineProperty(exports, "bnFromHex", { enumerable: true, get: function () { return toBn_js_1.hexToBn; } });
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @summary Utility methods to convert to and from `BN` objects
|
||||
*/
|
||||
export { BN } from './bn.js';
|
||||
export { bnFromHex } from './fromHex.js';
|
||||
export { bnMax, bnMin } from './min.js';
|
||||
export { bnSqrt } from './sqrt.js';
|
||||
export { bnToBn } from './toBn.js';
|
||||
export { bnToHex } from './toHex.js';
|
||||
export { bnToU8a } from './toU8a.js';
|
||||
export * from './consts.js';
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user