Gathering detailed insights and metrics for slimdom-sax-parser
Gathering detailed insights and metrics for slimdom-sax-parser
Gathering detailed insights and metrics for slimdom-sax-parser
Gathering detailed insights and metrics for slimdom-sax-parser
npm install slimdom-sax-parser
74.5
Supply Chain
98.9
Quality
75.7
Maintenance
100
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
8 Stars
67 Commits
5 Forks
6 Watching
8 Branches
6 Contributors
Updated on 12 Oct 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
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
4
Parses XML to a slimdom document using saxes. slimdom is a fast, tiny, standards-compliant XML DOM implementation for browser and node.
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
.
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" />');
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');
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
Reason
Found 3/22 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
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
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
14 existing vulnerabilities detected
Details
Score
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