Skip to content

Commit bbcba30

Browse files
committed
Bug Fixes
1 parent 3ebc646 commit bbcba30

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ npm-debug.log*
55
yarn-debug.log*
66
yarn-error.log*
77
lerna-debug.log*
8+
db.js
89

910

1011
# Diagnostic reports (https://nodejs.org/api/report.html)

example/test2.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const {
2-
async
3-
} = require('crypto-random-string');
41
const _udf = require('../index.js');
2+
const conn = require('./db.js');
53

6-
let nodeUDF = new _udf();
4+
let nodeUDF = new _udf({
5+
con: conn
6+
});
77

88
let {
99
convertToTradingSymbol,
@@ -33,4 +33,18 @@ const testme = async () => {
3333
}
3434
}
3535

36-
//USDINR2110173CE
36+
37+
const test2 = async () => {
38+
try {
39+
let sql = 'select * from users_db';
40+
let result = await nodeUDF.sqlQuery(sql, [], false, conn);
41+
let r = nodeUDF.convertToTable(result, ['id', 'client', 'password', 'api_key'], true, false, " | ", decimalLengths = 0, stringSplitter = ",", bunkColumn = 0, isfixedformat = false);
42+
43+
console.log(r);
44+
45+
} catch (e) {
46+
console.log(e);
47+
}
48+
}
49+
50+
test2()

public_api/bhavcopy.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ class BhavCopy {
282282
* @return Promise
283283
*/
284284
bhavdownload(reqObject, isfo = false) {
285-
console.log(this)
286285
return new Promise((resolve, reject) => {
287286
let {
288287
month,

string_udf/table.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const get_negative = (arr, total_cols) => {
2828
const get_positive = (arr, total_cols) => {
2929
let col_positive = [];
3030
for (let i = 0; i < total_cols; i++) {
31-
let _arr = arrayColumn(arr, i).filter(r => r > 0);
31+
let _arr = arrayColumn(arr, i).filter(r => r >= 0);
3232
let _n = Math.max(..._arr) || 0;
3333
col_positive.push(_n);
3434
}
@@ -77,7 +77,6 @@ class Table extends StringUDF {
7777
//get each col length
7878
let col_length = JSON.parse(JSON.stringify(array));
7979

80-
8180
let total_cols = col_length[0].length;
8281
if (col_length[0].constructor !== Array) return Promise.reject("Input is invalid for table conversion.")
8382

@@ -98,23 +97,26 @@ class Table extends StringUDF {
9897
let col_length_arr = col_length.map((r) => r.map((c) => lengths(c, decimalLengths)));
9998
let col_max = [...max_string_lengths(col_length_arr, total_cols)];
10099

100+
// console.log(col_negative, col_positive, col_length_arr, col_max);
101+
102+
101103
const format_row = (arrayValue, index) => {
102104
var rowTxt = arrayValue;
105+
103106
//check decimal
104107
if (decimalLengths > 0 && typeof (rowTxt) == 'number')
105108
rowTxt = rowTxt.toFixed(decimalLengths);
106109

107-
if (index == total_cols - 1)
108-
return rowTxt;
110+
// if (index == total_cols - 1)
111+
// return rowTxt;
109112

110113
//add_space_if_col_have_negative
111114
let isNegative = col_negative[index] < 0 && rowTxt >= 0;
112115

113-
//add extra space if col have negative and postive length>negative
116+
//add extra space if col have negative and positive length>negative negative
114117
let positive_buffer = col_negative[index] < 0 && col_max[index] >= col_negative[index].toString().length && col_positive[index].toString().length >= col_negative[index].toString().length
115118

116-
var _spaces = (-isNegative + positive_buffer + col_max[index] - lengths(rowTxt, decimalLengths)) || 0;
117-
_spaces = _spaces < 0 ? 0 : _spaces;
119+
var _spaces = Math.max(0, ((-isNegative + positive_buffer + col_max[index] - lengths(rowTxt, decimalLengths)) || 0));
118120
let _txt = rowTxt + rpt(_spaces);
119121

120122
let _return = isNegative ? rpt(1) + _txt : _txt;

0 commit comments

Comments
 (0)