UNPKG

@nodecfdi/cfdi-cleaner

Version:

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

27 lines (26 loc) 1.47 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ts_mixer_1 = require("ts-mixer"); const cfdi_x_path_1 = __importDefault(require("#src/internal/cfdi_x_path")); const schema_location_1 = __importDefault(require("#src/internal/schema_location")); const xml_attribute_methods_1 = __importDefault(require("#src/mixins/xml_attribute_methods")); const xml_namespace_methods_1 = __importDefault(require("#src/mixins/xml_namespace_methods")); class RemoveNonSatSchemaLocations extends (0, ts_mixer_1.Mixin)(xml_attribute_methods_1.default, xml_namespace_methods_1.default) { clean(document) { const xpath = cfdi_x_path_1.default.createFromDocument(document); const schemaLocations = xpath.querySchemaLocations(); for (const schemaLocation of schemaLocations) { const value = this.cleanSchemaLocationsValue(schemaLocation.value); this.attributeSetValueOrRemoveIfEmpty(schemaLocation, value); } } cleanSchemaLocationsValue(schemaLocationValue) { const schemaLocation = schema_location_1.default.createFromValue(schemaLocationValue); schemaLocation.filterUsingNamespace((namespace) => this.isNamespaceRelatedToSat(namespace)); return schemaLocation.asValue(); } } exports.default = RemoveNonSatSchemaLocations;