Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e75a939214 | |||
| deda012e03 | |||
| 933a5e0a45 | |||
| bb339b8c85 |
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartxml",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartxml",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.5",
|
||||
"private": false,
|
||||
"description": "a package for creating and parsing xml formated files",
|
||||
"main": "dist_ts/index.js",
|
||||
@@ -9,7 +9,7 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)"
|
||||
"build": "(tsbuild --web && tsbundle npm)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
|
||||
16
test/test.ts
16
test/test.ts
@@ -2,19 +2,33 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartxml from '../ts/index';
|
||||
|
||||
let testSmartxml: smartxml.SmartXml;
|
||||
let testXml = `
|
||||
<hello>
|
||||
<wow>nice</wow>
|
||||
</hello>
|
||||
`;
|
||||
|
||||
tap.test('should create ', async () => {
|
||||
tap.test('should create an instance', async () => {
|
||||
testSmartxml = new smartxml.SmartXml();
|
||||
});
|
||||
|
||||
tap.test('should create an xml string', async () => {
|
||||
const xmlResult = testSmartxml.createXmlFromObject({
|
||||
hello: {
|
||||
"@_xlmns:teststring": "hellothere",
|
||||
"@_xlmns:testnumber": 10,
|
||||
wow: 'test'
|
||||
}
|
||||
});
|
||||
console.log(xmlResult);
|
||||
});
|
||||
|
||||
tap.test('should parse an yml file', async () => {
|
||||
const jsObject = testSmartxml.parseXmlToObject(testXml);
|
||||
console.log(jsObject);
|
||||
expect(typeof jsObject).to.equal('object');
|
||||
expect(jsObject).property('hello').property('wow').to.equal('nice');
|
||||
});
|
||||
|
||||
|
||||
tap.start();
|
||||
|
||||
@@ -4,12 +4,15 @@ export class SmartXml {
|
||||
constructor() {}
|
||||
|
||||
public parseXmlToObject<T = any>(xmlStringArg: string): T {
|
||||
const jsonObject = plugins.fastXmlParser.convertToJson(xmlStringArg);
|
||||
const jsonObject = plugins.fastXmlParser.parse(xmlStringArg);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public createXmlFromObject(jsObject: any): string {
|
||||
const jsToXmlParser = new plugins.fastXmlParser.j2xParser({});
|
||||
const jsToXmlParser = new plugins.fastXmlParser.j2xParser({
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: "@_"
|
||||
});
|
||||
const xml = jsToXmlParser.parse(jsObject);
|
||||
return xml;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user