Additional internal comments for exposed functions (#1529)
This commit is contained in:
@@ -100,7 +100,7 @@ export function compactFromU8aLim (u8a: Uint8Array): [number, number] {
|
|||||||
case 7:
|
case 7:
|
||||||
return [7, u8a[1] + (u8a[2] * 0x1_00) + (u8a[3] * 0x1_00_00) + (u8a[4] * 0x1_00_00_00) + (u8a[5] * 0x1_00_00_00_00) + (u8a[6] * 0x1_00_00_00_00_00)];
|
return [7, u8a[1] + (u8a[2] * 0x1_00) + (u8a[3] * 0x1_00_00) + (u8a[4] * 0x1_00_00_00) + (u8a[5] * 0x1_00_00_00_00) + (u8a[6] * 0x1_00_00_00_00_00)];
|
||||||
|
|
||||||
// for anything else, use the non-unrolled version
|
// for anything else, we are above the actual MAX_SAFE_INTEGER - bail out
|
||||||
default:
|
default:
|
||||||
throw new Error('Compact input is > Number.MAX_SAFE_INTEGER');
|
throw new Error('Compact input is > Number.MAX_SAFE_INTEGER');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ const HR_MS = MIN_MS * 60;
|
|||||||
const DAY_MS = HR_MS * 24;
|
const DAY_MS = HR_MS * 24;
|
||||||
const ZERO: Time = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
|
const ZERO: Time = { days: 0, hours: 0, milliseconds: 0, minutes: 0, seconds: 0 };
|
||||||
|
|
||||||
/**
|
/** @internal */
|
||||||
* @name addTime
|
|
||||||
* @summary Add together two Time arrays
|
|
||||||
*/
|
|
||||||
|
|
||||||
function add (a: Partial<Time>, b: Time): Time {
|
function add (a: Partial<Time>, b: Time): Time {
|
||||||
return {
|
return {
|
||||||
days: (a.days || 0) + b.days,
|
days: (a.days || 0) + b.days,
|
||||||
@@ -23,6 +19,7 @@ function add (a: Partial<Time>, b: Time): Time {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
function extractSecs (ms: number): Time {
|
function extractSecs (ms: number): Time {
|
||||||
const s = ms / 1000;
|
const s = ms / 1000;
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,23 @@
|
|||||||
|
|
||||||
import { BigInt } from '@polkadot/x-bigint';
|
import { BigInt } from '@polkadot/x-bigint';
|
||||||
|
|
||||||
|
/** true if the environment has proper BigInt support */
|
||||||
export const hasBigInt = typeof BigInt === 'function' && typeof BigInt.asIntN === 'function';
|
export const hasBigInt = typeof BigInt === 'function' && typeof BigInt.asIntN === 'function';
|
||||||
|
|
||||||
|
/** true if the environment has support for Buffer */
|
||||||
export const hasBuffer = typeof Buffer !== 'undefined';
|
export const hasBuffer = typeof Buffer !== 'undefined';
|
||||||
|
|
||||||
|
/** true if the environment is CJS */
|
||||||
export const hasCjs = typeof require === 'function' && typeof module !== 'undefined';
|
export const hasCjs = typeof require === 'function' && typeof module !== 'undefined';
|
||||||
|
|
||||||
|
/** true if the environment has __dirname available */
|
||||||
export const hasDirname = typeof __dirname !== 'undefined';
|
export const hasDirname = typeof __dirname !== 'undefined';
|
||||||
|
|
||||||
|
/** true if the environment is ESM */
|
||||||
export const hasEsm = !hasCjs;
|
export const hasEsm = !hasCjs;
|
||||||
|
|
||||||
|
/** true if the environment has process available (typically Node.js) */
|
||||||
export const hasProcess = typeof process === 'object';
|
export const hasProcess = typeof process === 'object';
|
||||||
|
|
||||||
|
/** true if the environment has WebAssembly available */
|
||||||
export const hasWasm = typeof WebAssembly !== 'undefined';
|
export const hasWasm = typeof WebAssembly !== 'undefined';
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ type AnyFn = (...args: unknown[]) => unknown;
|
|||||||
|
|
||||||
type WithToString = { toString: () => string };
|
type WithToString = { toString: () => string };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name lazyMethod
|
||||||
|
* @description
|
||||||
|
* Creates a lazy, on-demand getter for the specific value. Upon get the value will be evaluated.
|
||||||
|
*/
|
||||||
export function lazyMethod <T, K> (result: Record<string, T> | AnyFn, item: K, creator: (d: K) => T, getName?: (d: K) => string): void {
|
export function lazyMethod <T, K> (result: Record<string, T> | AnyFn, item: K, creator: (d: K) => T, getName?: (d: K) => string): void {
|
||||||
const name = getName
|
const name = getName
|
||||||
? getName(item)
|
? getName(item)
|
||||||
@@ -46,6 +51,11 @@ export function lazyMethod <T, K> (result: Record<string, T> | AnyFn, item: K, c
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name lazyMethods
|
||||||
|
* @description
|
||||||
|
* Creates lazy, on-demand getters for the specific values.
|
||||||
|
*/
|
||||||
export function lazyMethods <T, K> (result: Record<string, T>, items: K[], creator: (v: K) => T, getName?: (m: K) => string): Record<string, T> {
|
export function lazyMethods <T, K> (result: Record<string, T>, items: K[], creator: (v: K) => T, getName?: (m: K) => string): Record<string, T> {
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
lazyMethod(result, items[i], creator, getName);
|
lazyMethod(result, items[i], creator, getName);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { objectSpread } from '../object/spread';
|
|||||||
const U8_MAX = BigInt(256);
|
const U8_MAX = BigInt(256);
|
||||||
const U16_MAX = BigInt(256 * 256);
|
const U16_MAX = BigInt(256 * 256);
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
function xor (input: Uint8Array): Uint8Array {
|
function xor (input: Uint8Array): Uint8Array {
|
||||||
const result = new Uint8Array(input.length);
|
const result = new Uint8Array(input.length);
|
||||||
const dvI = new DataView(input.buffer, input.byteOffset);
|
const dvI = new DataView(input.buffer, input.byteOffset);
|
||||||
@@ -29,6 +30,7 @@ function xor (input: Uint8Array): Uint8Array {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
function toBigInt (input: Uint8Array): bigint {
|
function toBigInt (input: Uint8Array): bigint {
|
||||||
const dvI = new DataView(input.buffer, input.byteOffset);
|
const dvI = new DataView(input.buffer, input.byteOffset);
|
||||||
const mod = input.length % 2;
|
const mod = input.length % 2;
|
||||||
|
|||||||
@@ -9,12 +9,18 @@ import { u8aConcatStrict } from './concat';
|
|||||||
import { u8aEq } from './eq';
|
import { u8aEq } from './eq';
|
||||||
import { u8aToU8a } from './toU8a';
|
import { u8aToU8a } from './toU8a';
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
export const U8A_WRAP_ETHEREUM = u8aToU8a('\x19Ethereum Signed Message:\n');
|
export const U8A_WRAP_ETHEREUM = u8aToU8a('\x19Ethereum Signed Message:\n');
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
export const U8A_WRAP_PREFIX = u8aToU8a('<Bytes>');
|
export const U8A_WRAP_PREFIX = u8aToU8a('<Bytes>');
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
export const U8A_WRAP_POSTFIX = u8aToU8a('</Bytes>');
|
export const U8A_WRAP_POSTFIX = u8aToU8a('</Bytes>');
|
||||||
|
|
||||||
const WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
|
const WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
export function u8aIsWrapped (u8a: Uint8Array, withEthereum: boolean): boolean {
|
export function u8aIsWrapped (u8a: Uint8Array, withEthereum: boolean): boolean {
|
||||||
return (
|
return (
|
||||||
(
|
(
|
||||||
@@ -30,6 +36,10 @@ export function u8aIsWrapped (u8a: Uint8Array, withEthereum: boolean): boolean {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name u8aUnwrapBytes
|
||||||
|
* @description Removes all <Bytes>...</Bytes> wrappers from the supplied value
|
||||||
|
*/
|
||||||
export function u8aUnwrapBytes (bytes: U8aLike): Uint8Array {
|
export function u8aUnwrapBytes (bytes: U8aLike): Uint8Array {
|
||||||
const u8a = u8aToU8a(bytes);
|
const u8a = u8aToU8a(bytes);
|
||||||
|
|
||||||
@@ -39,6 +49,10 @@ export function u8aUnwrapBytes (bytes: U8aLike): Uint8Array {
|
|||||||
: u8a;
|
: u8a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name u8aWrapBytes
|
||||||
|
* @description Adds a <Bytes>...</Bytes> wrapper to the supplied value (if not already existing)
|
||||||
|
*/
|
||||||
export function u8aWrapBytes (bytes: U8aLike): Uint8Array {
|
export function u8aWrapBytes (bytes: U8aLike): Uint8Array {
|
||||||
const u8a = u8aToU8a(bytes);
|
const u8a = u8aToU8a(bytes);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user