Skip to content

Commit

Permalink
Featured: add theme
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly.basaraba committed Dec 21, 2024
1 parent 65d2371 commit dc98b7a
Show file tree
Hide file tree
Showing 4 changed files with 3,527 additions and 48 deletions.
16 changes: 12 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ const filter = args.top ? 'top' : args.filter || 'all';
const amount = args.top || '';
const level = args.level || '';
const format = args.format || 'text';
const theme = args.theme || '';

const logHeader = (header) => console.log('\x1b[32m%s\x1b[0m', header);
const logDivider = () => console.log('_________________________');
const logExampleParams = () => {
console.log("\x1b[32m%s\x1b[0m", "Params example:");
console.log("--top ${amount}");
console.log("--level ( junior | middle | senior )");
console.log("--level ( basic | intermediate | advanced )");
console.log("--theme ( closures | storage | es6 | classes | database ... and other 203 themes)");
console.log("--format ( text | array | json )");
};

Expand All @@ -29,10 +31,15 @@ const displayQuestions = (result, format) => {
console.log(result);
break;
default:
result.forEach(({ title, url }) => {
result.forEach(({ title, url, text, theme }) => {
console.log('');
logHeader(`Question: ${title}`);
console.info(`Answer: \x1b]8;;${url}\x1b\\${url}\x1b]8;;\x1b\\`);
if (url) {
console.info(`Answer: \x1b]8;;${url}\x1b\\${url}\x1b]8;;\x1b\\`);
} else {
console.info(`Answer: ${text}`);
}
console.info(`Hash: ${theme.split(',').map((data) => ` #${data.trim().toLowerCase()}`)}`);
logDivider();
});
}
Expand All @@ -46,10 +53,11 @@ const main = async () => {
if (filter) console.log('Filter -', filter);
console.log('');

const result = await interviewQuestion({ filter, amount, level, format });
const result = await interviewQuestion({ filter, amount, level, format, theme });
displayQuestions(result, format);

console.log('');
console.log(`Found ${result.length} questions`);
logExampleParams();

if (verbose) console.log('Send questions');
Expand Down
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class InterviewQuestion {
* @returns {Promise<Array>} The filtered list of questions.
* @throws {Error} If an invalid level or filter type is provided.
*/
async execute(filter = 'all', amount = 0, level = null) {
async execute(filter = 'all', amount = 0, level = null, theme = null) {
let filteredData = this.data;

// Filter by level if provided
Expand All @@ -49,6 +49,11 @@ class InterviewQuestion {
filteredData = filteredData.filter(item => item.level === level);
}

// Filter by level if provided
if (theme) {
filteredData = filteredData.filter(item => item.theme.split(',').map((data) => data.trim().toLowerCase()).includes(theme));
}

switch (filter) {
case 'all':
return filteredData;
Expand Down Expand Up @@ -89,6 +94,6 @@ class InterviewQuestion {
*/
module.exports = async function (options = {}) {
const interviewQuestion = new InterviewQuestion(options);
const { filter = 'all', amount = 0, level = null } = options;
return interviewQuestion.execute(filter, amount, level);
const { filter = 'all', amount = 0, level = null, theme = null } = options;
return interviewQuestion.execute(filter, amount, level, theme);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interview-questions",
"version": "1.2.0",
"version": "1.2.3",
"main": "index.js",
"scripts": {
"test": "npx jest ./test/InterviewQuestion.test.js"
Expand Down
Loading

0 comments on commit dc98b7a

Please sign in to comment.