name: Option

description: An Option is an optional field. Basically the first byte indicates that there is is value to follow. If the byte is 1 there is an actual value. So the Option implements that - decodes, checks for optionality and wraps the required structure with a value if/as required/found.

Type parameters

T : Codec

Hierarchy

Base<T>

↳ Option

Implements

Constructors

constructor

⊕ new Option(Type: Constructor, value?: any): Option

Overrides Base.constructor

Defined in codec/Option.ts:19

Parameters:

Name Type
Type Constructor
Optional value any

Returns: Option


Accessors

encodedLength

get encodedLength(): number

Defined in codec/Option.ts:56

description: The length of the value when encoded as a Uint8Array

Returns: number


isEmpty

get isEmpty(): boolean

Defined in codec/Option.ts:64

description: Checks if the Option has no value

Returns: boolean


isNone

get isNone(): boolean

Defined in codec/Option.ts:71

description: Checks if the Option has no value

Returns: boolean


isSome

get isSome(): boolean

Defined in codec/Option.ts:78

description: Checks if the Option has a value

Returns: boolean


value

get value(): Codec

Defined in codec/Option.ts:85

description: The actual value for the Option

Returns: Codec


Methods

eq

▸ eq(other?: any): boolean

Implementation of Codec.eq

Defined in codec/Option.ts:92

description: Compares the value of the input to see if there is a match

Parameters:

Name Type
Optional other any

Returns: boolean


toHex

▸ toHex(): string

Implementation of Codec.toHex

Defined in codec/Option.ts:103

description: Returns a hex string representation of the value

Returns: string


toJSON

▸ toJSON(): any

Implementation of Codec.toJSON

Defined in codec/Option.ts:110

description: Converts the Object to JSON, typically used for RPC transfers

Returns: any


toString

▸ toString(): string

Implementation of Codec.toString

Defined in codec/Option.ts:117

description: Returns the string representation of the value

Returns: string


toU8a

▸ toU8a(isBare?: undefined | false | true): Uint8Array

Implementation of Codec.toU8a

Defined in codec/Option.ts:125

description: Encodes the value as a Uint8Array as per the parity-codec specifications

Parameters:

Name Type Description
Optional isBare undefined | false | true true when the value has none of the type-specific prefixes (internal)

Returns: Uint8Array


unwrap

▸ unwrap(): T

Defined in codec/Option.ts:143

description: Returns the value that the Option represents (if available), throws if null

Returns: T


unwrapOr

▸ unwrapOr<O>(defaultValue: O): T | O

Defined in codec/Option.ts:155

description: Returns the value that the Option represents (if available) or defaultValue if none

Type parameters:

O

Parameters:

Name Type Description
defaultValue O The value to return if the option isNone

Returns: T | O


<Static> decodeOption

▸ decodeOption<O>(Type: Constructor, value?: any): Codec

Defined in codec/Option.ts:26

Type parameters:

O

Parameters:

Name Type
Type Constructor
Optional value any

Returns: Codec


<Static> with

▸ with<O>(Type: Constructor): Constructor<Option<O>>

Defined in codec/Option.ts:45

Type parameters:

O : Codec

Parameters:

Name Type
Type Constructor

Returns: Constructor<Option<O>>


Last Updated: 2/25/2019, 4:39:16 PM