feat(core): Upgrade dependencies and enhance XML parsing and building

This commit is contained in:
Philipp Kunz 2024-12-30 20:57:27 +01:00
parent 431d97c4b1
commit 3ca651bc9a
6 changed files with 7985 additions and 3981 deletions

28
changelog.md Normal file
View File

@ -0,0 +1,28 @@
# Changelog
## 2024-12-30 - 1.1.0 - feat(core)
Upgrade dependencies and enhance XML parsing and building
- Updated fast-xml-parser dependency to version ^4.5.1
- Enhanced XML parsing to preserve order and handle attributes
- Refactored createXmlFromObject method with a new XMLBuilder implementation
- Improved test coverage for XML string creation and parsing
## 2024-05-29 - 1.0.8 - Various Updates
Minor updates and improvements to configuration and documentation.
- Updated project description
- Modified `tsconfig` file
- Updated `npmextra.json`: githost
## 2023-10-20 - 1.0.6 to 1.0.8 - Core Fixes and Updates
Maintenance and core updates with improvements in project configuration.
- Core functionality fixes and updates
- Configuration updates
- Preparation for versioning to 1.0.8
## 2020-10-24 - 1.0.1 to 1.0.6 - Core Fixes
Multiple fixes and enhancements in core components.
- Series of core updates to improve stability and performance

View File

@ -13,15 +13,15 @@
"buildDocs": "tsdoc"
},
"devDependencies": {
"@git.zone/tsbuild": "^2.1.25",
"@git.zone/tsbundle": "^2.0.10",
"@git.zone/tsrun": "^1.2.46",
"@git.zone/tstest": "^1.0.44",
"@push.rocks/tapbundle": "^5.0.15",
"@types/node": "^20.8.7"
"@git.zone/tsbuild": "^2.2.0",
"@git.zone/tsbundle": "^2.1.0",
"@git.zone/tsrun": "^1.3.3",
"@git.zone/tstest": "^1.0.90",
"@push.rocks/tapbundle": "^5.5.4",
"@types/node": "^22.10.2"
},
"dependencies": {
"fast-xml-parser": "^4.3.2"
"fast-xml-parser": "^4.5.1"
},
"browserslist": [
"last 1 chrome versions"

11889
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,7 @@ import { expect, tap } from '@push.rocks/tapbundle';
import * as smartxml from '../ts/index.js';
let testSmartxml: smartxml.SmartXml;
let testXml = `
<hello>
<wow>nice</wow>
</hello>
`;
let testXml = '';
tap.test('should create an instance', async () => {
testSmartxml = new smartxml.SmartXml();
@ -22,13 +18,14 @@ tap.test('should create an xml string', async () => {
}
});
console.log(xmlResult);
testXml = xmlResult;
});
tap.test('should parse an yml file', async () => {
const jsObject = testSmartxml.parseXmlToObject(testXml);
console.log(jsObject);
// console.log(JSON.stringify(jsObject, null, 2));
expect(typeof jsObject).toEqual('object');
expect(jsObject).property('hello').property('wow').toEqual('nice');
expect(jsObject).arrayItem(1).property('hello').arrayItem(0).property('wow').arrayItem(0).property('#text').toEqual('test');
});

View File

@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartxml',
version: '1.0.8',
description: 'a package for creating and parsing xml formated files'
version: '1.1.0',
description: 'A package for creating and parsing XML formatted files.'
}

View File

@ -4,19 +4,25 @@ export class SmartXml {
constructor() {}
public parseXmlToObject<T = any>(xmlStringArg: string): T {
const parser = new plugins.fastXmlParser.XMLParser();
const parser = new plugins.fastXmlParser.XMLParser({
preserveOrder: true,
ignoreAttributes: false,
parseTagValue: true,
parseAttributeValue: true,
// ignoreDeclaration: true
});
const jsonObject = parser.parse(xmlStringArg);
return jsonObject;
return jsonObject as T;
}
public createXmlFromObject(jsObject: any): string {
const jsToXmlParser = new plugins.fastXmlParser.XMLBuilder({
const builder = new plugins.fastXmlParser.XMLBuilder({
ignoreAttributes: false,
attributeNamePrefix: "@_",
attributeNamePrefix: '@_',
format: true,
indentBy: ' ',
indentBy: ' '
});
const xml = jsToXmlParser.build(jsObject);
const xml = builder.build(jsObject);
return '<?xml version="1.0" encoding="UTF-8"?>\n' + xml;
}
}