@cyclonedx/cyclonedx-library
Version:
Core functionality of CycloneDX for JavaScript (Node.js or WebBrowser).
65 lines (61 loc) • 2.06 kB
JavaScript
/*!
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 });
exports.BomLinkElement = exports.BomLinkDocument = void 0;
class BomLinkBase {
#value;
constructor(value) {
this.value = value;
}
get value() {
return this.#value;
}
set value(value) {
if (!this._isValid(value)) {
throw new RangeError('invalid value');
}
this.#value = value;
}
compare(other) {
return this.toString().localeCompare(other.toString());
}
toString() {
return this.value;
}
}
class BomLinkDocument extends BomLinkBase {
static #pattern = /^urn:cdx:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/[1-9][0-9]*$/;
static isValid(value) {
return typeof value === 'string' &&
this.#pattern.test(value);
}
_isValid(value) {
return BomLinkDocument.isValid(value);
}
}
exports.BomLinkDocument = BomLinkDocument;
class BomLinkElement extends BomLinkBase {
static #pattern = /^urn:cdx:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\/[1-9][0-9]*#.+$/;
static isValid(value) {
return typeof value === 'string' &&
this.#pattern.test(value);
}
_isValid(value) {
return BomLinkElement.isValid(value);
}
}
exports.BomLinkElement = BomLinkElement;
//# sourceMappingURL=bomLink.js.map
;