Skip to content

API Reference / @gtkx/runtime / fromVariant

Function: fromVariant() ​

Call Signature ​

fromVariant<S>(typeString, variant): ParsedValue<S>

Defined in: packages/runtime/dist/variant.d.ts:129

Unpacks a GLib.Variant into the JavaScript value its GVariant type describes, the inverse of toVariant. A dictionary keyed by strings unpacks to a record and one keyed by anything else to a Map, an array to an array, a byte array (ay) to the byte array type the generated bindings use (Uint8Array under the v2ByteArrays future flag, number[] otherwise), a tuple to an array of its members, a maybe to its value or null, and a nested variant to the GLib.Variant itself unless recursive is set, in which case it is unwrapped all the way down.

The type string is optional: without one the variant's own type is read, and the result is unknown. With one given as a literal, the result is typed from it.

Type Parameters ​

S ​

S extends string

Parameters ​

typeString ​

S

GVariant type the variant holds, such as "a{sv}".

variant ​

Variant

Variant to read, which has to hold that type.

Returns ​

ParsedValue<S>

The unpacked value.

Throws ​

When the type string is not one complete GVariant type.

Call Signature ​

fromVariant<S>(typeString, variant, options): ParsedValue<S>

Defined in: packages/runtime/dist/variant.d.ts:130

Unpacks a GLib.Variant into the JavaScript value its GVariant type describes, the inverse of toVariant. A dictionary keyed by strings unpacks to a record and one keyed by anything else to a Map, an array to an array, a byte array (ay) to the byte array type the generated bindings use (Uint8Array under the v2ByteArrays future flag, number[] otherwise), a tuple to an array of its members, a maybe to its value or null, and a nested variant to the GLib.Variant itself unless recursive is set, in which case it is unwrapped all the way down.

The type string is optional: without one the variant's own type is read, and the result is unknown. With one given as a literal, the result is typed from it.

Type Parameters ​

S ​

S extends string

Parameters ​

typeString ​

S

GVariant type the variant holds, such as "a{sv}".

variant ​

Variant

Variant to read, which has to hold that type.

options ​

RecursiveFromVariantOptions

Whether to unwrap nested variants recursively.

Returns ​

ParsedValue<S>

The unpacked value.

Throws ​

When the type string is not one complete GVariant type.

Call Signature ​

fromVariant<S>(typeString, variant, options): ParsedValue<S, Uint8Array<ArrayBufferLike>, Variant> | ParsedValue<S, Uint8Array<ArrayBufferLike>, unknown>

Defined in: packages/runtime/dist/variant.d.ts:131

Unpacks a GLib.Variant into the JavaScript value its GVariant type describes, the inverse of toVariant. A dictionary keyed by strings unpacks to a record and one keyed by anything else to a Map, an array to an array, a byte array (ay) to the byte array type the generated bindings use (Uint8Array under the v2ByteArrays future flag, number[] otherwise), a tuple to an array of its members, a maybe to its value or null, and a nested variant to the GLib.Variant itself unless recursive is set, in which case it is unwrapped all the way down.

The type string is optional: without one the variant's own type is read, and the result is unknown. With one given as a literal, the result is typed from it.

Type Parameters ​

S ​

S extends string

Parameters ​

typeString ​

S

GVariant type the variant holds, such as "a{sv}".

variant ​

Variant

Variant to read, which has to hold that type.

options ​

FromVariantOptions

Whether to unwrap nested variants recursively.

Returns ​

ParsedValue<S, Uint8Array<ArrayBufferLike>, Variant> | ParsedValue<S, Uint8Array<ArrayBufferLike>, unknown>

The unpacked value.

Throws ​

When the type string is not one complete GVariant type.

Call Signature ​

fromVariant(variant, options?): unknown

Defined in: packages/runtime/dist/variant.d.ts:132

Unpacks a GLib.Variant into the JavaScript value its GVariant type describes, the inverse of toVariant. A dictionary keyed by strings unpacks to a record and one keyed by anything else to a Map, an array to an array, a byte array (ay) to the byte array type the generated bindings use (Uint8Array under the v2ByteArrays future flag, number[] otherwise), a tuple to an array of its members, a maybe to its value or null, and a nested variant to the GLib.Variant itself unless recursive is set, in which case it is unwrapped all the way down.

The type string is optional: without one the variant's own type is read, and the result is unknown. With one given as a literal, the result is typed from it.

Parameters ​

variant ​

Variant

Variant to read, which has to hold that type.

options? ​

FromVariantOptions

Whether to unwrap nested variants recursively.

Returns ​

unknown

The unpacked value.

Throws ​

When the type string is not one complete GVariant type.