1.1.7 • Published 9 months ago

jui-builder v1.1.7

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

JUIBuilder

The JUIBuilder provides a simple and customizable way to generate dynamic HTML content based on structured JSON data.

Features

  • Convert JSON data to HTML markup
  • Define custom mapping between JSON keys and HTML elements
  • Support for nested JSON objects and arrays
  • Customizable class names and attributes for HTML elements
  • Basic validation of JSON data against a JSON schema

Limitations

  • Referenced data is not processed: If the JSON data contains references to other objects, the JUIBuilder will display placeholder values for these objects, which need further processing to show actual data.

Installation

In your terminal run npm i jui-builder

Usage

Here is an example on how to use this framework:

// (Optional) Define the element configuration map by matching the JSON properties of your data to HTML element references.
// The name of the element needs to match the name of the JSON-property. Per element you can define tag (HTML reference), style (CSS styling), class (HTML class) and sublevel.
// Use sublevel if the JSON property has nested objects, which you want to style specifically. In the sublevel you can define tag and style.
const elementConfigMap = {
    age: {
        tag: 'h3',
        subLevel: {
            name: {
                tag: 'p'
            }
        }
    },
    lastName: {
        tag: 'p',
        style: 'padding: 10px;'
    },
};

// Create an instance of the JUIBuilder class (optionally with own elementConfigMap else leave parameters empty)
const converter = new JUIBuilder(elementConfigMap);

/* (Optional) Define your JSON schema
*/ Define your own JSON schema for the JSON data you want to convert to HTML. The JSON schema needs to follow the 2020-12 schema standard. 
const jsonSchemaOne = {
    "$id": "https://example.com/person.schema.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "Person",
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string",
            "description": "The person's first name."
        },
        "lastName": {
            "type": "string",
            "description": "The person's last name."
        },
        "age": {
            "description": "Age in years which must be equal to or greater than zero.",
            "type": "integer",
            "minimum": 0
        }
    }
};

// Define your JSON data which you want to convert to HTML
const example = {
    "firstName": "John",
    "lastName": "Doe",
    "age": 21
};

// Convert the JSON data to HTML (optional with own jsonSchema else leave parameters empty)
const html = converter.processEventData(jsonData, jsonSchema);
1.1.7

9 months ago

1.1.6

9 months ago

1.1.5

9 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.9

9 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago