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

Function parseTextData

src/xmlparser/OrderedObjParser.js:150–180  ·  view source on GitHub ↗

* @param {string} val * @param {string} tagName * @param {string|Matcher} jPath - jPath string or Matcher instance based on options.jPath * @param {boolean} dontTrim * @param {boolean} hasAttributes * @param {boolean} isLeafNode * @param {boolean} escapeEntities

(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities)

Source from the content-addressed store, hash-verified

148 * @param {boolean} escapeEntities
149 */
150function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
151 const options = this.options;
152 if (val !== undefined) {
153 if (options.trimValues && !dontTrim) {
154 val = val.trim();
155 }
156 if (val.length > 0) {
157 if (!escapeEntities) val = this.replaceEntitiesValue(val, tagName, jPath);
158
159 // Pass jPath string or matcher based on options.jPath setting
160 const jPathOrMatcher = options.jPath ? jPath.toString() : jPath;
161 const newval = options.tagValueProcessor(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode);
162 if (newval === null || newval === undefined) {
163 //don't parse
164 return val;
165 } else if (typeof newval !== typeof val || newval !== val) {
166 //overwrite
167 return newval;
168 } else if (options.trimValues) {
169 return parseValue(val, options.parseTagValue, options.numberParseOptions);
170 } else {
171 const trimmedVal = val.trim();
172 if (trimmedVal === val) {
173 return parseValue(val, options.parseTagValue, options.numberParseOptions);
174 } else {
175 return val;
176 }
177 }
178 }
179 }
180}
181
182function resolveNameSpace(tagname) {
183 if (this.options.removeNSPrefix) {

Callers

nothing calls this directly

Calls 3

parseValueFunction · 0.85
replaceEntitiesValueMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected