UNPKG

@cyclonedx/cyclonedx-library

Version:

Core functionality of CycloneDX for JavaScript (Node.js or WebBrowser).

39 lines (35 loc) 1.47 kB
"use strict"; /*! This file is part of CycloneDX JavaScript Library. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. SPDX-License-Identifier: Apache-2.0 Copyright (c) OWASP Foundation. All Rights Reserved. */ Object.defineProperty(exports, "__esModule", { value: true }); const promises_1 = require("node:fs/promises"); const node_url_1 = require("node:url"); const libxmljs2_1 = require("libxmljs2"); const xmlParseOptions = Object.freeze({ nonet: true, compact: true, noent: false, dtdload: false }); exports.default = (async function (schemaPath) { const schema = (0, libxmljs2_1.parseXml)(await (0, promises_1.readFile)(schemaPath, 'utf-8'), { ...xmlParseOptions, baseUrl: (0, node_url_1.pathToFileURL)(schemaPath).toString() }); return function (data) { const doc = (0, libxmljs2_1.parseXml)(data, xmlParseOptions); return doc.validate(schema) ? null : doc.validationErrors; }; }); //# sourceMappingURL=libxmljs2.js.map