From 782eda7a6f85bc54caacd8db4e98c1b48cac6e5b Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sat, 24 Oct 2020 16:39:37 +0000 Subject: [PATCH] fix(core): update --- package-lock.json | 5 +++++ package.json | 4 +++- test/test.ts | 16 ++++++++++++++-- ts/index.ts | 15 ++++++++++++++- ts/smartxml.plugins.ts | 7 +++++-- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 93c65e1..0058766 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5156,6 +5156,11 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", "dev": true }, + "fast-xml-parser": { + "version": "3.17.4", + "resolved": "https://verdaccio.lossless.one/fast-xml-parser/-/fast-xml-parser-3.17.4.tgz", + "integrity": "sha512-qudnQuyYBgnvzf5Lj/yxMcf4L9NcVWihXJg7CiU1L+oUCq8MUnFEfH2/nXR/W5uq+yvUN1h7z6s7vs2v1WkL1A==" + }, "fastparse": { "version": "1.1.2", "resolved": "https://verdaccio.lossless.one/fastparse/-/fastparse-1.1.2.tgz", diff --git a/package.json b/package.json index 0520575..bc4ca51 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ "tslint": "^6.1.3", "tslint-config-prettier": "^1.15.0" }, - "dependencies": {}, + "dependencies": { + "fast-xml-parser": "^3.17.4" + }, "browserslist": [ "last 1 chrome versions" ], diff --git a/test/test.ts b/test/test.ts index 1f8023b..ed834b6 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,8 +1,20 @@ import { expect, tap } from '@pushrocks/tapbundle'; import * as smartxml from '../ts/index'; -tap.test('first test', async () => { - console.log(smartxml.standardExport); +let testSmartxml: smartxml.SmartXml; + +tap.test('should create ', async () => { + testSmartxml = new smartxml.SmartXml(); }); +tap.test('should create an xml string', async () => { + const xmlResult = testSmartxml.createXmlFromObject({ + hello: { + wow: 'test' + } + }); + console.log(xmlResult); +}); + + tap.start(); diff --git a/ts/index.ts b/ts/index.ts index b326149..0311dcf 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,3 +1,16 @@ import * as plugins from './smartxml.plugins'; -export let standardExport = 'Hi there! :) This is an exported string'; +export class SmartXml { + constructor() {} + + public parseXmlToObject(xmlStringArg: string): T { + const jsonObject = plugins.fastXmlParser.convertToJson(xmlStringArg); + return jsonObject; + } + + public createXmlFromObject(jsObject: any): string { + const jsToXmlParser = new plugins.fastXmlParser.j2xParser({}); + const xml = jsToXmlParser.parse(jsObject); + return xml; + } +} \ No newline at end of file diff --git a/ts/smartxml.plugins.ts b/ts/smartxml.plugins.ts index 29aa9da..50c0819 100644 --- a/ts/smartxml.plugins.ts +++ b/ts/smartxml.plugins.ts @@ -1,2 +1,5 @@ -const removeme = {}; -export { removeme }; +import * as fastXmlParser from 'fast-xml-parser'; + +export { + fastXmlParser +};