UNPKG

@cyclonedx/cyclonedx-library

Version:

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

51 lines (47 loc) 1.92 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. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.isSupportedSpdxId = isSupportedSpdxId; exports.fixupSpdxId = fixupSpdxId; exports.isValidSpdxLicenseExpression = isValidSpdxLicenseExpression; const spdx_expression_parse_1 = __importDefault(require("spdx-expression-parse")); const spdx_SNAPSHOT_schema_json_1 = require("../res/schema/spdx.SNAPSHOT.schema.json"); const spdxIds = new Set(spdx_SNAPSHOT_schema_json_1.enum); const spdxLowerToActual = Object.freeze(Object.fromEntries(spdx_SNAPSHOT_schema_json_1.enum.map(spdxId => [spdxId.toLowerCase(), spdxId]))); function isSupportedSpdxId(value) { return spdxIds.has(value); } function fixupSpdxId(value) { return typeof value === 'string' && value.length > 0 ? spdxLowerToActual[value.toLowerCase()] : undefined; } function isValidSpdxLicenseExpression(value) { if (typeof value !== 'string') { return false; } try { (0, spdx_expression_parse_1.default)(value); } catch (err) { return false; } return true; } //# sourceMappingURL=spdx.js.map