Skip to content

Commit 944d1fc

Browse files
committed
add data validation before process the actual data
1 parent 9c395f3 commit 944d1fc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/cli/single-feature.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { input, confirm } from '@inquirer/prompts'
44

55

66

7+
// Simplify std out from `console.log` into `print`
78
const print = console.log;
89

910

@@ -17,8 +18,7 @@ const print = console.log;
1718
* @param {Array} data - the raw data
1819
*/
1920
export default async function singleFeatureProcess(data) {
20-
console.clear()
21-
print('\n=====================================================\n')
21+
print('=====================================================\n')
2222
print(chalk.blue('SINGLE FEATURE PROCESS\n'))
2323

2424
const answers = await inquirer.prompt([
@@ -36,6 +36,21 @@ export default async function singleFeatureProcess(data) {
3636
}
3737
])
3838

39+
if (answers.feature == answers.label) {
40+
print(chalk.bgMagenta('Feature and label can not be same'))
41+
42+
if (await confirm({ message: 'Back?'})) return;
43+
}
44+
45+
46+
for (const item of data) {
47+
if (!Number.isNaN(item[answers.feature]) || !Number.isNaN(item[answers.label])) {
48+
print(chalk.redBright('\n[!] Some data is not a number! Unable to process further!'))
49+
await confirm({ message: 'Continue?'})
50+
return;
51+
}
52+
}
53+
3954

4055
/**
4156
* Calculate the value a and b to get equation y = a + bx

0 commit comments

Comments
 (0)