MCPcopy Create free account
hub / github.com/NaturalIntelligence/fast-xml-parser / assignAttributes

Function assignAttributes

src/xmlparser/node2json.js:134–159  ·  view source on GitHub ↗
(obj, attrMap, readonlyMatcher, options)

Source from the content-addressed store, hash-verified

132}
133
134function assignAttributes(obj, attrMap, readonlyMatcher, options) {
135 if (attrMap) {
136 const keys = Object.keys(attrMap);
137 const len = keys.length; //don't make it inline
138 for (let i = 0; i < len; i++) {
139 const atrrName = keys[i]; // This is the PREFIXED name (e.g., "@_class")
140
141 // Strip prefix for matcher path (for isArray callback)
142 const rawAttrName = atrrName.startsWith(options.attributeNamePrefix)
143 ? atrrName.substring(options.attributeNamePrefix.length)
144 : atrrName;
145
146 // For attributes, we need to create a temporary path
147 // Pass jPath string or matcher based on options.jPath setting
148 const jPathOrMatcher = options.jPath
149 ? readonlyMatcher.toString() + "." + rawAttrName
150 : readonlyMatcher;
151
152 if (options.isArray(atrrName, jPathOrMatcher, true, true)) {
153 obj[atrrName] = [attrMap[atrrName]];
154 } else {
155 obj[atrrName] = attrMap[atrrName];
156 }
157 }
158 }
159}
160
161function isLeafTag(obj, options) {
162 const { textNodeName } = options;

Callers 1

compressFunction · 0.85

Calls 1

toStringMethod · 0.45

Tested by

no test coverage detected