feat(core): Upgrade dependencies and enhance XML parsing and building
This commit is contained in:
parent
431d97c4b1
commit
3ca651bc9a
28
changelog.md
Normal file
28
changelog.md
Normal 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
|
14
package.json
14
package.json
@ -13,15 +13,15 @@
|
|||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.25",
|
"@git.zone/tsbuild": "^2.2.0",
|
||||||
"@git.zone/tsbundle": "^2.0.10",
|
"@git.zone/tsbundle": "^2.1.0",
|
||||||
"@git.zone/tsrun": "^1.2.46",
|
"@git.zone/tsrun": "^1.3.3",
|
||||||
"@git.zone/tstest": "^1.0.44",
|
"@git.zone/tstest": "^1.0.90",
|
||||||
"@push.rocks/tapbundle": "^5.0.15",
|
"@push.rocks/tapbundle": "^5.5.4",
|
||||||
"@types/node": "^20.8.7"
|
"@types/node": "^22.10.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-xml-parser": "^4.3.2"
|
"fast-xml-parser": "^4.5.1"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
|
11881
pnpm-lock.yaml
generated
11881
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
11
test/test.ts
11
test/test.ts
@ -2,11 +2,7 @@ import { expect, tap } from '@push.rocks/tapbundle';
|
|||||||
import * as smartxml from '../ts/index.js';
|
import * as smartxml from '../ts/index.js';
|
||||||
|
|
||||||
let testSmartxml: smartxml.SmartXml;
|
let testSmartxml: smartxml.SmartXml;
|
||||||
let testXml = `
|
let testXml = '';
|
||||||
<hello>
|
|
||||||
<wow>nice</wow>
|
|
||||||
</hello>
|
|
||||||
`;
|
|
||||||
|
|
||||||
tap.test('should create an instance', async () => {
|
tap.test('should create an instance', async () => {
|
||||||
testSmartxml = new smartxml.SmartXml();
|
testSmartxml = new smartxml.SmartXml();
|
||||||
@ -22,13 +18,14 @@ tap.test('should create an xml string', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(xmlResult);
|
console.log(xmlResult);
|
||||||
|
testXml = xmlResult;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should parse an yml file', async () => {
|
tap.test('should parse an yml file', async () => {
|
||||||
const jsObject = testSmartxml.parseXmlToObject(testXml);
|
const jsObject = testSmartxml.parseXmlToObject(testXml);
|
||||||
console.log(jsObject);
|
// console.log(JSON.stringify(jsObject, null, 2));
|
||||||
expect(typeof jsObject).toEqual('object');
|
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');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartxml',
|
name: '@push.rocks/smartxml',
|
||||||
version: '1.0.8',
|
version: '1.1.0',
|
||||||
description: 'a package for creating and parsing xml formated files'
|
description: 'A package for creating and parsing XML formatted files.'
|
||||||
}
|
}
|
||||||
|
18
ts/index.ts
18
ts/index.ts
@ -4,19 +4,25 @@ export class SmartXml {
|
|||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
public parseXmlToObject<T = any>(xmlStringArg: string): T {
|
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);
|
const jsonObject = parser.parse(xmlStringArg);
|
||||||
return jsonObject;
|
return jsonObject as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
public createXmlFromObject(jsObject: any): string {
|
public createXmlFromObject(jsObject: any): string {
|
||||||
const jsToXmlParser = new plugins.fastXmlParser.XMLBuilder({
|
const builder = new plugins.fastXmlParser.XMLBuilder({
|
||||||
ignoreAttributes: false,
|
ignoreAttributes: false,
|
||||||
attributeNamePrefix: "@_",
|
attributeNamePrefix: '@_',
|
||||||
format: true,
|
format: true,
|
||||||
indentBy: ' ',
|
indentBy: ' '
|
||||||
});
|
});
|
||||||
const xml = jsToXmlParser.build(jsObject);
|
const xml = builder.build(jsObject);
|
||||||
return '<?xml version="1.0" encoding="UTF-8"?>\n' + xml;
|
return '<?xml version="1.0" encoding="UTF-8"?>\n' + xml;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user