Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Feature/1/category #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
module.exports = {
"env": {
"browser": false,
"es6": true,
"mocha": true,
"node": true
},
"extends": [
"google",
"eslint:recommended"
],
"rules": {
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"camelcase": [2, {properties: "never"}],
"comma-dangle": 0,
"curly": 0,
"key-spacing": [2, {align: "value"}],
"max-len": [1, 120],
"no-control-regex": 0,
"no-console": 1,
"no-empty": [2, { "allowEmptyCatch": true }],
"no-eval": 1, // we use it on purpose
"no-loop-func": 1,
"no-multi-spaces": 0,
"no-proto": 1,
"no-unused-expressions": 1,
"no-unused-vars": 1,
"no-var": 0,
"no-warning-comments": 0,
"prefer-rest-params": 0,
"prefer-spread": 0,
"quote-props": 1,
"quotes": [2, "single", {avoidEscape: true}],
"require-jsdoc": 0,
}
'env': {
'browser': false,
'es6': true,
'mocha': true,
'node': true
},
'extends': [
'google',
'eslint:recommended'
],
'rules': {
'block-spacing': [2, 'always'],
'brace-style': [2, '1tbs', {'allowSingleLine': true}],
'camelcase': [2, {properties: 'never'}],
'comma-dangle': 0,
'curly': 0,
'key-spacing': [2, {align: 'value'}],
'max-len': [1, 120],
'no-control-regex': 0,
'no-console': 1,
'no-empty': [2, {'allowEmptyCatch': true}],
'no-eval': 1, // we use it on purpose
'no-loop-func': 1,
'no-multi-spaces': 0,
'no-proto': 1,
'no-unused-expressions': 1,
'no-unused-vars': 1,
'no-var': 0,
'no-warning-comments': 0,
'prefer-rest-params': 0,
'prefer-spread': 0,
'quote-props': 1,
'quotes': [2, 'single', {avoidEscape: true}],
'require-jsdoc': 0,
}
};
107 changes: 0 additions & 107 deletions lib/api.js

This file was deleted.

18 changes: 9 additions & 9 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function initLogLevel() {

function initDir() {
file.init();
file.mkdir(file.homeDir())
file.mkdir(file.homeDir());
}

function initPlugins(cb) {
Expand All @@ -77,13 +77,13 @@ function runCommand() {
var yargs = require('yargs');
h.width = yargs.terminalWidth();
yargs.commandDir('commands')
.completion()
.help('h')
.alias('h', 'help')
.version(false)
.epilog('Seek more help at https://skygragon.github.io/leetcode-cli/commands')
.wrap(Math.min(h.width, 120))
.argv;
.completion()
.help('h')
.alias('h', 'help')
.version(false)
.epilog('Seek more help at https://skygragon.github.io/leetcode-cli/commands')
.wrap(Math.min(h.width, 120))
.argv;
}

cli.run = function() {
Expand All @@ -96,7 +96,7 @@ cli.run = function() {
initColor();
initIcon();
initLogLevel();
initDir()
initDir();
initPlugins(function(e) {
if (e) return log.fatal(e);
cache.init();
Expand Down
64 changes: 33 additions & 31 deletions lib/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,34 @@ const cmd = {
desc: 'List questions',
builder: function(yargs) {
return yargs
.option('q', core.filters.query)
.option('s', {
alias: 'stat',
type: 'boolean',
default: false,
describe: 'Show statistics of listed questions'
})
.option('t', core.filters.tag)
.option('x', {
alias: 'extra',
type: 'boolean',
default: false,
describe: 'Show extra details: category, companies, tags.'
})
.positional('keyword', {
type: 'string',
default: '',
describe: 'Filter questions by keyword'
})
.example(chalk.yellow('leetcode list'), 'List all questions')
.example(chalk.yellow('leetcode list -x'), 'Show extra info of questions, e.g. tags')
.example('', '')
.example(chalk.yellow('leetcode list array'), 'List questions that has "array" in name')
.example(chalk.yellow('leetcode list -q eD'), 'List questions that with easy level and not done')
.example(chalk.yellow('leetcode list -t google'), 'List questions from Google company (require plugin)')
.example(chalk.yellow('leetcode list -t stack'), 'List questions realted to stack (require plugin)');
.option('q', core.filters.query)
.option('s', {
alias: 'stat',
type: 'boolean',
default: false,
describe: 'Show statistics of listed questions'
})
.option('t', core.filters.tag)
.option('x', {
alias: 'extra',
type: 'boolean',
default: false,
describe: 'Show extra details: category, companies, tags.'
})
.option('c', core.filters.category)
.positional('keyword', {
type: 'string',
default: '',
describe: 'Filter questions by keyword'
})
.example(chalk.yellow('leetcode list'), 'List all questions')
.example(chalk.yellow('leetcode list -x'), 'Show extra info of questions, e.g. tags')
.example('', '')
.example(chalk.yellow('leetcode list array'), 'List questions that has "array" in name')
.example(chalk.yellow('leetcode list -q eD'), 'List questions that with easy level and not done')
.example(chalk.yellow('leetcode list -t google'), 'List questions from Google company (require plugin)')
.example(chalk.yellow('leetcode list -t stack'), 'List questions realted to stack (require plugin)')
.example(chalk.yellow('leetcode list -c lcof'), 'List questions from category (require plugin)');
}
};

Expand All @@ -53,14 +55,14 @@ cmd.handler = function(argv) {
if (word.endsWith(word.substr(-1).repeat(6))) {
log.warn('Hmmm...you might need a new keyboard?');
}
problems = problems.filter(x => x.name.toLowerCase().includes(word));
problems = problems.filter((x) => x.name.toLowerCase().includes(word));
}

const stat = {};
for (let x of ['locked', 'starred', 'ac', 'notac', 'None', 'Easy', 'Medium', 'Hard']) stat[x] = 0;
for (const x of ['locked', 'starred', 'ac', 'notac', 'None', 'Easy', 'Medium', 'Hard']) stat[x] = 0;

problems = _.sortBy(problems, x => x.id);
for (let problem of problems) {
problems = _.sortBy(problems, (x) => x.id);
for (const problem of problems) {
stat[problem.level] = (stat[problem.level] || 0) + 1;
stat[problem.state] = (stat[problem.state] || 0) + 1;
if (problem.locked) ++stat.locked;
Expand All @@ -82,7 +84,7 @@ cmd.handler = function(argv) {

let buf = [];
let len = 0;
for (let x of badges) {
for (const x of badges) {
if (len + x.length + 3 >= 60) {
log.printf('%12s%s', ' ', chalk.gray(buf.join(' | ')));
buf = [];
Expand Down
27 changes: 19 additions & 8 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ core.filters = {
type: 'array',
default: [],
describe: 'Filter questions by tag'
},
category: {
alias: 'category',
type: 'string',
default: '',
describe: 'Filter questions by category'
}
};

function hasTag(o, tag) {
return Array.isArray(o) && o.some(x => x.indexOf(tag.toLowerCase()) >= 0);
return Array.isArray(o) && o.some((x) => x.indexOf(tag.toLowerCase()) >= 0);
}

const isLevel = (x, q) => x.level[0].toLowerCase() === q.toLowerCase();
const isACed = x => x.state === 'ac';
const isLocked = x => x.locked;
const isStarred = x => x.starred;
const isACed = (x) => x.state === 'ac';
const isLocked = (x) => x.locked;
const isStarred = (x) => x.starred;

const QUERY_HANDLERS = {
e: isLevel,
Expand All @@ -63,14 +69,19 @@ const QUERY_HANDLERS = {
core.filterProblems = function(opts, cb) {
this.getProblems(function(e, problems) {
if (e) return cb(e);

for (let q of (opts.query || '').split('')) {
for (const q of (opts.query || '').split('')) {
const f = QUERY_HANDLERS[q];
if (!f) continue;
problems = problems.filter(x => f(x, q));
problems = problems.filter((x) => f(x, q));
}

if (opts.category) {
problems = problems.filter((x) => {
return x.category === opts.category;
});
}

for (let t of (opts.tag || [])) {
for (const t of (opts.tag || [])) {
problems = problems.filter(function(x) {
return x.category === t ||
hasTag(x.companies, t) ||
Expand Down
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading