Skip to content

Commit df53819

Browse files
authored
refactor: refactor internal libs (#1083)
refactoring internal libs, in preparation of possible additions in the field --------- Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 038352e commit df53819

File tree

7 files changed

+34
-39
lines changed

7 files changed

+34
-39
lines changed

libs/universal-node-xml/index.d.ts renamed to libs/universal-node-xml/stringify.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,5 @@ declare interface ThrowError {
2828
}
2929

3030
declare type Stringify = (element: SimpleXml.Element, options?: SerializerOptions) => string
31-
export declare const stringify: Stringify | ThrowError
32-
33-
/*
34-
declare type Parse = (xml: string) => SimpleXml.Element
35-
export declare const parse: Parse | ThrowError
36-
*/
31+
declare const stringify: Stringify | ThrowError
32+
export = stringify

libs/universal-node-xml/index.js renamed to libs/universal-node-xml/stringify.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,25 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2525
* @type {[string, function():(Function|*)][]}
2626
*/
2727
const possibleStringifiers = [
28-
['xmlbuilder2', () => require('./stringifiers/xmlbuilder2')]
28+
['xmlbuilder2', () => require('./__stringifiers/xmlbuilder2')]
29+
// ... add others here, pull-requests welcome!
2930
]
3031
/* eslint-enable jsdoc/valid-types */
3132

32-
module.exports.stringify = function () {
33+
module.exports = function () {
3334
throw new Error(
3435
'No stringifier available.' +
3536
' Please install any of the optional dependencies: ' +
3637
possibleStringifiers.map(kv => kv[0]).join(', ')
3738
)
3839
}
39-
module.exports.stringify.fails = true
40+
module.exports.fails = true
4041

4142
for (const [, getStringifier] of possibleStringifiers) {
4243
try {
4344
const possibleStringifier = getStringifier()
4445
if (typeof possibleStringifier === 'function') {
45-
module.exports.stringify = possibleStringifier
46+
module.exports = possibleStringifier
4647
break
4748
}
4849
} catch {

libs/universal-node-xml/index.test.js renamed to libs/universal-node-xml/stringify.test.js

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,32 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
2020
const assert = require('assert')
2121
const { suite, test } = require('mocha')
2222

23-
const { stringify } = require('./')
23+
const stringify = require('./stringify')
2424

25-
suite('libs/universal-node-xml', () => {
26-
suite('stringify', () => {
27-
const dummyElem = Object.freeze({
28-
type: 'element',
29-
name: 'foo'
30-
})
31-
const dummyElemStringifiedRE = /<foo(:?\/>|><\/foo>)/
32-
33-
if (stringify.fails) {
34-
test('call should fail/throw', () => {
35-
assert.throws(
36-
() => {
37-
stringify(dummyElem)
38-
},
39-
(err) => {
40-
assert.ok(err instanceof Error)
41-
assert.match(err.message, /no stringifier available/i)
42-
return true
43-
}
44-
)
45-
})
46-
} else {
47-
test('call should pass', () => {
48-
const stringified = stringify(dummyElem)
49-
assert.match(stringified, dummyElemStringifiedRE)
50-
})
51-
}
25+
suite('libs/universal-node-xml/stringify', () => {
26+
const dummyElem = Object.freeze({
27+
type: 'element',
28+
name: 'foo'
5229
})
30+
const dummyElemStringifiedRE = /<foo(:?\/>|><\/foo>)/
31+
32+
if (stringify.fails) {
33+
test('call should fail/throw', () => {
34+
assert.throws(
35+
() => {
36+
stringify(dummyElem)
37+
},
38+
(err) => {
39+
assert.ok(err instanceof Error)
40+
assert.match(err.message, /no stringifier available/i)
41+
return true
42+
}
43+
)
44+
})
45+
} else {
46+
test('call should pass', () => {
47+
const stringified = stringify(dummyElem)
48+
assert.match(stringified, dummyElemStringifiedRE)
49+
})
50+
}
5351
})

src/serialize/xmlSerializer.node.ts

Lines changed: 1 addition & 1 deletion
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 { stringify } from '../../libs/universal-node-xml'
20+
import * as stringify from '../../libs/universal-node-xml/stringify'
2121
import type { SerializerOptions } from './types'
2222
import type { SimpleXml } from './xml/types'
2323
import { XmlBaseSerializer } from './xmlBaseSerializer'

0 commit comments

Comments
 (0)