@polkadot/types-codec
Advanced tools
Comparing version 9.12.1 to 9.13.1
@@ -22,2 +22,5 @@ import type { HexString } from '@polkadot/util/types'; | ||
get hash(): IU8a; | ||
/** | ||
* @description returns the inner (wrapped value) | ||
*/ | ||
get inner(): T; | ||
@@ -64,4 +67,11 @@ /** | ||
*/ | ||
toRawType(): string; | ||
abstract toRawType(): string; | ||
/** | ||
* @description Returns the inner wrapped value (equivalent to valueOf) | ||
*/ | ||
unwrap(): T; | ||
/** | ||
* @description Returns the inner wrapped value | ||
*/ | ||
valueOf(): T; | ||
} |
@@ -29,2 +29,6 @@ // Copyright 2017-2023 @polkadot/types-codec authors & contributors | ||
} | ||
/** | ||
* @description returns the inner (wrapped value) | ||
*/ | ||
get inner() { | ||
@@ -101,8 +105,16 @@ return this.#raw; | ||
*/ | ||
toRawType() { | ||
return 'Base'; | ||
} | ||
/** | ||
* @description Returns the inner wrapped value (equivalent to valueOf) | ||
*/ | ||
unwrap() { | ||
return this.#raw; | ||
} | ||
/** | ||
* @description Returns the inner wrapped value | ||
*/ | ||
valueOf() { | ||
return this.#raw; | ||
} | ||
} |
// Copyright 2017-2023 @polkadot/types-codec authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBn, isFunction, isHex, isNumber, isObject, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util'; | ||
import { BN, BN_BILLION, BN_HUNDRED, BN_MILLION, BN_QUINTILL, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isBigInt, isBn, isFunction, isHex, isNumber, isObject, isString, isU8a, u8aToBn, u8aToNumber } from '@polkadot/util'; | ||
export const DEFAULT_UINT_BITS = 64; | ||
@@ -12,2 +12,5 @@ | ||
const FORMATTERS = [['Perquintill', BN_QUINTILL], ['Perbill', BN_BILLION], ['Permill', BN_MILLION], ['Percent', BN_HUNDRED]]; | ||
function isToBn(value) { | ||
return isFunction(value.toBn); | ||
} | ||
function toPercentage(value, divisor) { | ||
@@ -35,5 +38,9 @@ return `${(value.mul(MUL_P).div(divisor).toNumber() / 100).toFixed(2)}%`; | ||
return value; | ||
} else if (isBn(value)) { | ||
} else if (isBn(value) || isBigInt(value)) { | ||
return value.toString(); | ||
} else if (isObject(value) && !isFunction(value.toBn)) { | ||
} else if (isObject(value)) { | ||
if (isToBn(value)) { | ||
return value.toBn().toString(); | ||
} | ||
// Allow the construction from an object with a single top-level key. This means that | ||
@@ -46,9 +53,5 @@ // single key objects can be treated equivalently to numbers, assuming they meet the | ||
} | ||
const inner = value[keys[0]]; | ||
if (!isString(inner) && !isNumber(inner)) { | ||
throw new Error('Unable to construct from object with non-string/non-number value'); | ||
} | ||
return decodeAbstractInt(inner, isNegative); | ||
return decodeAbstractInt(value[keys[0]], isNegative); | ||
} | ||
return bnToBn(value).toString(); | ||
throw new Error(`Unable to create BN from unknown type ${typeof value}`); | ||
} | ||
@@ -55,0 +58,0 @@ |
@@ -35,2 +35,6 @@ "use strict"; | ||
} | ||
/** | ||
* @description returns the inner (wrapped value) | ||
*/ | ||
get inner() { | ||
@@ -107,9 +111,17 @@ return this.#raw; | ||
*/ | ||
toRawType() { | ||
return 'Base'; | ||
} | ||
/** | ||
* @description Returns the inner wrapped value (equivalent to valueOf) | ||
*/ | ||
unwrap() { | ||
return this.#raw; | ||
} | ||
/** | ||
* @description Returns the inner wrapped value | ||
*/ | ||
valueOf() { | ||
return this.#raw; | ||
} | ||
} | ||
exports.AbstractBase = AbstractBase; |
@@ -19,2 +19,5 @@ "use strict"; | ||
const FORMATTERS = [['Perquintill', _util.BN_QUINTILL], ['Perbill', _util.BN_BILLION], ['Permill', _util.BN_MILLION], ['Percent', _util.BN_HUNDRED]]; | ||
function isToBn(value) { | ||
return (0, _util.isFunction)(value.toBn); | ||
} | ||
function toPercentage(value, divisor) { | ||
@@ -42,5 +45,9 @@ return `${(value.mul(MUL_P).div(divisor).toNumber() / 100).toFixed(2)}%`; | ||
return value; | ||
} else if ((0, _util.isBn)(value)) { | ||
} else if ((0, _util.isBn)(value) || (0, _util.isBigInt)(value)) { | ||
return value.toString(); | ||
} else if ((0, _util.isObject)(value) && !(0, _util.isFunction)(value.toBn)) { | ||
} else if ((0, _util.isObject)(value)) { | ||
if (isToBn(value)) { | ||
return value.toBn().toString(); | ||
} | ||
// Allow the construction from an object with a single top-level key. This means that | ||
@@ -53,9 +60,5 @@ // single key objects can be treated equivalently to numbers, assuming they meet the | ||
} | ||
const inner = value[keys[0]]; | ||
if (!(0, _util.isString)(inner) && !(0, _util.isNumber)(inner)) { | ||
throw new Error('Unable to construct from object with non-string/non-number value'); | ||
} | ||
return decodeAbstractInt(inner, isNegative); | ||
return decodeAbstractInt(value[keys[0]], isNegative); | ||
} | ||
return (0, _util.bnToBn)(value).toString(); | ||
throw new Error(`Unable to create BN from unknown type ${typeof value}`); | ||
} | ||
@@ -62,0 +65,0 @@ |
@@ -16,4 +16,4 @@ "use strict"; | ||
type: 'cjs', | ||
version: '9.12.1' | ||
version: '9.13.1' | ||
}; | ||
exports.packageInfo = packageInfo; |
@@ -23,3 +23,3 @@ { | ||
"type": "module", | ||
"version": "9.12.1", | ||
"version": "9.13.1", | ||
"main": "./cjs/index.js", | ||
@@ -51,7 +51,2 @@ "module": "./index.js", | ||
}, | ||
"./abstract/BigInt": { | ||
"types": "./abstract/BigInt.d.ts", | ||
"require": "./cjs/abstract/BigInt.js", | ||
"default": "./abstract/BigInt.js" | ||
}, | ||
"./abstract/Int": { | ||
@@ -62,2 +57,7 @@ "types": "./abstract/Int.d.ts", | ||
}, | ||
"./abstract/Object": { | ||
"types": "./abstract/Object.d.ts", | ||
"require": "./cjs/abstract/Object.js", | ||
"default": "./abstract/Object.js" | ||
}, | ||
"./base": { | ||
@@ -441,5 +441,5 @@ "types": "./base/index.d.ts", | ||
"@babel/runtime": "^7.20.13", | ||
"@polkadot/util": "^10.2.6", | ||
"@polkadot/x-bigint": "^10.2.6" | ||
"@polkadot/util": "^10.3.1", | ||
"@polkadot/x-bigint": "^10.3.1" | ||
} | ||
} |
@@ -10,3 +10,3 @@ // Copyright 2017-2023 @polkadot/types-codec authors & contributors | ||
type: 'esm', | ||
version: '9.12.1' | ||
version: '9.13.1' | ||
}; |
import type { HexString } from '@polkadot/util/types'; | ||
import type { AnyJson } from './helpers'; | ||
import type { AnyJson, ToString } from './helpers'; | ||
import type { IU8a } from './interfaces'; | ||
@@ -104,3 +104,7 @@ import type { Registry } from './registry'; | ||
} | ||
export interface CodecObject<T extends ToString> extends Codec { | ||
readonly $: T; | ||
valueOf(): T; | ||
} | ||
export type CodecTo = 'toHex' | 'toJSON' | 'toPrimitive' | 'toString' | 'toU8a'; | ||
export type ArgsDef = Record<string, CodecClass | string>; |
@@ -18,1 +18,8 @@ /// <reference types="bn.js" /> | ||
export type AnyTupleValue = Exclude<AnyU8a, string> | HexString | (Codec | AnyU8a | AnyNumber | AnyString | undefined | null)[]; | ||
export interface ToString { | ||
toString: () => string; | ||
} | ||
export interface ToBn { | ||
toBn: () => BN; | ||
} | ||
export type LookupString = `Lookup${number}`; |
/// <reference types="bn.js" /> | ||
import type { BN } from '@polkadot/util'; | ||
import type { Codec, CodecClass } from './codec'; | ||
import type { AnyTuple } from './helpers'; | ||
import type { AnyTuple, LookupString } from './helpers'; | ||
import type { ICompact, IEnum, IMap, IMethod, INumber, IOption, IResult, ISet, IStruct, ITuple, IU8a, IVec } from './interfaces'; | ||
@@ -48,4 +48,4 @@ export type OnlyCodec<K, T, Types> = K extends keyof Types ? Types[K] : T extends ICompact | IEnum | IMap | IMethod | INumber | IOption | IResult | ISet | IStruct | ITuple | IU8a | IVec ? T : T extends Codec ? T : never; | ||
findMetaEvent(eventIndex: Uint8Array): CodecClass<any>; | ||
isLookupType(value: string): boolean; | ||
createLookupType(lookupId: ICompact<INumber> | number): string; | ||
isLookupType(value: string): value is LookupString; | ||
createLookupType(lookupId: ICompact<INumber> | number): LookupString; | ||
createClassUnsafe<T extends Codec = Codec, K extends string = string>(type: K): CodecClass<T>; | ||
@@ -52,0 +52,0 @@ createTypeUnsafe<T extends Codec = Codec, K extends string = string>(type: K, params: unknown[], options?: CodecCreateOptions): T; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
627219
13260
Updated@polkadot/util@^10.3.1
Updated@polkadot/x-bigint@^10.3.1