JHson.js - Documentation - Public Functions

Below is a list of all the public API functions that can be called from a JHson.js service.

Download Now

v2.3.0 - 9th Sep 2024
Functions

JSON:

json():

Returns all the chained functions that will allow an HTML DOM element to be converted to JSON.
Returns: 'Object' - The JSON properties object.

json() > includeAttributes( flag ):

States if the attributes should be included.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The JSON properties object.

json() > includeDataAttributes( flag ):

States if the data attributes should be included.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The JSON properties object.

json() > includeCssProperties( flag ):

States if the CSS style properties should be included.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to false).
Returns: 'Object' - The JSON properties object.

json() > includeText( flag ):

States if the node text should be included.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The JSON properties object.

json() > includeChildren( flag ):

States if the children should be included.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The JSON properties object.

json() > includeImagesAsBase64( flag ):

States if the image source attribute should be included as Base 64 URLs.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to false).
Returns: 'Object' - The JSON properties object.

json() > friendlyFormat( flag ):

States if the JSON should be formatted in an easy-to-read layout.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The JSON properties object.

json() > indentSpaces( spaces ):

States the total indent spaces that should be used for the friendly format JSON.
Parameter: spaces: 'number' - The spaces value that should be used (defaults to 2).
Returns: 'Object' - The JSON properties object.

json() > ignoreNodeTypes( types ):

States the node types that should not be included in the JSON.
Parameter: types: 'Object' - The node types to ignore (can be an array of strings, or a space-separated string, and defaults to []).
Returns: 'Object' - The JSON properties object.

json() > ignoreNodeCondition( func ):

States the condition function (parameters being element:HtmlElement, and return value being a boolean) to use to state if an element should be included in the JSON.
Parameter: func: 'function' - The condition function to use to check if a element should be included (defaults to null).
Returns: 'Object' - The JSON properties object.

json() > ignoreCssProperties( cssProperties ):

States the CSS properties that should not be included in the JSON.
Parameter: cssProperties: 'Object' - The CSS properties to ignore (can be an array of strings, or a space-separated string, and defaults to []).
Returns: 'Object' - The JSON properties object.

json() > ignoreAttributes( attributes ):

States the attributes that should not be included in the JSON.
Parameter: attributes: 'Object' - The attributes to ignore (can be an array of strings, or a space-separated string, and defaults to []).
Returns: 'Object' - The JSON properties object.

json() > generateUniqueMissingIds( flag ):

States if the JSON should include unique IDs for DOM elements that don't have them set already.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to false).
Returns: 'Object' - The JSON properties object.

json() > generateUniqueMissingNames( flag ):

States if the JSON should include unique name for DOM elements that don't have them set already.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to false).
Returns: 'Object' - The JSON properties object.

json() > propertyReplacer( func ):

States the property replacer function (parameters being Key:string, Value:any) to use for Keys and Values written for the JSON.
Parameter: func: 'function' - The replacer function to use when writing the JSON (defaults to null).
Returns: 'Object' - The JSON properties object.

json() > get( element ):

Uses all the options selected via the chained functions to get the JSON from the HTML DOM element.
Parameter: element: 'Object' - The DOM element to get the JSON for.
Returns: 'string' - The JSON string.

json() > getVariables( json ):

Uses all the options selected via the chained functions to get the template variables from a JSON string.
Parameter: json: 'string' - The JSON to get the template variables from.
Returns: 'string[]' - The template variables.



HTML:

html():

Returns all the chained functions that will allow JSON to be written as HTML DOM elements.
Returns: 'Object' - The HTML properties object.

html() > json( json ):

States the JSON that should be written as HTML DOM elements.
Parameter: json: 'string' - The JSON that should be converted to HTML.
Returns: 'Object' - The HTML properties object.

html() > templateData( templateData ):

States the template data that should be used inside each HTML DOM elements HTML.
Parameter: templateData: 'Object' - The template data to set inside each node's HTML.
Returns: 'Object' - The HTML properties object.

html() > removeOriginalAttributes( flag ):

States if the original attributes on the element should be removed.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > removeOriginalDataAttributes( flag ):

States if the original data attributes on the element should be removed.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > clearOriginalHTML( flag ):

States if the original HTML in the element should be cleared.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > addCssToHead( flag ):

States if the CSS style properties should be written to a "style" tag in the HTML documents HEAD DOM element.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to false).
Returns: 'Object' - The HTML properties object.

html() > clearCssFromHead( flag ):

States if all the CSS style tags should be cleared from the HTML documents HEAD DOM element.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to false).
Returns: 'Object' - The HTML properties object.

html() > logTemplateDataWarnings( flag ):

States if the template data variables not found in any data are logged as warnings.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to false).
Returns: 'Object' - The HTML properties object.

html() > addAttributes( flag ):

States if the attributes should be written for each element.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > addDataAttributes( flag ):

States if the data attributes should be written for each element.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > addCssProperties( flag ):

States if the CSS properties should be written for each element.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > addText( flag ):

States if the text should be written for each element.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > addChildren( flag ):

States if the children should be written for each element.
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > insertBefore( flag ):

States if the elements should be added before the first detected child (if clearing the HTML is turned off).
Parameter: flag: 'boolean' - The boolean flag that states the condition (defaults to true).
Returns: 'Object' - The HTML properties object.

html() > write( element ):

Uses all the options selected via the chained functions to convert the JSON into HTML DOM elements.
Parameter: element: 'Object' - The DOM element to add the new JSON HTML nodes to.
Returns: 'Object' - The JHson.js class instance.

html() > get():

Uses all the options selected via the chained functions to convert the JSON into HTML DOM element.
Returns: 'Object' - The HTML DOM element created from the JSON.

html() > getVariables( element ):

Uses all the options selected via the chained functions to get the template variables from a HTML DOM element.
Parameter: element: 'Object' - The DOM element to get the template variables from.
Returns: 'string[]' - The template variables.



Rendering:

render( element, options ):

Renders an element using the options specified.
Parameter: element: 'Object' - The element to render.
Parameter: options: 'Object' - All the binding options that should be set (refer to "Binding Options" documentation for properties).
Returns: 'Object' - The JHson.js class instance.

renderAll():

Finds all new elements and renders them.
Returns: 'Object' - The JHson.js class instance.



Configuration:

setConfiguration( newConfiguration ):

Sets the specific configuration options that should be used.
Parameter: newConfiguration: 'Object' - All the configuration options that should be set (refer to "Configuration Options" documentation for properties).
Returns: 'Object' - The JHson.js class instance.



Additional Data:

getVersion():

Returns the version of JHson.js.
Returns: 'string' - The version number.