Skip to content

Commit d08f04c

Browse files
committed
test message
1 parent 12d060c commit d08f04c

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/inputVerifier.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export const isValidJson = (str: string): Boolean => {
2+
if (!str) {
3+
console.error('Input is required');
4+
return false;
5+
}
6+
27
try {
38
const jsonObj = JSON.parse(str);
49
if (!Array.isArray(jsonObj)) {
@@ -12,9 +17,19 @@ export const isValidJson = (str: string): Boolean => {
1217
}
1318
};
1419

15-
export const verifyInput = (inp: string): Boolean => isValidJson(inp);
20+
export const verifyInput = (inp: string): Boolean => {
21+
if (inp === undefined || inp === null) {
22+
console.error('Input is required');
23+
return false;
24+
}
25+
return isValidJson(inp);
26+
};
1627

1728
export const verifyTableOptions = (options: string): boolean => {
29+
if (!options) {
30+
console.error('Table options are required');
31+
return false;
32+
}
1833
try {
1934
JSON.parse(options);
2035
return true;

src/service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ const parseAndValidateInput = (inp: string, tableOptions?: string): ParsedInput
1818
return null;
1919
}
2020

21-
return {
22-
data: JSON.parse(inp),
23-
options: tableOptions && JSON.parse(tableOptions)
24-
};
21+
try {
22+
return {
23+
data: JSON.parse(inp),
24+
options: tableOptions && JSON.parse(tableOptions)
25+
};
26+
} catch (err) {
27+
console.log(`not a valid input ${inp}`);
28+
return null;
29+
}
2530
};
2631

2732
const printTableFromInp = (inp: string, tableOptions?: string): void | string => {

test/service.test.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)