diff --git a/packages/types-codec/src/abstract/Array.ts b/packages/types-codec/src/abstract/Array.ts index 551117168c41..ebeeba9afaee 100644 --- a/packages/types-codec/src/abstract/Array.ts +++ b/packages/types-codec/src/abstract/Array.ts @@ -153,12 +153,12 @@ export abstract class AbstractArray extends Array implements /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { const count = this.length; const result = new Array(count); for (let i = 0; i < count; i++) { - result[i] = this[i] && this[i].toPrimitive(); + result[i] = this[i] && this[i].toPrimitive(disableAscii); } return result; diff --git a/packages/types-codec/src/abstract/Base.ts b/packages/types-codec/src/abstract/Base.ts index c92c6b1ecc96..1a54b5809c5c 100644 --- a/packages/types-codec/src/abstract/Base.ts +++ b/packages/types-codec/src/abstract/Base.ts @@ -89,8 +89,8 @@ export abstract class AbstractBase implements Codec { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { - return this.#raw.toPrimitive(); + public toPrimitive (disableAscii?: boolean): AnyJson { + return this.#raw.toPrimitive(disableAscii); } /** diff --git a/packages/types-codec/src/abstract/Object.ts b/packages/types-codec/src/abstract/Object.ts index 74a3b66f3763..7ab48145e6dc 100644 --- a/packages/types-codec/src/abstract/Object.ts +++ b/packages/types-codec/src/abstract/Object.ts @@ -70,7 +70,7 @@ export abstract class AbstractObject implements CodecObject< /** * @description Converts the value in a best-fit primitive form */ - public abstract toPrimitive (): AnyJson; + public abstract toPrimitive (disableAscii?: boolean): AnyJson; /** * @description Returns the string representation of the value diff --git a/packages/types-codec/src/base/Compact.ts b/packages/types-codec/src/base/Compact.ts index 065a82f57bfd..e8ae40b5525c 100644 --- a/packages/types-codec/src/base/Compact.ts +++ b/packages/types-codec/src/base/Compact.ts @@ -164,8 +164,8 @@ export class Compact implements ICompact { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): string | number { - return this.#raw.toPrimitive(); + public toPrimitive (disableAscii?: boolean): string | number { + return this.#raw.toPrimitive(disableAscii); } /** diff --git a/packages/types-codec/src/base/Enum.ts b/packages/types-codec/src/base/Enum.ts index 8f8ef87ff349..53c112444445 100644 --- a/packages/types-codec/src/base/Enum.ts +++ b/packages/types-codec/src/base/Enum.ts @@ -399,10 +399,10 @@ export class Enum implements IEnum { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { return this.#isBasic ? this.type - : { [stringCamelCase(this.type)]: this.#raw.toPrimitive() }; + : { [stringCamelCase(this.type)]: this.#raw.toPrimitive(disableAscii) }; } /** diff --git a/packages/types-codec/src/base/Option.ts b/packages/types-codec/src/base/Option.ts index 5482fe502b56..fc270d578374 100644 --- a/packages/types-codec/src/base/Option.ts +++ b/packages/types-codec/src/base/Option.ts @@ -199,10 +199,10 @@ export class Option implements IOption { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { return this.isNone ? null - : this.#raw.toPrimitive(); + : this.#raw.toPrimitive(disableAscii); } /** diff --git a/packages/types-codec/src/extended/BTreeSet.ts b/packages/types-codec/src/extended/BTreeSet.ts index a2e0fec77f31..41bc60b2e5c6 100644 --- a/packages/types-codec/src/extended/BTreeSet.ts +++ b/packages/types-codec/src/extended/BTreeSet.ts @@ -196,11 +196,11 @@ export class BTreeSet extends Set implements ISet /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): AnyJson { + public toPrimitive (disableAscii?: boolean): AnyJson { const json: AnyJson = []; for (const v of this.values()) { - json.push(v.toPrimitive()); + json.push(v.toPrimitive(disableAscii)); } return json; diff --git a/packages/types-codec/src/extended/WrapperKeepOpaque.ts b/packages/types-codec/src/extended/WrapperKeepOpaque.ts index e15073df07c9..24c7991963b0 100644 --- a/packages/types-codec/src/extended/WrapperKeepOpaque.ts +++ b/packages/types-codec/src/extended/WrapperKeepOpaque.ts @@ -87,16 +87,16 @@ export class WrapperKeepOpaque extends Bytes { public override toHuman (isExtended?: boolean, disableAscii?: boolean): AnyJson { return this.#decoded ? this.#decoded.toHuman(isExtended, disableAscii) - : super.toHuman(); + : super.toHuman(isExtended, disableAscii); } /** * @description Converts the value in a best-fit primitive form */ - public override toPrimitive (): any { + public override toPrimitive (disableAscii?: boolean): any { return this.#decoded - ? this.#decoded.toPrimitive() - : super.toPrimitive(); + ? this.#decoded.toPrimitive(disableAscii) + : super.toPrimitive(disableAscii); } /** diff --git a/packages/types-codec/src/native/Json.ts b/packages/types-codec/src/native/Json.ts index 93a72b7fbb3b..362d81d7c162 100644 --- a/packages/types-codec/src/native/Json.ts +++ b/packages/types-codec/src/native/Json.ts @@ -114,10 +114,10 @@ export class Json extends Map implements Codec { /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): Record { + public toPrimitive (disableAscii?: boolean): Record { return [...this.entries()].reduce>((json, [key, value]): Record => { json[key] = isFunction((value as Codec).toPrimitive) - ? (value as Codec).toPrimitive() + ? (value as Codec).toPrimitive(disableAscii) : value as AnyJson; return json; diff --git a/packages/types-codec/src/native/Struct.ts b/packages/types-codec/src/native/Struct.ts index 82e472d165ae..1089c21e4685 100644 --- a/packages/types-codec/src/native/Struct.ts +++ b/packages/types-codec/src/native/Struct.ts @@ -296,11 +296,11 @@ export class Struct< /** * @description Converts the value in a best-fit primitive form */ - public toPrimitive (): Record { + public toPrimitive (disableAscii?: boolean): Record { const json: Record = {}; for (const [k, v] of this.entries()) { - json[k as string] = v.toPrimitive(); + json[k as string] = v.toPrimitive(disableAscii); } return json; diff --git a/packages/types-codec/src/types/interfaces.ts b/packages/types-codec/src/types/interfaces.ts index 9f0760778241..2a11bf53d7a2 100644 --- a/packages/types-codec/src/types/interfaces.ts +++ b/packages/types-codec/src/types/interfaces.ts @@ -31,7 +31,7 @@ export interface INumber extends Codec { toBigInt (): bigint; toBn (): BN; toNumber (): number; - toPrimitive (): string | number; + toPrimitive (disableAscii?: boolean): string | number; } export interface IFloat extends Codec { @@ -78,7 +78,7 @@ export interface IU8a extends Uint8Array, Codec { readonly isUtf8: boolean bitLength (): number; - toHuman (isExtended?: boolean): any; + toHuman (isExtended?: boolean, disableAscii?: boolean): any; toJSON (): any; toUtf8 (): string; }