Installations
npm install slimdom-sax-parser
Score
74.5
Supply Chain
98.9
Quality
75.7
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
16.15.0
NPM Version
8.5.5
Statistics
8 Stars
67 Commits
5 Forks
6 Watching
8 Branches
6 Contributors
Updated on 12 Oct 2024
Languages
TypeScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
145,054
Last day
23%
171
Compared to previous day
Last week
38.3%
957
Compared to previous week
Last month
-6.6%
3,695
Compared to previous month
Last year
38.6%
28,609
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
4
slimdom-sax-parser
Parses XML to a slimdom document using saxes. slimdom is a fast, tiny, standards-compliant XML DOM implementation for browser and node.
- Parses text, elements, attributes, processing instructions, comments and CDATA
- Supports namespaces
- Works in NodeJS and the browser
Exports
Has two named exports:
async
(function) Asynchronously return a slimdom Document for the given XML string or Readable stream.sync
(function) Synchronously return a slimdom Document for the given XML string:slimdom
(slimdom) A reference to the lib this parser is built around, as a convenience.
The shape of the async
function is as follows;
1function async( 2 xml: string | stream.Readable, 3 options?: saxes.SaxesOptions & { 4 additionalEntities?: { 5 [entityName: string]: string; 6 }; 7 } 8): Promise<slimdom.Document>;
The shape of the sync
function is as follows;
1function sync( 2 xml: string, 3 options?: saxes.SaxesOptions & { 4 additionalEntities?: { 5 [entityName: string]: string; 6 }; 7 } 8): slimdom.Document;
See also saxes.SaxesOptions. Contrary to saxes
, XML namespaces (the xmlns
option) are enabled by default.
See also the standard DOM API, which is the interface implemented by slimdom
.
Usage
1import { async } from 'slimdom-sax-parser'; 2 3const dom = await async('<xml foo="bar" />');
1import { sync } from 'slimdom-sax-parser'; 2 3const dom = sync('<xml foo="bar" />');
Examples
Modify the XML DOM:
1import { sync } from 'slimdom-sax-parser'; 2 3const document = sync(`<foo />`); 4 5document.documentElement.setAttribute('bar', 'baz'); 6// document.documentElement.hasAttribute('bar') === true
Use with an XPath engine (fontoxpath):
1import { sync } from 'slimdom-sax-parser'; 2import { evaluateXPath } from 'fontoxpath'; 3 4const document = sync(`<foo><bar /><baz /></foo>`); 5const childNodeNames = evaluateXPath('/foo/*/name()', document); 6// childNodeNames equals ['bar', 'baz']
Use source code position tracking:
1import { slimdom, sync } from 'slimdom-sax-parser'; 2 3const xml = '<example><child-element /></example>'; 4 5const document = sync(xml, { position: true }); 6// document instanceof slimdom.Document === true 7 8const childElement = document.documentElement.firstChild; 9// childElement instanceof slimdom.Element === true 10 11const position = childElement.position; 12// xml.substring(position.start, position.end) === '<child-element />'
Transform a XML file:
1import fs from 'fs'; 2import { async, slimdom } from 'slimdom-sax-parser'; 3import { evaluateXPathToNodes } from 'fontoxpath'; 4 5async function transform(filePath) { 6 const xmlStream = fs.createReadStream(filePath); 7 const document = await async(xmlStream); 8 9 const barNodes = evaluateXPathToNodes('//bar/*', document); 10 for (const barNode of barNodes) { 11 barNode.setAttribute('bar', 'baz'); 12 } 13 14 await fs.promises.writeFile(filePath, slimdom.serializeToWellFormedString(document)); 15} 16 17transform('./file.xml');
License
Copyright (c) 2019 Wybe Minnebo
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/wvbe/slimdom-sax-parser/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/wvbe/slimdom-sax-parser/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/wvbe/slimdom-sax-parser/main.yml/master?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
14 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.6
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More