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 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphics-data-definition

v1.1.1

Published

This library contains a few useful tools for javascript developers when working with the [Graphics Data Definition](https://github.com/SuperFlyTV/GraphicsDataDefinition). It can be used in the browser or Node.js.

Downloads

51

Readme

GraphicsDataDefinition javascript library

This library contains a few useful tools for javascript developers when working with the Graphics Data Definition. It can be used in the browser or Node.js.

Installation

npm install graphics-data-definition

How to use

Validating schema and data

// Typescript
import {
    validateData,
    getDefaultDataFromSchema,
    setupSchemaValidator,
    GDDSchema
} from 'graphics-data-definition'
import fetch from 'node-fetch'

;(async () => {
// This object represents a GDD Schema that have been read from a graphics template:
const mySchema: GDDSchema = {
    "$schema": "https://superflytv.github.io/GraphicsDataDefinition/gdd-meta-schema/v1/schema.json",
    "title": "One-Line GFX Template",
    "type": "object",
    "properties": {
        "text0": {
            "type": "string",
            "gddType": "single-line",
        },
        "color": {
            "type": "string",
            "gddType": "color-rrggbb",
            "pattern": '^#[0-9a-f]{6}$',
            "default": "#000000"
        }
    },
}
// This object represents the data that comes from the user input form:
const myData = {
    text0: "This is the text!"
}

// Verify that the schema is valid: -------------------------------------------
const schemaValidator = await setupSchemaValidator({
    fetch: async (url) => {
        return await (await fetch(url)).json()
    }
})
const schemaValidateResult = schemaValidator.validate(mySchema)
if (schemaValidateResult === null) console.log('Schema is valid!')
else console.log('Schema is not valid: ' + schemaValidateResult)

// Validate that the data is correct: -----------------------------------------
const dataValidateResult = validateData(mySchema, myData)
if (dataValidateResult === null) console.log('Data is valid!')
else console.log('Data is not valid: ' + schemaValidateResult)

// Generate a default data-object, to use for prefilling: ---------------------
const defaultData = getDefaultDataFromSchema(mySchema)
console.log('Default Data from schema: ' + JSON.stringify(defaultData))

})().catch(console.error)

Building a GUI

See Reference-GUI for example implementation,

// Typescript
import {
    validateData,
    getDefaultDataFromSchema,
    setupSchemaValidator,
    GDDSchema,
    GDDTypes
} from 'graphics-data-definition'


function drawGUIComponent(schema: GDDSchemaProperty) {
    const gddSchema = schema as GDDTypes

    // Handle GDD Types:
    if (gddSchema.type === 'string') {
        if (gddSchema.gddType === 'single-line') return drawGUIComponentSingleLine(innerProps)
        else if (gddSchema.gddType === 'multi-line') return drawGUIComponentMultiLine(innerProps)
        // etc ...
    } else if (gddSchema.type === 'integer') {
		if (gddSchema.gddType === 'select') return drawGUIComponentSelect(innerProps)
        // etc ...
    } // else if () etc ...


    // Handle basic types:
    const basicType = getBasicType(schema.type)

    if (basicType === 'boolean') return drawGUIComponentBoolean(innerProps)
    if (basicType === 'string') return drawGUIComponentString(innerProps)
    if (basicType === 'number') return drawGUIComponentNumber(innerProps)
    if (basicType === 'integer') return drawGUIComponentInteger(innerProps)
    if (basicType === 'array') return drawGUIComponentArray(innerProps)
    if (basicType === 'object') return drawGUIComponentObject(innerProps)

    // Fallback:
    return drawGUIComponentUnknown({ ...innerProps, basicType })
}