UNPKG

@nodecfdi/cfdi-cleaner

Version:

Librería para limpiar comprobantes fiscales digitales v3.3 y v4.0

32 lines (31 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class XmlNsSchemaLocation { clean(xml) { if (!xml.includes('xmlns:schemaLocation="')) { // Nothing to do return xml; } const pattern = /<[\s\S]*?>/gu; const matches = [...xml.matchAll(pattern)]; const parts = xml.split(pattern); const buffer = [parts[0]]; for (const [index, match] of matches.entries()) { buffer.push(this.cleanTagContent(match[0]), parts[index + 1]); } return buffer.join(''); } cleanTagContent(content) { if (!content.includes('xmlns:schemaLocation="')) { // Nothing to do return content; } if (!content.includes('xsi:schemaLocation="')) { // Safely replace to "xsi:schemaLocation" return content.replaceAll(/(\s)xmlns:schemaLocation="/g, '$1xsi:schemaLocation="'); } // Remove xmlns:schemaLocation attribute return content.replaceAll(/\sxmlns:schemaLocation="[\s\S]*?"/g, ''); } } exports.default = XmlNsSchemaLocation;