How to use hibp - 10 common examples

To help you get started, we’ve selected a few hibp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wKovacs64 / hibp / example / runkit.js View on Github external
const hibp = require('hibp');

hibp
  .breach('Adobe')
  .then(data => {
    if (data) {
      // Breach data found
      console.log(data);
    } else {
      console.log('No breach data found by that name.');
    }
  })
  .catch(err => {
    // Something went wrong.
    console.log(err.message);
  });
github wKovacs64 / pwned / src / commands / breach.ts View on Github external
export const handler = async ({
  name,
  raw,
}: BreachHandlerOptions): Promise => {
  if (!raw) {
    spinner.start();
  }

  try {
    const breachData = await breach(name, { userAgent });
    if (breachData && raw) {
      logger.log(JSON.stringify(breachData));
    } else if (breachData) {
      spinner.stop();
      logger.log(prettyjson.render(breachData));
    } else if (!breachData && !raw) {
      spinner.succeed('No breach found by that name.');
    }
  } catch (err) {
    if (!raw) {
      spinner.fail(err.message);
    } else {
      logger.error(err.message);
    }
  }
};
github wKovacs64 / pwned / src / api / getBreach.js View on Github external
export default (name, raw) => {
  if (!raw && process.stdout.isTTY) {
    spinner.start();
  }
  return Promise.resolve(breach(name))
    .then((breachData) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }
      if (breachData && raw) {
        logger.log(JSON.stringify(breachData));
      } else if (breachData) {
        logger.log(prettyjson.render(breachData));
      } else if (!breachData && !raw) {
        logger.log('No breach found by that name.');
      }
    })
    .catch((err) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }
github wKovacs64 / pwned / src / commands / ba.ts View on Github external
export const handler = async ({
  account,
  domainFilter: domain,
  includeUnverified,
  truncate,
  raw,
}: BaHandlerOptions): Promise => {
  if (!raw) {
    spinner.start();
  }

  try {
    const breachData = await breachedAccount(account.trim(), {
      domain,
      includeUnverified,
      truncate,
      userAgent,
    });
    if (breachData && raw) {
      logger.log(JSON.stringify(breachData));
    } else if (breachData) {
      spinner.stop();
      logger.log(prettyjson.render(breachData));
    } else if (!breachData && !raw) {
      spinner.succeed('Good news — no pwnage found!');
    }
  } catch (err) {
    if (!raw) {
      spinner.fail(err.message);
github wKovacs64 / pwned / src / api / getBreachedAccount.js View on Github external
export default (account, domain, truncate, raw) => {
  if (!raw && process.stdout.isTTY) {
    spinner.start();
  }
  return Promise.resolve(breachedAccount(account, { domain, truncate }))
    .then((breachData) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }
      if (breachData && raw) {
        logger.log(JSON.stringify(breachData));
      } else if (breachData) {
        logger.log(prettyjson.render(breachData));
      } else if (!breachData && !raw) {
        logger.log('Good news — no pwnage found!');
      }
    })
    .catch((err) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }
github wKovacs64 / pwned / src / api / getPastes.js View on Github external
export default (email, raw) => {
  if (!raw && process.stdout.isTTY) {
    spinner.start();
  }
  return Promise.resolve(pasteAccount(email))
    .then((pasteData) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }
      if (pasteData && raw) {
        logger.log(JSON.stringify(pasteData));
      } else if (pasteData) {
        logger.log(prettyjson.render(pasteData));
      } else if (!pasteData && !raw) {
        logger.log('Good news — no pwnage found!');
      }
    })
    .catch((err) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }
github wKovacs64 / pwned / src / commands / pa.ts View on Github external
export const handler = async ({
  email,
  raw,
}: PaHandlerOptions): Promise => {
  if (!raw) {
    spinner.start();
  }

  try {
    const pasteData = await pasteAccount(email, {
      apiKey: config.get('apiKey'),
      userAgent,
    });
    if (pasteData && raw) {
      logger.log(JSON.stringify(pasteData));
    } else if (pasteData) {
      spinner.stop();
      logger.log(prettyjson.render(pasteData));
    } else if (!pasteData && !raw) {
      spinner.succeed('Good news — no pwnage found!');
    }
  } catch (err) {
    const errMsg = translateApiError(err.message);
    if (!raw) {
      spinner.fail(errMsg);
    } else {
github wKovacs64 / pwned / src / api / getSearch.js View on Github external
export default (account, domain, truncate, raw) => {
  if (!raw && process.stdout.isTTY) {
    spinner.start();
  }
  return Promise.resolve(search(account, { domain, truncate }))
    .then((searchData) => {
      const foundData = !!(searchData.breaches || searchData.pastes);
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }
      if (foundData && raw) {
        logger.log(JSON.stringify(searchData));
      } else if (foundData) {
        logger.log(prettyjson.render(searchData));
      } else if (!foundData && !raw) {
        logger.log('Good news — no pwnage found!');
      }
    })
    .catch((err) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
github wKovacs64 / pwned / src / commands / search.ts View on Github external
export const handler = async ({
  account,
  domainFilter: domain,
  truncate,
  raw,
}: SearchHandlerOptions): Promise => {
  if (!raw) {
    spinner.start();
  }

  try {
    const searchData = await search(account, { domain, truncate, userAgent });
    const foundData = !!(searchData.breaches || searchData.pastes);
    if (foundData && raw) {
      logger.log(JSON.stringify(searchData));
    } else if (foundData) {
      spinner.stop();
      logger.log(prettyjson.render(searchData));
    } else if (!foundData && !raw) {
      spinner.succeed('Good news — no pwnage found!');
    }
  } catch (err) {
    if (!raw) {
      spinner.fail(err.message);
    } else {
      logger.error(err.message);
    }
  }
github wKovacs64 / pwned / src / api / getBreaches.js View on Github external
export default (domain, raw) => {
  if (!raw && process.stdout.isTTY) {
    spinner.start();
  }
  return Promise.resolve(breaches({ domain }))
    .then((breachData) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }
      if (breachData.length && raw) {
        logger.log(JSON.stringify(breachData));
      } else if (breachData.length) {
        logger.log(prettyjson.render(breachData));
      } else if (!breachData.length && !raw) {
        logger.log('No breaches found.');
      }
    })
    .catch((err) => {
      if (!raw && process.stdout.isTTY) {
        spinner.stop(true);
      }

hibp

An unofficial TypeScript SDK for the 'Have I been pwned?' service.

MIT
Latest version published 4 months ago

Package Health Score

72 / 100
Full package analysis