lib-bb-portal-model-parser

1.0.0 • Public • Published

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)

Parameter Type Description
stringToDoc Function A function that converts XML string to DOM Document
Returns

ParserAPI - API of the model parser

Type Definitions

ParserAPI

Type: Object

Property Type Description
stringToJs Function Converts XML string to JXON object
jsToString Function Converts JXON object to XML string
normalize Normalize Converts XML string with item to Normalized object.
formalize Formalize Converts Normalized portal model object to XML string

Normalize(xmlString)

Parameter Type Description
xmlString String
Returns

Normalized - Normalized model

Formalize(normalized)

Parameter Type Description
normalized Normalized Normalized model
Returns

String - xml string

Normalized

Type: Object

Property Type Description
tag String Tag name of the first element
attributes Object Hash of first element attributes
model Object Hash of first descendant property name/value pairs
items Array of Normalized Array of descendant Normalized items

ViewHint

Type: Object

Property Type Description
designMode Boolean (optional)
role String (optional) admin, manager, user, none
input String (optional) text-input, checkbox, select-one
order Number (optional)

Property

Type: Object

Property Type Description
name String Name of the property
value String
valueType String (optional)
label String (optional)
manageable String (optional)
readonly String (optional)
itemName String (optional)
viewHint ViewHint (optional)

Tag

Type: Object

Property Type Description
value String
type String (optional)
blacklist String (optional)
manageable String (optional)

Readme

Keywords

none

Package Sidebar

Install

npm i lib-bb-portal-model-parser

Weekly Downloads

277

Version

1.0.0

License

none

Last publish

Collaborators

  • bb-cli
  • backbase-admin