vita-playwright 1.0.0
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/README.md +57 -0
- package/dist/src/helpers/api-helpers.js +52 -0
- package/dist/src/helpers/api-helpers.js.map +1 -0
- package/dist/src/helpers/ui-helpers.js +134 -0
- package/dist/src/helpers/ui-helpers.js.map +1 -0
- package/dist/src/index.js +22 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/utils/api_axios.js +36 -0
- package/dist/src/utils/api_axios.js.map +1 -0
- package/dist/src/utils/azure_storage_methods.js +87 -0
- package/dist/src/utils/azure_storage_methods.js.map +1 -0
- package/dist/src/utils/comparisions.js +85 -0
- package/dist/src/utils/comparisions.js.map +1 -0
- package/dist/src/utils/document_utility.js +67 -0
- package/dist/src/utils/document_utility.js.map +1 -0
- package/dist/src/utils/keyvault_methods.js +30 -0
- package/dist/src/utils/keyvault_methods.js.map +1 -0
- package/dist/src/utils/test_data.js +282 -0
- package/dist/src/utils/test_data.js.map +1 -0
- package/dist/src/utils/xmlToJson.js +55 -0
- package/dist/src/utils/xmlToJson.js.map +1 -0
- package/package.json +91 -0
- package/src/helpers/api-helpers.ts +40 -0
- package/src/helpers/ui-helpers.ts +122 -0
- package/src/index.ts +21 -0
- package/src/utils/api_axios.ts +22 -0
- package/src/utils/azure_storage_methods.ts +91 -0
- package/src/utils/comparisions.ts +72 -0
- package/src/utils/document_utility.ts +49 -0
- package/src/utils/keyvault_methods.ts +17 -0
- package/src/utils/test_data.ts +263 -0
- package/src/utils/xmlToJson.ts +40 -0
- package/tsconfig.json +106 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var DOMParser = require('xmldom').DOMParser;
|
|
2
|
+
import { XmlToJson } from './xmlToJson';
|
|
3
|
+
var CryptoJS = require('crypto-js');
|
|
4
|
+
import { TokenGenerators } from './api_axios'
|
|
5
|
+
|
|
6
|
+
export class AzureStorageMethods {
|
|
7
|
+
|
|
8
|
+
static async getblobs(storageAccount: any, containerName: any, storageAccountKey: any, apiMethodName: string, blobFilterName = "") {
|
|
9
|
+
var header_date = new Date().toUTCString();
|
|
10
|
+
var apiMethod = apiMethodName.toUpperCase();
|
|
11
|
+
|
|
12
|
+
var url = new URL(`https://${storageAccount}.blob.core.windows.net/${containerName}?restype=container&comp=list&prefix=${blobFilterName}`);
|
|
13
|
+
const signatureParts = [apiMethod, "", "", "", "", "", "", "", "", "", "", ""]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const canonicalHeaderParts = [];
|
|
17
|
+
canonicalHeaderParts.push(`x-ms-date:${header_date}`);
|
|
18
|
+
canonicalHeaderParts.push(`x-ms-version:2018-03-28`);
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
// Add headers to signature
|
|
22
|
+
signatureParts.push.apply(signatureParts, canonicalHeaderParts);
|
|
23
|
+
|
|
24
|
+
// Construct CanonicalizedResource
|
|
25
|
+
const canonicalResourceParts = [`/${storageAccount}${url.pathname}`];
|
|
26
|
+
const canonicalQueryNames: string[] = [];
|
|
27
|
+
url.searchParams.forEach(function (value, key) {
|
|
28
|
+
canonicalQueryNames.push(key.toLowerCase());
|
|
29
|
+
});
|
|
30
|
+
canonicalQueryNames.sort();
|
|
31
|
+
canonicalQueryNames.forEach(queryName => {
|
|
32
|
+
const value = url.searchParams.get(queryName);
|
|
33
|
+
|
|
34
|
+
canonicalResourceParts.push(`${queryName}:${value}`);
|
|
35
|
+
});
|
|
36
|
+
// Add resource to signature
|
|
37
|
+
signatureParts.push.apply(signatureParts, canonicalResourceParts);
|
|
38
|
+
|
|
39
|
+
// Now, construct signature raw string
|
|
40
|
+
const signatureRaw = signatureParts.join("\n");
|
|
41
|
+
|
|
42
|
+
// Hash it using HMAC-SHA256 and then encode using base64
|
|
43
|
+
|
|
44
|
+
const signatureBytes = CryptoJS.HmacSHA256(signatureRaw, CryptoJS.enc.Base64.parse(storageAccountKey));
|
|
45
|
+
const signatureEncoded = signatureBytes.toString(CryptoJS.enc.Base64);
|
|
46
|
+
|
|
47
|
+
var config = {
|
|
48
|
+
method: apiMethod,
|
|
49
|
+
url: `https://${storageAccount}.blob.core.windows.net/${containerName}?restype=container&comp=list&prefix=${blobFilterName}`,
|
|
50
|
+
headers: {
|
|
51
|
+
"Authorization": `SharedKey ${storageAccount}:${signatureEncoded}`,
|
|
52
|
+
"x-ms-date": header_date,
|
|
53
|
+
"x-ms-version": "2018-03-28"
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
var response = await TokenGenerators.request(config);
|
|
58
|
+
var apiData = response.data
|
|
59
|
+
var XmlNode = new DOMParser().parseFromString(apiData, 'text/xml');
|
|
60
|
+
var jsonObj = await XmlToJson.xmlToJson(XmlNode);
|
|
61
|
+
var blobs = jsonObj.EnumerationResults.Blobs.Blob;
|
|
62
|
+
var newBlobs = [];
|
|
63
|
+
if (blobs.length) {
|
|
64
|
+
for (var i = 0; i < blobs.length; i++) {
|
|
65
|
+
var blob = {
|
|
66
|
+
"fileName": (blobs[i].Name['#text']).replace(blobFilterName, ""),
|
|
67
|
+
"modifiedTime": (Date.parse(blobs[i].Properties['Last-Modified']['#text'])),
|
|
68
|
+
"status": Math.floor(Date.now() - (Date.parse(blobs[i].Properties['Last-Modified']['#text'])) / 1000) > 30 ? 1 : 0,
|
|
69
|
+
}
|
|
70
|
+
newBlobs.push(blob)
|
|
71
|
+
}
|
|
72
|
+
} else if (blobs.fileName) {
|
|
73
|
+
var blob = {
|
|
74
|
+
"fileName": (blobs.Name['#text']).replace(blobFilterName, ""),
|
|
75
|
+
"modifiedTime": (Date.parse(blobs.Properties['Last-Modified']['#text'])),
|
|
76
|
+
"status": Math.floor(Date.now() - (Date.parse(blobs.Properties['Last-Modified']['#text'])) / 1000) > 30 ? 1 : 0,
|
|
77
|
+
}
|
|
78
|
+
newBlobs.push(blob)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
newBlobs.sort((a, b) => a.fileName > b.fileName ? 1 : ((b.fileName > a.fileName) ? -1 : 0))
|
|
82
|
+
newBlobs.sort((a, b) => a.modifiedTime < b.modifiedTime ? 1 : ((b.modifiedTime < a.modifiedTime) ? -1 : 0))
|
|
83
|
+
|
|
84
|
+
return newBlobs;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { expect } from "@playwright/test";
|
|
2
|
+
import { isDeepStrictEqual } from "util";
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
|
|
5
|
+
export class Comparisions {
|
|
6
|
+
|
|
7
|
+
static async compareObjects(actualObj: string, expectedObj: string) {
|
|
8
|
+
var same;
|
|
9
|
+
console.log("Actual Obj: " + actualObj + " and Expected Obj: " + expectedObj)
|
|
10
|
+
same = _.isEqual(actualObj, expectedObj);
|
|
11
|
+
console.log(same);
|
|
12
|
+
return same;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
static async compareUnorderedJSONObjects(actualObj: { [x: string]: any; }, expectedObj: { [x: string]: any; }) {
|
|
16
|
+
var Keydata = Object.keys(expectedObj)
|
|
17
|
+
var result = new Array();
|
|
18
|
+
var boolean;
|
|
19
|
+
for (var i = 0; i < Keydata.length; i++) {
|
|
20
|
+
if (actualObj[Keydata[i]] == expectedObj[Keydata[i]]) {
|
|
21
|
+
result.push(true)
|
|
22
|
+
} else {
|
|
23
|
+
result.push(false)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
boolean = result.includes(false) ? false : true;
|
|
27
|
+
return boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static compareJSONObjects(receivedJson, expectedJson): Boolean {
|
|
31
|
+
let isJsonEqual = true;
|
|
32
|
+
let receivedKeys: string[] = this.getJsonKeys(receivedJson);
|
|
33
|
+
let expectedKeys = this.getJsonKeys(expectedJson);
|
|
34
|
+
let receivedValues = this.getJsonValues(receivedJson);
|
|
35
|
+
let expectedValues = this.getJsonValues(expectedJson);
|
|
36
|
+
let count: number = this.getJsonCount(receivedJson);
|
|
37
|
+
|
|
38
|
+
for (let i: number = 0; i < count; i++) {
|
|
39
|
+
let receivedKey = receivedKeys[i];
|
|
40
|
+
let expectedKey = expectedKeys[i];
|
|
41
|
+
let receivedValue = receivedValues[i];
|
|
42
|
+
let expectedValue = expectedValues[i];
|
|
43
|
+
|
|
44
|
+
let isKeyEmpty: Boolean = receivedKey == (null || "");
|
|
45
|
+
let isKeyEqual: Boolean = receivedKey == expectedKey;
|
|
46
|
+
let isValueEqual: Boolean = isDeepStrictEqual(receivedValue, expectedValue);
|
|
47
|
+
expect.soft(!isKeyEmpty, "Actual Key received is not null.");
|
|
48
|
+
expect.soft(isKeyEqual, "Actual key received is: '" + receivedKey + "' and expected key is: '" + expectedKey + "'.").toBeTruthy();
|
|
49
|
+
expect.soft(isValueEqual, "Actual value received for '" + expectedKey + "' is " + JSON.stringify(receivedValue) + " and \nExpected value is: " + JSON.stringify(expectedValue) + ".").toBeTruthy();
|
|
50
|
+
|
|
51
|
+
if (isKeyEmpty || !isKeyEqual || !isValueEqual) {
|
|
52
|
+
isJsonEqual = false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return isJsonEqual;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//Get Keys from Json Files
|
|
59
|
+
static getJsonKeys(jsonFile) {
|
|
60
|
+
return Object.keys(jsonFile);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//Get Values From Json Files
|
|
64
|
+
static getJsonValues(jsonFile) {
|
|
65
|
+
return Object.values(jsonFile);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//Get Count of Json items
|
|
69
|
+
static getJsonCount(jsonFile) {
|
|
70
|
+
return Object.keys(jsonFile).length;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import XLSX from 'xlsx';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
export class DocumentUtility {
|
|
7
|
+
|
|
8
|
+
static async readData(filePath: string) {
|
|
9
|
+
return XLSX.readFile(filePath, { cellDates: true, bookVBA: true, sheetStubs: true, cellNF: true });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static async readDataFromExcelorCSV(filePath: string, sheetname?: string) {
|
|
13
|
+
const workbook = await DocumentUtility.readData(filePath);
|
|
14
|
+
const sheet_name_list = workbook.SheetNames;
|
|
15
|
+
sheetname = (sheetname === undefined ? sheet_name_list[0] : sheetname);
|
|
16
|
+
return XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]]);
|
|
17
|
+
|
|
18
|
+
// const tempTwoDimentionalArr = new Array(_.keys(excelData[0]).length);
|
|
19
|
+
// for (var i = 0; i < tempTwoDimentionalArr.length; i++) {
|
|
20
|
+
// tempTwoDimentionalArr[i] = new Array();
|
|
21
|
+
// }
|
|
22
|
+
// return _.map(excelData, function (obj) {
|
|
23
|
+
// return _.reduce(_.keys(excelData[0]), function (result, columnName, index) {
|
|
24
|
+
// tempTwoDimentionalArr[index].push(obj[columnName])
|
|
25
|
+
// result[columnName] = tempTwoDimentionalArr[index];
|
|
26
|
+
// return result;
|
|
27
|
+
// }, {})
|
|
28
|
+
// })[0];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static async filterData(filePath: string, sheetName: string, filterObject: object) {
|
|
32
|
+
let fileData = await DocumentUtility.readData(filePath);
|
|
33
|
+
return _.filter(XLSX.utils.sheet_to_json(fileData.Sheets[sheetName]), filterObject)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static async updateExcelData(filePath: string, sheetName: string, exportData: Array<object>) {
|
|
37
|
+
const workbook = await DocumentUtility.readData(filePath);
|
|
38
|
+
workbook.Sheets[sheetName] = XLSX.utils.json_to_sheet(exportData);
|
|
39
|
+
XLSX.writeFile(workbook, filePath);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static async deleteAllFilesUnderDIr(dirPath: string) {
|
|
43
|
+
for (const file of await fs.readdir(dirPath)) {
|
|
44
|
+
await fs.unlink(path.join(dirPath, file));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TokenGenerators } from './api_axios'
|
|
2
|
+
|
|
3
|
+
export class KeyVaultMethods {
|
|
4
|
+
|
|
5
|
+
static async getSecrets(secretName: any) {
|
|
6
|
+
var keyvault = `${process.env.subscription}conm${process.env.env}${process.env.locationshortcut}securekv`
|
|
7
|
+
var token = await TokenGenerators.generateKeyVaultAccessToken();
|
|
8
|
+
var config = {
|
|
9
|
+
method: 'get',
|
|
10
|
+
url: `https://${keyvault}.vault.azure.net/secrets/${secretName}?api-version=2016-10-01`,
|
|
11
|
+
headers: { "Authorization": `Bearer ${token}` }
|
|
12
|
+
};
|
|
13
|
+
var response = await TokenGenerators.request(config);
|
|
14
|
+
return response.data;
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
//const cosmosClient = require("@azure/cosmos").CosmosClient;
|
|
2
|
+
const sql = require('mssql');
|
|
3
|
+
import { AnyNaptrRecord } from "dns";
|
|
4
|
+
import fsr from "fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import XLSX from "xlsx";
|
|
7
|
+
|
|
8
|
+
export class TestData {
|
|
9
|
+
|
|
10
|
+
static async sqlDBConnection() {
|
|
11
|
+
var server = process.env.subscription + "-conm-" + process.env.env + "-" + process.env.locationshortcut + "-sqlserver-dbs.database.windows.net"
|
|
12
|
+
var database = "ConnectivityModuleDb"
|
|
13
|
+
var config = {
|
|
14
|
+
server: server,
|
|
15
|
+
// user: 'mssqladministrator',
|
|
16
|
+
// password: process.env.sqldbpassword,
|
|
17
|
+
database: database,
|
|
18
|
+
requestTimeout: 600000,
|
|
19
|
+
options: {
|
|
20
|
+
encrypt: true // Use this if you're on Windows Azure
|
|
21
|
+
},
|
|
22
|
+
authentication: {
|
|
23
|
+
type: "azure-active-directory-service-principal-secret",
|
|
24
|
+
options: {
|
|
25
|
+
clientId: process.env.servicePrincipalClientId,
|
|
26
|
+
clientSecret: process.env.servicePrincipalClientSecret,
|
|
27
|
+
tenantId: process.env.tenantId
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var conn = new sql.ConnectionPool(config);
|
|
32
|
+
return conn;
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
static async executeSqlQuery(pool1: { connect: () => any; on: (arg0: string, arg1: (err: any) => void) => void; request: () => any; close: () => void; }, queryString: any) {
|
|
36
|
+
var pool1Connect = await pool1.connect();
|
|
37
|
+
pool1.on('error', err => {
|
|
38
|
+
console.log(err);
|
|
39
|
+
return;
|
|
40
|
+
})
|
|
41
|
+
await pool1Connect;
|
|
42
|
+
try {
|
|
43
|
+
const request = pool1.request(); // or: new sql.Request(pool1)
|
|
44
|
+
const result = await request.query(queryString)
|
|
45
|
+
return result;
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error('SQL error', err);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
pool1.close();
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
static async generateRandomUniqeIDNumber() {
|
|
57
|
+
const d = new Date();
|
|
58
|
+
let minutes = d.getMinutes();
|
|
59
|
+
let seconds = d.getSeconds();
|
|
60
|
+
let hour = d.getHours();
|
|
61
|
+
const result = Math.random().toString(36).substring(2, 5).toUpperCase();
|
|
62
|
+
let localUid = "SNO" + result + hour + minutes.toString() + seconds;
|
|
63
|
+
return localUid;
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static async getUTCTimeCustom24hrs(localTime: string) {
|
|
68
|
+
|
|
69
|
+
console.log(localTime);
|
|
70
|
+
var localDate = new Date();
|
|
71
|
+
|
|
72
|
+
localDate.setHours(parseInt(localTime.split(":")[0].trim()));
|
|
73
|
+
|
|
74
|
+
localDate.setMinutes(parseInt(localTime.split(":")[1].substring(0, 2).trim()))
|
|
75
|
+
localDate.setSeconds(0, 0)
|
|
76
|
+
console.log("**** Returning time " + localDate.toISOString());
|
|
77
|
+
return localDate.toISOString()
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static async waitFortimeOut(waitTime: any) {
|
|
82
|
+
const sleep = (waitTimeInMs: any) => new Promise(resolve => setTimeout(resolve, waitTimeInMs));
|
|
83
|
+
await sleep(waitTime);
|
|
84
|
+
}
|
|
85
|
+
static async executeCosmosQuery(queryString: any) {
|
|
86
|
+
/*var endpoint = process.env.cosmosConfig.endpoint;
|
|
87
|
+
var key = process.env.cosmosConfig.key;
|
|
88
|
+
var databaseId = process.env.cosmosConfig.databaseId;
|
|
89
|
+
var containerId = process.env.cosmosConfig.containerId;
|
|
90
|
+
const client = new cosmosClient({ endpoint, key });
|
|
91
|
+
|
|
92
|
+
const database = client.database(databaseId);
|
|
93
|
+
const container = database.container(containerId);
|
|
94
|
+
console.log(`Querying container: Items`);
|
|
95
|
+
|
|
96
|
+
// query to return all items
|
|
97
|
+
const querySpec = {
|
|
98
|
+
query: queryString
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// read all items in the Items container
|
|
102
|
+
var {resources: items} = await container.items.query(querySpec).fetchAll();
|
|
103
|
+
return items;*/
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static async getUTCTimeCustom(localTime: any) {
|
|
107
|
+
|
|
108
|
+
console.log(localTime);
|
|
109
|
+
var localDate = new Date();
|
|
110
|
+
var hours = parseInt(localTime.split(":")[0].trim());
|
|
111
|
+
if (localTime.includes('PM')) {
|
|
112
|
+
if (hours == 12) {
|
|
113
|
+
localDate.setHours(parseInt(localTime.split(":")[0].trim()));
|
|
114
|
+
} else {
|
|
115
|
+
localDate.setHours(parseInt(localTime.split(":")[0].trim()) + 12);
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
if (hours == 12) {
|
|
119
|
+
localDate.setHours(0);
|
|
120
|
+
} else {
|
|
121
|
+
localDate.setHours(parseInt(localTime.split(":")[0].trim()));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
localDate.setMinutes(parseInt(localTime.split(":")[1].substring(0, 2).trim()))
|
|
125
|
+
localDate.setSeconds(0, 0)
|
|
126
|
+
console.log("**** Returning time " + localDate.toISOString());
|
|
127
|
+
return localDate.toISOString()
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
static async ConvertCSVDataToJSONObject(csvfilePath: any, jsonfilePath: any) {
|
|
131
|
+
try {
|
|
132
|
+
const pathtoCSV = path.resolve(__dirname, csvfilePath);
|
|
133
|
+
const pathtoJson = path.resolve(__dirname, jsonfilePath);
|
|
134
|
+
const csvfile = fsr.readFileSync(pathtoCSV);
|
|
135
|
+
const arr = csvfile.toString().split(/[\r\n]+/);
|
|
136
|
+
var jsonObject = [];
|
|
137
|
+
var headers = arr[0].split(',')
|
|
138
|
+
|
|
139
|
+
for (var i = 1; i < arr.length; i++) {
|
|
140
|
+
var data = arr[i].split(',');
|
|
141
|
+
var object = {};
|
|
142
|
+
for (var j = 0; j < data.length; j++) {
|
|
143
|
+
object[headers[j].trim()] = data[j].trim();
|
|
144
|
+
}
|
|
145
|
+
jsonObject.push(object)
|
|
146
|
+
}
|
|
147
|
+
const result = jsonObject;
|
|
148
|
+
fsr.writeFileSync(pathtoJson, JSON.stringify(jsonObject));
|
|
149
|
+
|
|
150
|
+
return result;
|
|
151
|
+
|
|
152
|
+
} catch (exception) {
|
|
153
|
+
console.log(exception.message);
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
static async ConvertCSVDataToJSONFile(csvfilePath: any, jsonfilePath: any) {
|
|
159
|
+
try {
|
|
160
|
+
const pathtoCSV = path.resolve(__dirname, csvfilePath);
|
|
161
|
+
const pathtoJson = path.resolve(__dirname, jsonfilePath);
|
|
162
|
+
const csvfile = fsr.readFileSync(pathtoCSV);
|
|
163
|
+
const arr = csvfile.toString().split(/[\r\n]+/);
|
|
164
|
+
var jsonObject = [];
|
|
165
|
+
var headers = arr[0].split('|')
|
|
166
|
+
for (var i = 1; i < arr.length; i++) {
|
|
167
|
+
var data = arr[i].split('|');
|
|
168
|
+
var object = {};
|
|
169
|
+
for (var j = 0; j < data.length; j++) {
|
|
170
|
+
object[headers[j].trim()] = data[j].trim();
|
|
171
|
+
}
|
|
172
|
+
jsonObject.push(object)
|
|
173
|
+
}
|
|
174
|
+
const result = jsonObject;
|
|
175
|
+
fsr.writeFileSync(pathtoJson, JSON.stringify(jsonObject));
|
|
176
|
+
return result;
|
|
177
|
+
|
|
178
|
+
} catch (exception) {
|
|
179
|
+
console.log(exception.message);
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
static async ConvertCSVDataToKeyValue(csvfilePath: any, jsonfilePath: any) {
|
|
185
|
+
try {
|
|
186
|
+
const pathtoCSV = path.resolve(__dirname, csvfilePath);
|
|
187
|
+
const pathtoJson = path.resolve(__dirname, jsonfilePath);
|
|
188
|
+
const csvfile = fsr.readFileSync(pathtoCSV);
|
|
189
|
+
const arr = csvfile.toString().split(/[\r\n]+/);
|
|
190
|
+
var jsonObject = [];
|
|
191
|
+
|
|
192
|
+
for (var i = 0; i < arr.length; i++) {
|
|
193
|
+
var data = arr[i].split(',');
|
|
194
|
+
var object = {};
|
|
195
|
+
for (var j = 1; j < data.length; j++) {
|
|
196
|
+
object[data[0].trim()] = data[j].trim();
|
|
197
|
+
}
|
|
198
|
+
jsonObject.push(object)
|
|
199
|
+
}
|
|
200
|
+
const result = jsonObject;
|
|
201
|
+
fsr.writeFileSync(pathtoJson, JSON.stringify(jsonObject));
|
|
202
|
+
return result;
|
|
203
|
+
|
|
204
|
+
} catch (exception) {
|
|
205
|
+
console.log(exception.message);
|
|
206
|
+
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
static async GenerateTripLinksFile(tripdetails: any, triplinks_path: any, triplinks_folder: any) {
|
|
211
|
+
try {
|
|
212
|
+
var pathtoTripLinks = path.resolve(__dirname, triplinks_path);
|
|
213
|
+
var dir = path.resolve(__dirname, triplinks_folder);
|
|
214
|
+
if (!fsr.existsSync(dir)) {
|
|
215
|
+
fsr.mkdirSync(dir);
|
|
216
|
+
if (!fsr.existsSync(pathtoTripLinks)) {
|
|
217
|
+
fsr.open(pathtoTripLinks, 'w', function (err, file) {
|
|
218
|
+
if (err) throw err;
|
|
219
|
+
console.log('File is opened in write mode.');
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
if (!fsr.existsSync(pathtoTripLinks)) {
|
|
225
|
+
fsr.open(pathtoTripLinks, 'w', function (err, file) {
|
|
226
|
+
if (err) throw err;
|
|
227
|
+
console.log('File is opened in write mode.');
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
let existingTrips = fsr.readFileSync(pathtoTripLinks, "utf-8");
|
|
232
|
+
if (existingTrips.length != 0) {
|
|
233
|
+
var jsonObject = [];
|
|
234
|
+
jsonObject = JSON.parse(existingTrips);
|
|
235
|
+
}
|
|
236
|
+
else var jsonObject = [];
|
|
237
|
+
var headers = tripdetails[0].split(',')
|
|
238
|
+
for (var i = 1; i < tripdetails.length; i++) {
|
|
239
|
+
var data = tripdetails[i].split(',');
|
|
240
|
+
var object = {};
|
|
241
|
+
for (var j = 0; j < data.length; j++) {
|
|
242
|
+
object[headers[j].trim()] = data[j].trim();
|
|
243
|
+
}
|
|
244
|
+
jsonObject.push(object)
|
|
245
|
+
}
|
|
246
|
+
const result = jsonObject;
|
|
247
|
+
fsr.writeFileSync(pathtoTripLinks, JSON.stringify(jsonObject));
|
|
248
|
+
return result;
|
|
249
|
+
} catch (exception) {
|
|
250
|
+
console.log(exception.message);
|
|
251
|
+
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
static async readExcel(path: string) {
|
|
256
|
+
const workbook = XLSX.readFile(path);
|
|
257
|
+
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
|
258
|
+
const jsonSheet = XLSX.utils.sheet_to_json(sheet);
|
|
259
|
+
console.log(jsonSheet);
|
|
260
|
+
return jsonSheet;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export class XmlToJson {
|
|
2
|
+
|
|
3
|
+
static async xmlToJson(xml: any) {
|
|
4
|
+
|
|
5
|
+
// Create the return object
|
|
6
|
+
var obj: any = {};
|
|
7
|
+
|
|
8
|
+
if (xml.nodeType == 1) { // element
|
|
9
|
+
// do attributes
|
|
10
|
+
if (xml.attributes.length > 0) {
|
|
11
|
+
obj["@attributes"] = {};
|
|
12
|
+
for (var j = 0; j < xml.attributes.length; j++) {
|
|
13
|
+
var attribute = xml.attributes.item(j);
|
|
14
|
+
obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
} else if (xml.nodeType == 3) { // text
|
|
18
|
+
obj = xml.nodeValue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// do children
|
|
22
|
+
if (xml.hasChildNodes()) {
|
|
23
|
+
for (var i = 0; i < xml.childNodes.length; i++) {
|
|
24
|
+
var item = xml.childNodes.item(i);
|
|
25
|
+
var nodeName = item.nodeName;
|
|
26
|
+
if (typeof (obj[nodeName]) == "undefined") {
|
|
27
|
+
obj[nodeName] = this.xmlToJson(item);
|
|
28
|
+
} else {
|
|
29
|
+
if (typeof (obj[nodeName].push) == "undefined") {
|
|
30
|
+
var old = obj[nodeName];
|
|
31
|
+
obj[nodeName] = [];
|
|
32
|
+
obj[nodeName].push(old);
|
|
33
|
+
}
|
|
34
|
+
obj[nodeName].push(this.xmlToJson(item));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return obj;
|
|
39
|
+
};
|
|
40
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"sourceMap": true,
|
|
4
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
5
|
+
|
|
6
|
+
/* Projects */
|
|
7
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
8
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
9
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
10
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
11
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
12
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
13
|
+
|
|
14
|
+
/* Language and Environment */
|
|
15
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
16
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
17
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
18
|
+
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
|
19
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
20
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
21
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
22
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
23
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
24
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
25
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
26
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
27
|
+
|
|
28
|
+
/* Modules */
|
|
29
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
30
|
+
"rootDir": "./", /* Specify the root folder within your source files. */
|
|
31
|
+
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
32
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
33
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
34
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
35
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
36
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
37
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
38
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
39
|
+
"resolveJsonModule": true, /* Enable importing .json files. */
|
|
40
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
41
|
+
|
|
42
|
+
/* JavaScript Support */
|
|
43
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
44
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
45
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
46
|
+
|
|
47
|
+
/* Emit */
|
|
48
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
49
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
50
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
51
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
52
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
53
|
+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
54
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
55
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
56
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
57
|
+
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
|
58
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
59
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
60
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
61
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
62
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
63
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
64
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
65
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
66
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
67
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
68
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
69
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
70
|
+
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
|
71
|
+
|
|
72
|
+
/* Interop Constraints */
|
|
73
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
74
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
75
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
76
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
77
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
78
|
+
|
|
79
|
+
/* Type Checking */
|
|
80
|
+
"strict": false, /* Enable all strict type-checking options. */
|
|
81
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
82
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
83
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
84
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
85
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
86
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
87
|
+
"useUnknownInCatchVariables": false, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
88
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
89
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
90
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
91
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
92
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
93
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
94
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
95
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
96
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
97
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
98
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
99
|
+
|
|
100
|
+
/* Completeness */
|
|
101
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
102
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
103
|
+
},
|
|
104
|
+
"include": ["src/**/*.ts"],
|
|
105
|
+
"exclude": ["node_modules"]
|
|
106
|
+
}
|