Skip to content

Commit 652224b

Browse files
authored
style: simplify internal lib universal-node-xml (#621)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent ad33fa4 commit 652224b

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

libs/universal-node-xml/index.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2020
import type { SerializerOptions } from '../../src/serialize/types'
2121
import type { SimpleXml } from '../../src/serialize/xml/types'
2222

23+
/** @throws {@link Error} */
2324
declare type ThrowError = (..._: any[]) => never
2425

2526
declare type Stringify = (element: SimpleXml.Element, options?: SerializerOptions) => string
26-
export declare const stringify: Stringify | undefined
27-
export declare const stringifyFallback: Stringify | ThrowError
27+
export declare const stringify: Stringify | ThrowError
2828

2929
/*
3030
declare type Parse = (xml: string) => SimpleXml.Element
31-
export declare const parse: Parse | undefined
32-
export declare const parseFallback: Parse | ThrowError
31+
export declare const parse: Parse | ThrowError
3332
*/

libs/universal-node-xml/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,20 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20+
module.exports.stringify = function () {
21+
/* c8 ignore start */
22+
throw new Error(
23+
'No stringifier available. Please install any of the optional xml libraries: ' +
24+
possibleStringifiers.join(', ')
25+
)
26+
/* c8 ignore end */
27+
}
28+
2029
const possibleStringifiers = [
2130
// prioritized list of possible implementations
2231
'xmlbuilder2'
2332
]
2433

25-
module.exports.stringify = undefined
2634
for (const file of possibleStringifiers) {
2735
try {
2836
const possibleStringifier = require(`./stringifiers/${file}`)
@@ -36,10 +44,3 @@ for (const file of possibleStringifiers) {
3644
}
3745
/* c8 ignore end */
3846
}
39-
40-
module.exports.stringifyFallback = module.exports.stringify ??
41-
/* c8 ignore start */
42-
function () {
43-
throw new Error('No stringifier available. Please install one of the optional xml libraries.')
44-
}
45-
/* c8 ignore end */

src/serialize/xmlSerializer.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
import { stringifyFallback } from '../../libs/universal-node-xml'
20+
import { stringify } from '../../libs/universal-node-xml'
2121
import type { SerializerOptions } from './types'
2222
import type { SimpleXml } from './xml/types'
2323
import { XmlBaseSerializer } from './xmlBaseSerializer'
@@ -30,6 +30,6 @@ export class XmlSerializer extends XmlBaseSerializer {
3030
normalizedBom: SimpleXml.Element,
3131
options: SerializerOptions = {}
3232
): string {
33-
return stringifyFallback(normalizedBom, options)
33+
return stringify(normalizedBom, options)
3434
}
3535
}

0 commit comments

Comments
 (0)