1.0.0 • Published 7 years ago

lib-bb-portal-model-parser v1.0.0

Weekly downloads
658
License
-
Repository
-
Last release
7 years ago

lib-bb-portal-model-parser

Version: 1.0.0

Example

import modelParser from 'lib-bb-portal-model-parser';
// browser
const DOMParser = window.DOMParser;
// Node.js
import { DOMParser } from 'xmldom';

const stringToDoc = str => new DOMParser().parseFromString(str, 'application/xml');
const {
  stringToJs,
  jsToString,
  normalize,
  formalize
} = modelParser(stringToDoc);

let xmlString = '<...>';
const normalized = normalize(xmlString);
const bbModel = normalized.items[0].model;

const name = bbModel.name;
const extends = bbModel.extendedItemName;
const title = bbModel.properties
  .find(prop => prop.name === 'label')
  .value;
const isCatalog = bbModel.tags.find(tag => tag.type === 'catalogItem');

bbModel.tags.push({ type: 'foo', value: 'bar' });

xmlString = formalize(normalized);

Table of Contents

  • Exports default(stringToDoc)
  • Type Definitions ParserAPI Normalize(xmlString) Formalize(normalized) Normalized ViewHint Property Tag

Exports

default(stringToDoc)

ParameterTypeDescription
stringToDocFunctionA function that converts XML string to DOM Document
Returns

ParserAPI - API of the model parser

Type Definitions

ParserAPI

Type: Object

PropertyTypeDescription
stringToJsFunctionConverts XML string to JXON object
jsToStringFunctionConverts JXON object to XML string
normalizeNormalizeConverts XML string with item to Normalized object.
formalizeFormalizeConverts Normalized portal model object to XML string

Normalize(xmlString)

ParameterTypeDescription
xmlStringString
Returns

Normalized - Normalized model

Formalize(normalized)

ParameterTypeDescription
normalizedNormalizedNormalized model
Returns

String - xml string

Normalized

Type: Object

PropertyTypeDescription
tagStringTag name of the first element
attributesObjectHash of first element attributes
modelObjectHash of first descendant property name/value pairs
itemsArray of NormalizedArray of descendant Normalized items

ViewHint

Type: Object

PropertyTypeDescription
designModeBoolean (optional)
roleString (optional)admin, manager, user, none
inputString (optional)text-input, checkbox, select-one
orderNumber (optional)

Property

Type: Object

PropertyTypeDescription
nameStringName of the property
valueString
valueTypeString (optional)
labelString (optional)
manageableString (optional)
readonlyString (optional)
itemNameString (optional)
viewHintViewHint (optional)

Tag

Type: Object

PropertyTypeDescription
valueString
typeString (optional)
blacklistString (optional)
manageableString (optional)