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

Function stripAttributePrefix

src/xmlparser/node2json.js:14–29  ·  view source on GitHub ↗

* Helper function to strip attribute prefix from attribute map * @param {object} attrs - Attributes with prefix (e.g., {"@_class": "code"}) * @param {string} prefix - Attribute prefix to remove (e.g., "@_") * @returns {object} Attributes without prefix (e.g., {"class": "code"})

(attrs, prefix)

Source from the content-addressed store, hash-verified

12 * @returns {object} Attributes without prefix (e.g., {"class": "code"})
13 */
14function stripAttributePrefix(attrs, prefix) {
15 if (!attrs || typeof attrs !== 'object') return {};
16 if (!prefix) return attrs;
17
18 const rawAttrs = {};
19 for (const key in attrs) {
20 if (key.startsWith(prefix)) {
21 const rawName = key.substring(prefix.length);
22 rawAttrs[rawName] = attrs[key];
23 } else {
24 // Attribute without prefix (shouldn't normally happen, but be safe)
25 rawAttrs[key] = attrs[key];
26 }
27 }
28 return rawAttrs;
29}
30
31/**
32 *

Callers 1

compressFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected