UNPKG

@mikezimm/npmfunctions

Version:
102 lines (99 loc) 3.64 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getArrayOfXMLElements = exports.buildMLineDiv = void 0; var React = __importStar(require("react")); var constants_1 = require("../Regex/constants"); //Used in Easy Contents Panel to convert xml to a string format function buildMLineDiv(indent, element) { var spaces4 = indent > 0 ? '\u00a0' + '\u00a0' + '\u00a0' + '\u00a0' : null; var spaces = ''; var doElement = null; if (typeof element === 'string') { //This splits string for LineFeed character doElement = element.split('
'); } else { doElement = [element]; } if (indent >= 1) { spaces += spaces4; } if (indent >= 2) { spaces += spaces4; } if (indent >= 3) { spaces += spaces4; } if (indent >= 4) { spaces += spaces4; } if (indent >= 5) { spaces += spaces4; } var newDiv = React.createElement("div", null, " ", doElement.map(function (el) { return React.createElement("div", null, spaces, el); })); return newDiv; } exports.buildMLineDiv = buildMLineDiv; function getArrayOfXMLElements(thisXMLString) { console.log('getWebXML thisXMLString:', thisXMLString); var sample = thisXMLString; var xmlArray = []; do { var loc = sample.search(constants_1.RegexXMLOpenProp); if (xmlArray.length === 0) { //Do this to split the xml tag out var firstSlice = sample.slice(0, loc + 1); var loc2 = firstSlice.indexOf(' '); var tag = firstSlice.slice(0, loc2); var prop = firstSlice.slice(loc2 + 1); xmlArray.push(buildMLineDiv(0, tag)); xmlArray.push(buildMLineDiv(2, prop)); } else { xmlArray.push(buildMLineDiv(2, sample.slice(0, loc + 1))); } sample = sample.slice(loc + 2); } while (sample.search(constants_1.RegexXMLOpenProp) > 0); xmlArray.push(buildMLineDiv(2, sample)); console.log('getWebXML:', sample, xmlArray); /* let x = sample.search(RegexXMLOpenProp); function testMe(str, index, replacement) { return str.substr(0, index + 1) + replacement + str.substr(index + 2); } let newV = testMe(sample,x,'---'); console.log(newV); */ return xmlArray; } exports.getArrayOfXMLElements = getArrayOfXMLElements; //# sourceMappingURL=formating.js.map