Skip to content

API Reference / @gtkx/runtime / toVariant

Variable: toVariant

const toVariant: <S>(typeString, value) => GLib.Variant

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

Packs a JavaScript value into the GLib.Variant a GVariant type string describes, building the nested arrays, dictionaries, tuples and maybes the type calls for. A type string given as a literal also types value, so "as" takes an array of strings, "a{sv}" a record of variants, "(si)" a string and a number pair, a 64-bit type a bigint, and "ay" a Uint8Array or an array of byte values.

Type Parameters

S

S extends string

Parameters

typeString

S

GVariant type of the variant to build, such as "a{sv}".

value

VariantInput<S>

Value to pack, shaped the way typeString describes.

Returns

GLib.Variant

The packed variant.

Throws

When the type string is not one complete GVariant type, when a value packed as an object path or a type signature is not a valid one, or when a byte array is packed from anything but a Uint8Array or an array of byte values.

Released under the MPL-2.0 License.