npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gststructure

v0.1.1

Published

Pure TypeScript parser for GStreamer Structure and Caps serialization format

Downloads

478

Readme

gststructure

Pure TypeScript parser and serializer for the GStreamer Structure and Caps serialization format. No runtime dependencies.

Installation

npm install gststructure

Usage

Parsing a GstStructure

import { GstStructure } from 'gststructure';

const s = GstStructure.fromString(
  'video/x-raw, format=I420, width=1920, height=1080, framerate=30/1'
);

s.name; // → 'video/x-raw'
s['width']; // → 1920
s['format']; // → 'I420'
s['framerate']; // → { numerator: 30, denominator: 1 }
s['loop']; // → undefined  (missing fields return undefined)

Field access via s['fieldName'] returns plain JavaScript values — no type wrapper. For the full typed Value object use getTyped():

s.getTyped('width'); // → { type: 'int', value: 1920 }
s.getTyped('framerate'); // → { type: 'fraction', numerator: 30, denominator: 1 }

parseStructure() is a convenient alternative that returns null on invalid input instead of throwing:

import { parseStructure } from 'gststructure';

const s = parseStructure('video/x-raw, format=I420')!;
s['format']; // → 'I420'

Parsing GstCaps

import { parseCaps } from 'gststructure';

// Special caps
parseCaps('ANY'); // { type: 'any' }
parseCaps('EMPTY'); // { type: 'empty' }

// One or more structures separated by ';'
const caps = parseCaps('video/x-raw, format=I420; audio/x-raw, rate=44100');
// caps.type === 'structures'
// caps.entries[0].structure.name === 'video/x-raw'
// caps.entries[1].structure.name === 'audio/x-raw'

// With capability features
const dmabuf = parseCaps('video/x-raw(memory:DMABuf), format=NV12');
// dmabuf.entries[0].features === ['memory:DMABuf']

Serializing back to string

import { GstStructure, capsToString, parseCaps } from 'gststructure';

const s = GstStructure.fromString('seek, start=5.0, stop=10.0, flags=flush+accurate');
s.toString();
// → 'seek, start=(double)5.0, stop=(double)10.0, flags=flush+accurate'

const caps = parseCaps('video/x-raw, format=I420; audio/x-raw, rate=44100')!;
capsToString(caps);
// → 'video/x-raw, format="I420"; audio/x-raw, rate=(int)44100'

Error handling

parseStructure and parseCaps return null on invalid input. Use the OrThrow variants to get a ParseError instead:

import { GstStructure, parseCapsOrThrow, ParseError } from 'gststructure';

try {
  GstStructure.fromString('=invalid');
} catch (e) {
  if (e instanceof ParseError) {
    console.error(e.message); // includes position info
  }
}

Supported value types

| GStreamer type | Example | s['field'] returns | | ------------------- | ---------------------------------- | -------------------------------------------- | | Integer | 42, (int)42, 0xFF | number | | Float | 3.14, (float)1.0 | number | | Boolean | true, yes, t, (bool)1 | boolean | | String | "hello", (string)world | string | | Fraction | 30/1 | { numerator: number; denominator: number } | | Bitmask | (bitmask)0x67 | bigint | | Flags | flush+accurate | string[] | | GstValueList | { 1, 2, 3 } | unknown[] (recursively unwrapped) | | GstValueArray | < 1, 2, 3 > | unknown[] (recursively unwrapped) | | Range | [ 0, 255 ], [ 0, 255, 2 ] | { min, max, step? } (unwrapped) | | Nested GstStructure | (GstStructure)"name, field=val;" | GstStructure | | Nested GstCaps | (GstCaps)"video/x-raw" | Caps |

Type inference for unquoted values follows GStreamer's own order: int → double → fraction → flags → boolean → string.

API

// Primary class
class GstStructure {
  static fromString(s: string): GstStructure; // throws ParseError on failure
  readonly name: string;
  readonly fields: Map<string, Value>; // typed access
  [key: string]: unknown; // dict-like access (unwrapped)
  getTyped(key: string): Value | undefined;
  toString(): string;
}

// Functional API
function parseStructure(s: string): GstStructure | null;
function parseStructureOrThrow(s: string): GstStructure;
function parseCaps(s: string): Caps | null;
function parseCapsOrThrow(s: string): Caps;

// Serialization
function structureToString(s: Structure): string;
function capsToString(c: Caps): string;
function valueToString(v: Value): string; // with explicit type prefix
function valueToStringBare(v: Value): string; // without prefix for scalars
function unwrapValue(v: Value): unknown; // unwrap to plain JS value

License

MIT