1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\r
3 # Licensed under the Apache License, Version 2.0 (the "License"); #
\r
4 # you may not use this file except in compliance with the License. #
\r
5 # You may obtain a copy of the License at #
\r
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\r
9 # Unless required by applicable law or agreed to in writing, software #
\r
10 # distributed under the License is distributed on an "AS IS" BASIS, #
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
\r
12 # See the License for the specific language governing permissions and #
\r
13 # limitations under the License. #
\r
14 ##############################################################################*/
\r
17 const YAML = require('yamljs');
\r
19 module.exports = function (convertTo) {
\r
21 const toConvert = ['testDataTemplate'];
\r
23 function convert(p) {
\r
24 for (var key in p) {
\r
25 if (p.hasOwnProperty(key) && (typeof p[key] === 'object' || typeof p[key] === 'array') ) {
\r
26 if (toConvert.indexOf(key) < 0) {
\r
30 if(convertTo == 'yaml'){
\r
31 p[key] = YAML.stringify(p[key]);
\r
33 if(convertTo == 'json'){
\r
35 console.log(p[key]);
\r
36 p[key] = convertTabs(p[key]);
\r
37 p[key] = YAML.parse(p[key]);
\r
38 console.log(p[key]);
\r
42 if (toConvert.indexOf(key) >= 0) {
\r
44 if(convertTo == 'yaml'){
\r
45 p[key] = YAML.stringify(p[key]);
\r
47 if(convertTo == 'json'){
\r
48 p[key] = convertTabs(p[key]);
\r
49 p[key] = YAML.parse(p[key]);
\r
57 function convertTabs(str){
\r
58 if(typeof str === 'string'){
\r
59 return str.replace(/\t/g, ' ');
\r
63 return async context => {
\r
65 convert(context.result);
\r
67 convert(context.data);
\r