Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 91ae580914 | |||
| e7f6805eab | |||
| 292e558d51 | |||
| c2c50583f0 | |||
| 403f9c5757 | |||
| 3ca651bc9a | |||
| 431d97c4b1 | |||
| c9d6ffe7ab | |||
| 3d375ad00d | |||
| a4da0a7dd7 | |||
| 19c2128c2a | |||
| e72bdd1dcf | |||
| 39e38d516b | |||
| bf92c2ccb3 | |||
| 77c2433edc | |||
| 5481831711 | |||
| fb606e734b | |||
| e75a939214 | |||
| deda012e03 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @ship.zone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @git.zone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,7 +3,6 @@
|
|||||||
# artifacts
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
pages/
|
|
||||||
|
|
||||||
# installs
|
# installs
|
||||||
node_modules/
|
node_modules/
|
||||||
@@ -17,4 +16,8 @@ node_modules/
|
|||||||
dist/
|
dist/
|
||||||
dist_*/
|
dist_*/
|
||||||
|
|
||||||
# custom
|
# AI
|
||||||
|
.claude/
|
||||||
|
.serena/
|
||||||
|
|
||||||
|
#------# custom
|
||||||
137
.gitlab-ci.yml
137
.gitlab-ci.yml
@@ -1,137 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --production --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
auditDevDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command npm audit --audit-level=high --only=dev
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g tslint typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command tsdoc
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
||||||
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
67
changelog.md
Normal file
67
changelog.md
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2025-11-19 - 2.0.0 - BREAKING CHANGE(core)
|
||||||
|
Implement custom XmlBuilder, remove xmlbuilder2, upgrade fast-xml-parser, update SmartXml API, tests and CI
|
||||||
|
|
||||||
|
- Add a new chainable XmlBuilder implementation (create(), ele(), txt(), att(), up(), com(), end(), toString()) and export it from the package
|
||||||
|
- Remove xmlbuilder2 dependency and its export from smartxml.plugins.ts
|
||||||
|
- Upgrade fast-xml-parser dependency to ^5.3.2 and use it for parsing and building XML
|
||||||
|
- Update SmartXml to use XmlBuilder.create() as the create factory and export XmlBuilder for direct use
|
||||||
|
- Extend and update tests to cover the new XmlBuilder chainable API and XML serialization behavior
|
||||||
|
- Update CI workflows: switch container IMAGE registry, adjust NPMCI_COMPUTED_REPOURL and change pnpm install target for npmci package name
|
||||||
|
- Bump several devDependencies, add pnpm packageManager/pnpm metadata, and apply small tsconfig/.gitignore cleanups
|
||||||
|
|
||||||
|
## 2025-11-19 - 1.2.0 - feat(core)
|
||||||
|
|
||||||
|
Implement custom XmlBuilder with chainable API and upgrade dependencies
|
||||||
|
|
||||||
|
- **BREAKING**: Removed xmlbuilder2 dependency (replaced with custom implementation)
|
||||||
|
- Upgraded fast-xml-parser from 4.5.1 to 5.3.2
|
||||||
|
- Implemented custom XmlBuilder class with fluent/chainable API
|
||||||
|
- `.ele(name, attrs)` - Add elements
|
||||||
|
- `.txt(content)` - Add text content
|
||||||
|
- `.att(name, value)` - Add attributes
|
||||||
|
- `.up()` - Navigate to parent
|
||||||
|
- `.end(options)` - Serialize to XML
|
||||||
|
- Added comprehensive tests for XmlBuilder functionality
|
||||||
|
- Maintains API compatibility: `smartxml.create()` continues to work
|
||||||
|
- Browser-compatible implementation (no Node.js dependencies)
|
||||||
|
- Export XmlBuilder class for direct usage
|
||||||
|
|
||||||
|
## 2024-12-30 - 1.1.1 - fix(dependencies)
|
||||||
|
|
||||||
|
Added missing xmlbuilder2 dependency and relevant exports
|
||||||
|
|
||||||
|
- Added xmlbuilder2 to dependencies in package.json
|
||||||
|
- Export xmlbuilder2 functionality from smartxml.plugins.ts and ts/index.ts
|
||||||
|
|
||||||
|
## 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
|
||||||
@@ -2,17 +2,28 @@
|
|||||||
"gitzone": {
|
"gitzone": {
|
||||||
"projectType": "npm",
|
"projectType": "npm",
|
||||||
"module": {
|
"module": {
|
||||||
"githost": "gitlab.com",
|
"githost": "code.foss.global",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "push.rocks",
|
||||||
"gitrepo": "smartxml",
|
"gitrepo": "smartxml",
|
||||||
"shortDescription": "a package for creating and parsing xml formated files",
|
"description": "A package for creating and parsing XML formatted files.",
|
||||||
"npmPackagename": "@pushrocks/smartxml",
|
"npmPackagename": "@push.rocks/smartxml",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks",
|
||||||
|
"keywords": [
|
||||||
|
"XML",
|
||||||
|
"parsing",
|
||||||
|
"XML creation",
|
||||||
|
"fast-xml-parser",
|
||||||
|
"TypeScript",
|
||||||
|
"data serialization"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
11025
package-lock.json
generated
11025
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@@ -1,27 +1,27 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartxml",
|
"name": "@push.rocks/smartxml",
|
||||||
"version": "1.0.4",
|
"version": "2.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a package for creating and parsing xml formated files",
|
"description": "A package for creating and parsing XML formatted files.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web && tsbundle npm)"
|
"build": "(tsbuild --web && tsbundle npm)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@git.zone/tsbuild": "^3.1.0",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@git.zone/tsbundle": "^2.5.2",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@git.zone/tsrun": "^2.0.0",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@git.zone/tstest": "^2.8.2",
|
||||||
"@types/node": "^14.11.2",
|
"@push.rocks/tapbundle": "^6.0.3",
|
||||||
"tslint": "^6.1.3",
|
"@types/node": "^22.10.2"
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fast-xml-parser": "^3.17.4"
|
"fast-xml-parser": "^5.3.2"
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
@@ -37,5 +37,26 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
]
|
],
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://code.foss.global/push.rocks/smartxml.git"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://code.foss.global/push.rocks/smartxml/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://code.foss.global/push.rocks/smartxml#readme",
|
||||||
|
"type": "module",
|
||||||
|
"keywords": [
|
||||||
|
"XML",
|
||||||
|
"parsing",
|
||||||
|
"XML creation",
|
||||||
|
"fast-xml-parser",
|
||||||
|
"TypeScript",
|
||||||
|
"data serialization"
|
||||||
|
],
|
||||||
|
"packageManager": "pnpm@10.18.1+sha512.77a884a165cbba2d8d1c19e3b4880eee6d2fcabd0d879121e282196b80042351d5eb3ca0935fa599da1dc51265cc68816ad2bddd2a2de5ea9fdf92adbec7cd34",
|
||||||
|
"pnpm": {
|
||||||
|
"overrides": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10682
pnpm-lock.yaml
generated
Normal file
10682
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
138
readme.md
138
readme.md
@@ -1,39 +1,121 @@
|
|||||||
# @pushrocks/smartxml
|
# @push.rocks/smartxml
|
||||||
a package for creating and parsing xml formated files
|
|
||||||
|
|
||||||
## Availabililty and Links
|
a package for creating and parsing XML formatted files
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartxml)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartxml)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartxml)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartxml/)
|
|
||||||
|
|
||||||
## Status for master
|
## Install
|
||||||
|
|
||||||
Status Category | Status Badge
|
To start using @push.rocks/smartxml in your project, you'll first need to install it. This package is distributed via npm, so you can install it by running the following command in your project's root directory:
|
||||||
-- | --
|
|
||||||
GitLab Pipelines | [](https://lossless.cloud)
|
```sh
|
||||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
npm install @push.rocks/smartxml --save
|
||||||
npm | [](https://lossless.cloud)
|
```
|
||||||
Snyk | [](https://lossless.cloud)
|
|
||||||
TypeScript Support | [](https://lossless.cloud)
|
|
||||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
Code Style | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class intellisense
|
### Getting Started
|
||||||
|
|
||||||
## Contribution
|
First, ensure that your project is set up to use TypeScript and ESM syntax. Then, you can import `SmartXml` from @push.rocks/smartxml as follows:
|
||||||
|
|
||||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
```typescript
|
||||||
|
import { SmartXml } from '@push.rocks/smartxml';
|
||||||
|
```
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
`SmartXml` provides two main functionalities: parsing XML formatted strings into JavaScript objects and vice versa, creating XML formatted strings from JavaScript objects.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
### Parsing XML String to Object
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
To parse an XML string to a JavaScript object, you can use the `parseXmlToObject` method. This method takes an XML string as its argument and returns a JavaScript object.
|
||||||
|
|
||||||
|
Here's a simple example:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const xmlString = `
|
||||||
|
<note>
|
||||||
|
<to>Tove</to>
|
||||||
|
<from>Jani</from>
|
||||||
|
<heading>Reminder</heading>
|
||||||
|
<body>Don't forget me this weekend!</body>
|
||||||
|
</note>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const smartXml = new SmartXml();
|
||||||
|
const resultObject = smartXml.parseXmlToObject(xmlString);
|
||||||
|
|
||||||
|
console.log(resultObject);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Creating XML String from Object
|
||||||
|
|
||||||
|
Conversely, if you have a JavaScript object that you want to convert into an XML formatted string, you can use the `createXmlFromObject` method. This method accepts a JavaScript object and returns a string containing the XML representation of the object.
|
||||||
|
|
||||||
|
Here's an example:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const noteObject = {
|
||||||
|
note: {
|
||||||
|
to: 'Tove',
|
||||||
|
from: 'Jani',
|
||||||
|
heading: 'Reminder',
|
||||||
|
body: "Don't forget me this weekend!",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const smartXml = new SmartXml();
|
||||||
|
const xmlString = smartXml.createXmlFromObject(noteObject);
|
||||||
|
|
||||||
|
console.log(xmlString);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Usage
|
||||||
|
|
||||||
|
The `SmartXml` class is built on top of the `fast-xml-parser` library, which provides a lot of flexibility for both parsing and creation. For example, when creating XML from objects, you can control attributes, formatting, and more.
|
||||||
|
|
||||||
|
Let's look at a more complex example that includes XML attributes:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const complexObject = {
|
||||||
|
note: {
|
||||||
|
'@_id': '12345',
|
||||||
|
'@_priority': 'high',
|
||||||
|
to: 'Tove',
|
||||||
|
from: { '@_domain': 'personal', '#text': 'Jani' },
|
||||||
|
heading: {
|
||||||
|
'@_style': 'bold',
|
||||||
|
'#text': 'Reminder',
|
||||||
|
},
|
||||||
|
body: 'This is a special note for the weekend.',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const smartXml = new SmartXml();
|
||||||
|
const complexXmlString = smartXml.createXmlFromObject(complexObject, {
|
||||||
|
format: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(complexXmlString);
|
||||||
|
```
|
||||||
|
|
||||||
|
This example demonstrates how to add attributes (using `"@_attributeName": "value"`) and mixed content (using `"#text": "text value"`) to your objects before converting them to XML.
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
The `@push.rocks/smartxml` package offers a straightforward and powerful means to work with XML in your JavaScript or TypeScript projects. By integrating it, you can easily convert between XML strings and JavaScript objects, allowing for efficient data processing and transmission in scenarios where XML is the preferred format. Whether you're building web services, APIs, or need to handle configuration files in XML, `SmartXml` offers the necessary tools to get the job done with minimal hassle.
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
|||||||
83
test/test.ts
83
test/test.ts
@@ -1,12 +1,8 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
import * as smartxml from '../ts/index';
|
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();
|
||||||
@@ -15,18 +11,79 @@ tap.test('should create an instance', async () => {
|
|||||||
tap.test('should create an xml string', async () => {
|
tap.test('should create an xml string', async () => {
|
||||||
const xmlResult = testSmartxml.createXmlFromObject({
|
const xmlResult = testSmartxml.createXmlFromObject({
|
||||||
hello: {
|
hello: {
|
||||||
wow: 'test'
|
'@_xlmns:teststring': 'hellothere',
|
||||||
}
|
'@_xlmns:testnumber': 10,
|
||||||
|
wow: 'test',
|
||||||
|
url: [{ loc: 3 }, { loc: 3 }],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
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).to.equal('object');
|
expect(typeof jsObject).toEqual('object');
|
||||||
expect(jsObject).property('hello').property('wow').to.equal('nice');
|
expect(jsObject)
|
||||||
|
.arrayItem(1)
|
||||||
|
.property('hello')
|
||||||
|
.arrayItem(0)
|
||||||
|
.property('wow')
|
||||||
|
.arrayItem(0)
|
||||||
|
.property('#text')
|
||||||
|
.toEqual('test');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Test XmlBuilder chainable API
|
||||||
|
tap.test('should create XML using chainable API', async () => {
|
||||||
|
const xml = testSmartxml.create()
|
||||||
|
.ele('root', { att: 'val' })
|
||||||
|
.ele('foo')
|
||||||
|
.ele('bar').txt('foobar').up()
|
||||||
|
.up()
|
||||||
|
.ele('baz').up()
|
||||||
|
.up()
|
||||||
|
.end({ prettyPrint: true });
|
||||||
|
|
||||||
tap.start();
|
console.log('Chainable XML:', xml);
|
||||||
|
expect(xml).toContain('<root');
|
||||||
|
expect(xml).toContain('att="val"');
|
||||||
|
expect(xml).toContain('<foo>');
|
||||||
|
expect(xml).toContain('<bar>foobar</bar>');
|
||||||
|
expect(xml).toContain('<baz');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create XML from object using XmlBuilder', async () => {
|
||||||
|
const obj = {
|
||||||
|
root: {
|
||||||
|
'@_att': 'val',
|
||||||
|
foo: {
|
||||||
|
bar: 'foobar'
|
||||||
|
},
|
||||||
|
baz: {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const xml = testSmartxml.create(obj).end({ prettyPrint: true });
|
||||||
|
console.log('Object-based XML:', xml);
|
||||||
|
expect(xml).toContain('<root');
|
||||||
|
expect(xml).toContain('att="val"');
|
||||||
|
expect(xml).toContain('<bar>foobar</bar>');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should add attributes using att() method', async () => {
|
||||||
|
const xml = testSmartxml.create()
|
||||||
|
.ele('data')
|
||||||
|
.att('x', 1)
|
||||||
|
.att('y', 2)
|
||||||
|
.txt('value')
|
||||||
|
.up()
|
||||||
|
.end();
|
||||||
|
|
||||||
|
expect(xml).toContain('x="1"');
|
||||||
|
expect(xml).toContain('y="2"');
|
||||||
|
expect(xml).toContain('>value</data>');
|
||||||
|
});
|
||||||
|
|
||||||
|
export default tap.start();
|
||||||
|
|||||||
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smartxml',
|
||||||
|
version: '2.0.0',
|
||||||
|
description: 'A package for creating and parsing XML formatted files.'
|
||||||
|
}
|
||||||
29
ts/index.ts
29
ts/index.ts
@@ -1,16 +1,33 @@
|
|||||||
import * as plugins from './smartxml.plugins';
|
import * as plugins from './smartxml.plugins.js';
|
||||||
|
import { XmlBuilder } from './smartxml.xmlbuilder.js';
|
||||||
|
|
||||||
export class SmartXml {
|
export class SmartXml {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
|
public create = XmlBuilder.create;
|
||||||
|
|
||||||
public parseXmlToObject<T = any>(xmlStringArg: string): T {
|
public parseXmlToObject<T = any>(xmlStringArg: string): T {
|
||||||
const jsonObject = plugins.fastXmlParser.parse(xmlStringArg);
|
const parser = new plugins.fastXmlParser.XMLParser({
|
||||||
return jsonObject;
|
preserveOrder: true,
|
||||||
|
ignoreAttributes: false,
|
||||||
|
parseTagValue: true,
|
||||||
|
parseAttributeValue: true,
|
||||||
|
// ignoreDeclaration: true
|
||||||
|
});
|
||||||
|
const jsonObject = parser.parse(xmlStringArg);
|
||||||
|
return jsonObject as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
public createXmlFromObject(jsObject: any): string {
|
public createXmlFromObject(jsObject: any): string {
|
||||||
const jsToXmlParser = new plugins.fastXmlParser.j2xParser({});
|
const builder = new plugins.fastXmlParser.XMLBuilder({
|
||||||
const xml = jsToXmlParser.parse(jsObject);
|
ignoreAttributes: false,
|
||||||
return xml;
|
attributeNamePrefix: '@_',
|
||||||
|
format: true,
|
||||||
|
indentBy: ' ',
|
||||||
|
});
|
||||||
|
const xml = builder.build(jsObject);
|
||||||
|
return '<?xml version="1.0" encoding="UTF-8"?>\n' + xml;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export { XmlBuilder };
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import * as fastXmlParser from 'fast-xml-parser';
|
import * as fastXmlParser from 'fast-xml-parser';
|
||||||
|
|
||||||
export {
|
export { fastXmlParser };
|
||||||
fastXmlParser
|
|
||||||
};
|
|
||||||
|
|||||||
180
ts/smartxml.xmlbuilder.ts
Normal file
180
ts/smartxml.xmlbuilder.ts
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
import * as plugins from './smartxml.plugins.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A lightweight chainable XML builder that provides a fluent API
|
||||||
|
* for programmatically constructing XML documents.
|
||||||
|
*/
|
||||||
|
export class XmlBuilder {
|
||||||
|
private stack: any[] = [];
|
||||||
|
private current: any = null;
|
||||||
|
private rootElement: any = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new XML builder instance
|
||||||
|
* @param input Optional: object to convert to XML, or XML string to parse
|
||||||
|
*/
|
||||||
|
constructor(input?: any) {
|
||||||
|
if (input) {
|
||||||
|
if (typeof input === 'string') {
|
||||||
|
// Parse XML string using fast-xml-parser
|
||||||
|
const parser = new plugins.fastXmlParser.XMLParser({
|
||||||
|
preserveOrder: true,
|
||||||
|
ignoreAttributes: false,
|
||||||
|
});
|
||||||
|
this.rootElement = parser.parse(input);
|
||||||
|
this.current = this.rootElement;
|
||||||
|
} else if (typeof input === 'object') {
|
||||||
|
// Accept object input
|
||||||
|
this.rootElement = input;
|
||||||
|
this.current = input;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static factory method for creating instances
|
||||||
|
*/
|
||||||
|
static create(input?: any): XmlBuilder {
|
||||||
|
return new XmlBuilder(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add an element
|
||||||
|
* @param name Element name
|
||||||
|
* @param attributes Optional attributes object
|
||||||
|
*/
|
||||||
|
public ele(name: string, attributes?: Record<string, any>): this {
|
||||||
|
if (!this.current) {
|
||||||
|
// First element becomes root
|
||||||
|
this.rootElement = {};
|
||||||
|
this.current = this.rootElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newElement: any = {};
|
||||||
|
|
||||||
|
// Add attributes with @_ prefix (fast-xml-parser format)
|
||||||
|
if (attributes) {
|
||||||
|
for (const [key, value] of Object.entries(attributes)) {
|
||||||
|
newElement[`@_${key}`] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this property already exists
|
||||||
|
if (this.current[name]) {
|
||||||
|
// Convert to array if not already
|
||||||
|
if (!Array.isArray(this.current[name])) {
|
||||||
|
this.current[name] = [this.current[name]];
|
||||||
|
}
|
||||||
|
this.current[name].push(newElement);
|
||||||
|
this.stack.push(this.current);
|
||||||
|
this.current = newElement;
|
||||||
|
} else {
|
||||||
|
this.current[name] = newElement;
|
||||||
|
this.stack.push(this.current);
|
||||||
|
this.current = newElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text content to current element
|
||||||
|
* @param content Text content
|
||||||
|
*/
|
||||||
|
public txt(content: string | number): this {
|
||||||
|
if (this.current) {
|
||||||
|
// Check if current element already has properties
|
||||||
|
const hasProperties = Object.keys(this.current).length > 0;
|
||||||
|
if (hasProperties) {
|
||||||
|
// Use #text format for mixed content
|
||||||
|
this.current['#text'] = String(content);
|
||||||
|
} else {
|
||||||
|
// For simple text-only elements, we can use direct assignment
|
||||||
|
// But to maintain consistency, we'll use #text
|
||||||
|
this.current['#text'] = String(content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add attribute to current element
|
||||||
|
* @param name Attribute name
|
||||||
|
* @param value Attribute value
|
||||||
|
*/
|
||||||
|
public att(name: string, value: any): this {
|
||||||
|
if (this.current) {
|
||||||
|
this.current[`@_${name}`] = value;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move up to parent element
|
||||||
|
*/
|
||||||
|
public up(): this {
|
||||||
|
if (this.stack.length > 0) {
|
||||||
|
this.current = this.stack.pop();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the root element (for navigation)
|
||||||
|
*/
|
||||||
|
public root(): this {
|
||||||
|
if (this.stack.length > 0) {
|
||||||
|
this.current = this.stack[0];
|
||||||
|
this.stack = [];
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a comment
|
||||||
|
* @param content Comment text
|
||||||
|
*/
|
||||||
|
public com(content: string): this {
|
||||||
|
// Comments in fast-xml-parser format
|
||||||
|
if (this.current) {
|
||||||
|
if (!this.current['#comment']) {
|
||||||
|
this.current['#comment'] = [];
|
||||||
|
}
|
||||||
|
if (!Array.isArray(this.current['#comment'])) {
|
||||||
|
this.current['#comment'] = [this.current['#comment']];
|
||||||
|
}
|
||||||
|
this.current['#comment'].push(content);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Serialize the XML document
|
||||||
|
* @param options Serialization options
|
||||||
|
*/
|
||||||
|
public end(options?: { prettyPrint?: boolean; format?: string }): string | any {
|
||||||
|
const opts = options || {};
|
||||||
|
|
||||||
|
if (opts.format === 'object') {
|
||||||
|
return this.rootElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use fast-xml-parser to build XML
|
||||||
|
const builder = new plugins.fastXmlParser.XMLBuilder({
|
||||||
|
ignoreAttributes: false,
|
||||||
|
attributeNamePrefix: '@_',
|
||||||
|
format: opts.prettyPrint !== false,
|
||||||
|
indentBy: ' ',
|
||||||
|
});
|
||||||
|
|
||||||
|
const xml = builder.build(this.rootElement || {});
|
||||||
|
return '<?xml version="1.0" encoding="UTF-8"?>\n' + xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert to string (alias for end)
|
||||||
|
*/
|
||||||
|
public toString(): string {
|
||||||
|
return this.end() as string;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {}
|
||||||
|
},
|
||||||
|
"exclude": ["dist_*/**/*.d.ts"]
|
||||||
|
}
|
||||||
17
tslint.json
17
tslint.json
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user