{"size": 1522, "ext": "js", "max_stars_repo_path": "src/routes.js", "max_stars_repo_name": "vaibhavpandeyvpz/passbird", "max_stars_repo_stars_event_min_datetime": "2021-12-24T15:49:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-24T15:49:00.000Z", "max_issues_repo_path": "src/routes.js", "max_issues_repo_name": "vaibhavpandeyvpz/passbird", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/routes.js", "max_forks_repo_name": "vaibhavpandeyvpz/passbird", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.7662337662, "max_line_length": 56, "alphanum_fraction": 0.5361366623}
const free = require('free-email-domains');
const disposables = require('disposable-email-domains');
const Joi = require('joi');
const router = require('koa-joi-router');
const zxcvbn = require('zxcvbn');

const routes = router();

routes.route({
  method: 'get',
  path: '/',
  async handler(ctx) {
    ctx.status = 200;
    ctx.body = {
      '/': ['GET'],
      '/email': ['POST'],
      '/password': ['POST'],
    };
  },
});

routes.route({
  method: 'post',
  path: '/email',
  validate: {
    body: {
      email: Joi.string().lowercase().email(),
    },
    type: 'form',
  },
  async handler(ctx) {
    const { email } = ctx.request.body;
    const domain = email.split('@').pop();
    let type;
    if (disposables.indexOf(domain) >= 0) {
      type = 'disposable';
    } else if (free.indexOf(domain) >= 0) {
      type = 'free';
    } else {
      type = 'business';
    }

    ctx.status = 200;
    ctx.body = {
      type,
      types: ['disposable', 'free', 'business'],
    };
  },
});

routes.route({
  method: 'post',
  path: '/password',
  validate: {
    body: {
      password: Joi.string(),
    },
    type: 'form',
  },
  async handler(ctx) {
    const { password } = ctx.request.body;
    const result = zxcvbn(password, null);
    ctx.status = 200;
    ctx.body = {
      feedback: result.feedback.warning || null,
      strength: {
        value: result.score + 1,
        min: 1,
        max: 5,
      },
      suggestions: result.feedback.suggestions,
    };
  },
});

module.exports = routes;
