Skip to content

Commit 10438aa

Browse files
committed
style
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent a989f93 commit 10438aa

File tree

7 files changed

+78
-20
lines changed

7 files changed

+78
-20
lines changed

src/serialize/json/normalize.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ export class BomNormalizer extends BaseJsonNormalizer<Models.Bom> {
146146
}
147147
}
148148

149-
#isEligibleSerialNumber(v: string | undefined ): boolean {
150-
return v !== undefined
149+
#isEligibleSerialNumber (v: string | undefined): boolean {
150+
return v !== undefined &&
151151
// see https://github.com/CycloneDX/specification/blob/ef71717ae0ecb564c0b4c9536d6e9e57e35f2e69/schema/bom-1.4.schema.json#L39
152-
&& /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(v)
152+
/^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(v)
153153
}
154154
}
155155

src/serialize/xml/normalize.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ export class BomNormalizer extends BaseXmlNormalizer<Models.Bom> {
161161
}
162162
}
163163

164-
#isEligibleSerialNumber(v: string | undefined ): boolean {
165-
return v !== undefined
164+
#isEligibleSerialNumber (v: string | undefined): boolean {
165+
return v !== undefined &&
166166
// see https://github.com/CycloneDX/specification/blob/ef71717ae0ecb564c0b4c9536d6e9e57e35f2e69/schema/bom-1.4.xsd#L699
167-
&& /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|^\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}$/.test(v)
167+
/^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|^\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}$/.test(v)
168168
}
169169
}
170170

src/types/urn.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2323
*
2424
* @see {@link isUrnUuid}
2525
*
26-
* @deprecated
26+
* @deprecated Use `string` instead.
2727
*/
2828
export type UrnUuid = string
2929

@@ -32,7 +32,9 @@ export type UrnUuid = string
3232
*/
3333
const urnUuidPattern = /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
3434

35-
/** @deprecated */
35+
/**
36+
* @deprecated This function will be removed during next mayor release.
37+
*/
3638
export function isUrnUuid (value: any): value is UrnUuid {
3739
return typeof value === 'string' &&
3840
urnUuidPattern.test(value)

src/utils/bomUtility.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
119
export function randomSerialNumber (): string {
220
const b = [
321
Math.round(Math.random() * 0xFFFF),

src/utils/index.ts

+18
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
119
export * as BomUtility from './bomUtility'

tests/unit/Models.Bom.spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ suite('Models.Bom', () => {
9898
)
9999

100100
suite('can set serialNumber', () => {
101-
test(`empty string`, () => {
101+
test('empty string', () => {
102102
const bom = new Bom()
103103
bom.serialNumber = ''
104104
assert.strictEqual(bom.serialNumber, undefined)
105-
});
106-
test(`something`, () => {
105+
})
106+
test('something', () => {
107107
const bom = new Bom()
108108
bom.serialNumber = 'something'
109109
assert.strictEqual(bom.serialNumber, 'something')
110-
});
110+
})
111111
})
112112
})

tests/unit/Utils.BomUtility.spec.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
1+
/*!
2+
This file is part of CycloneDX JavaScript Library.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
SPDX-License-Identifier: Apache-2.0
17+
Copyright (c) OWASP Foundation. All Rights Reserved.
18+
*/
119

220
const assert = require('assert')
321
const { suite, test } = require('mocha')
422

5-
const { Utils : {
6-
BomUtility
7-
}} = require('../../');
23+
const {
24+
Utils: {
25+
BomUtility
26+
}
27+
} = require('../../')
828

929
suite('Utils.BomUtility', () => {
1030
suite('randomSerialNumber()', () => {
1131
test('has correct format according to XSD', () => {
12-
const value = BomUtility.randomSerialNumber();
13-
assert.match(value, /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|^\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}$/);
14-
});
32+
const value = BomUtility.randomSerialNumber()
33+
assert.match(value, /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|^\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}$/)
34+
})
1535
test('has correct format according to JSON schema', () => {
16-
const value = BomUtility.randomSerialNumber();
17-
assert.match(value, /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
36+
const value = BomUtility.randomSerialNumber()
37+
assert.match(value, /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/)
1838
})
1939
})
2040
})

0 commit comments

Comments
 (0)