Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5481831711 | |||
| fb606e734b | |||
| e75a939214 | |||
| deda012e03 | |||
| 933a5e0a45 | |||
| bb339b8c85 | |||
| 4fa7b5a4d2 | |||
| 782eda7a6f |
7
package-lock.json
generated
7
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartxml",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.6",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -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",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartxml",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.6",
|
||||
"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",
|
||||
@@ -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"
|
||||
],
|
||||
|
||||
31
test/test.ts
31
test/test.ts
@@ -1,8 +1,35 @@
|
||||
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;
|
||||
let testXml = `
|
||||
<hello>
|
||||
<wow>nice</wow>
|
||||
</hello>
|
||||
`;
|
||||
|
||||
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',
|
||||
url: [{loc: 3},{loc: 3}]
|
||||
}
|
||||
});
|
||||
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();
|
||||
|
||||
20
ts/index.ts
20
ts/index.ts
@@ -1,3 +1,21 @@
|
||||
import * as plugins from './smartxml.plugins';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
||||
export class SmartXml {
|
||||
constructor() {}
|
||||
|
||||
public parseXmlToObject<T = any>(xmlStringArg: string): T {
|
||||
const jsonObject = plugins.fastXmlParser.parse(xmlStringArg);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public createXmlFromObject(jsObject: any): string {
|
||||
const jsToXmlParser = new plugins.fastXmlParser.j2xParser({
|
||||
ignoreAttributes: false,
|
||||
attributeNamePrefix: "@_",
|
||||
format: true,
|
||||
indentBy: ' ',
|
||||
});
|
||||
const xml = jsToXmlParser.parse(jsObject);
|
||||
return '<?xml version="1.0" encoding="UTF-8"?>\n' + xml;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,5 @@
|
||||
const removeme = {};
|
||||
export { removeme };
|
||||
import * as fastXmlParser from 'fast-xml-parser';
|
||||
|
||||
export {
|
||||
fastXmlParser
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user