ml-testing-toolkit 18.15.1-url-handling.0 → 18.15.1-url-handling.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/utils.js +15 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ml-testing-toolkit",
|
|
3
3
|
"description": "Testing Toolkit for Mojaloop implementations",
|
|
4
|
-
"version": "18.15.1-url-handling.
|
|
4
|
+
"version": "18.15.1-url-handling.1",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Vijaya Kumar Guthi, ModusBox Inc. ",
|
|
7
7
|
"contributors": [
|
package/src/lib/utils.js
CHANGED
|
@@ -43,6 +43,7 @@ const readRecursiveAsync = promisify(files)
|
|
|
43
43
|
const rmdirAsync = promisify(fs.rmdir)
|
|
44
44
|
const mvAsync = promisify(mv)
|
|
45
45
|
const { resolve } = require('path')
|
|
46
|
+
const yaml = require('js-yaml')
|
|
46
47
|
|
|
47
48
|
const getHeader = (headers, name) => {
|
|
48
49
|
return Object.entries(headers).find(
|
|
@@ -80,9 +81,20 @@ const checkUrl = async fileName => {
|
|
|
80
81
|
await fileHandle.close()
|
|
81
82
|
}
|
|
82
83
|
const prefix = buffer.toString('utf8').replace('\uFEFF', '') // Remove BOM
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
if (prefix.startsWith('"http') || prefix.startsWith("'http")) {
|
|
85
|
+
const content = fs.readFileSync(fileName, 'utf8')
|
|
86
|
+
try {
|
|
87
|
+
return JSON.parse(content)
|
|
88
|
+
} catch (jsonErr) {
|
|
89
|
+
try {
|
|
90
|
+
return yaml.load(content)
|
|
91
|
+
} catch (yamlErr) {
|
|
92
|
+
throw new Error(`Failed to parse file as JSON or YAML: ${jsonErr.message}; ${yamlErr.message}`)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
return fileName
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
module.exports = {
|