Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-xml-parser

Package Overview
Dependencies
Maintainers
1
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-xml-parser - npm Package Compare versions

Comparing version 4.4.1 to 4.5.0

src/ignoreAttributes.js

3

CHANGELOG.md
<small>Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.</small>
**4.5.0 / 2024-09-03**
- feat #666: ignoreAttributes support function, and array of string or regex (By [ArtemM](https://github.com/mav-rik))
**4.4.1 / 2024-07-28**

@@ -4,0 +7,0 @@ - v5 fix: maximum length limit to currency value

3

package.json
{
"name": "fast-xml-parser",
"version": "4.4.1",
"version": "4.5.0",
"description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",

@@ -52,3 +52,2 @@ "main": "./src/fxp.js",

"babel-loader": "^8.2.2",
"cytorus": "^0.2.9",
"eslint": "^8.3.0",

@@ -55,0 +54,0 @@ "he": "^1.2.0",

@@ -33,5 +33,13 @@ type X2jOptions = {

*
* When `true` - ignores all the attributes
*
* When `false` - parses all the attributes
*
* When `Array<string | RegExp>` - filters out attributes that match provided patterns
*
* When `Function` - calls the function for each attribute and filters out those for which the function returned `true`
*
* Defaults to `true`
*/
ignoreAttributes?: boolean;
ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPath: string) => boolean);

@@ -254,7 +262,15 @@ /**

/**
* Whether to ignore attributes when parsing
* Whether to ignore attributes when building
*
* When `true` - ignores all the attributes
*
* When `false` - builds all the attributes
*
* When `Array<string | RegExp>` - filters out attributes that match provided patterns
*
* When `Function` - calls the function for each attribute and filters out those for which the function returned `true`
*
* Defaults to `true`
*/
ignoreAttributes?: boolean;
ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPath: string) => boolean);

@@ -261,0 +277,0 @@ /**

'use strict';
//parse Empty Node as self closing node
const buildFromOrderedJs = require('./orderedJs2Xml');
const getIgnoreAttributesFn = require('../ignoreAttributes')

@@ -41,3 +42,3 @@ const defaultOptions = {

this.options = Object.assign({}, defaultOptions, options);
if (this.options.ignoreAttributes || this.options.attributesGroupName) {
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
this.isAttribute = function(/*a*/) {

@@ -47,2 +48,3 @@ return false;

} else {
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
this.attrPrefixLen = this.options.attributeNamePrefix.length;

@@ -76,9 +78,10 @@ this.isAttribute = isAttribute;

}
return this.j2x(jObj, 0).val;
return this.j2x(jObj, 0, []).val;
}
};
Builder.prototype.j2x = function(jObj, level) {
Builder.prototype.j2x = function(jObj, level, ajPath) {
let attrStr = '';
let val = '';
const jPath = ajPath.join('.')
for (let key in jObj) {

@@ -106,5 +109,5 @@ if(!Object.prototype.hasOwnProperty.call(jObj, key)) continue;

const attr = this.isAttribute(key);
if (attr) {
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
}else {
} else if (!attr) {
//tag value

@@ -133,3 +136,3 @@ if (key === this.options.textNodeName) {

if(this.options.oneListGroup){
const result = this.j2x(item, level + 1);
const result = this.j2x(item, level + 1, ajPath.concat(key));
listTagVal += result.val;

@@ -140,3 +143,3 @@ if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {

}else{
listTagVal += this.processTextOrObjNode(item, key, level)
listTagVal += this.processTextOrObjNode(item, key, level, ajPath)
}

@@ -166,3 +169,3 @@ } else {

} else {
val += this.processTextOrObjNode(jObj[key], key, level)
val += this.processTextOrObjNode(jObj[key], key, level, ajPath)
}

@@ -182,4 +185,4 @@ }

function processTextOrObjNode (object, key, level) {
const result = this.j2x(object, level + 1);
function processTextOrObjNode (object, key, level, ajPath) {
const result = this.j2x(object, level + 1, ajPath.concat(key));
if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {

@@ -186,0 +189,0 @@ return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);

@@ -8,2 +8,3 @@ 'use strict';

const toNumber = require("strnum");
const getIgnoreAttributesFn = require('../ignoreAttributes')

@@ -57,2 +58,3 @@ // const regx =

this.addChild = addChild;
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
}

@@ -130,3 +132,3 @@

function buildAttributesMap(attrStr, jPath, tagName) {
if (!this.options.ignoreAttributes && typeof attrStr === 'string') {
if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
// attrStr = attrStr.replace(/\r?\n/g, ' ');

@@ -140,2 +142,5 @@ //attrStr = attrStr || attrStr.trim();

const attrName = this.resolveNameSpace(matches[i][1]);
if (this.ignoreAttributesFn(attrName, jPath)) {
continue
}
let oldVal = matches[i][4];

@@ -142,0 +147,0 @@ let aName = this.options.attributeNamePrefix + attrName;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc