Skip to content

Commit

Permalink
Add includeUnverified option to breachedAccount function
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 committed Jan 20, 2019
1 parent 90820bd commit be01ad1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ an Error
| account | <code>string</code> | a username or email address |
| [options] | <code>object</code> | a configuration object |
| [options.domain] | <code>string</code> | a domain by which to filter the results (default: all domains) |
| [options.includeUnverified] | <code>boolean</code> | include "unverified" breaches in the results (by default, only verified breaches are included) |
| [options.truncate] | <code>boolean</code> | truncate the results to only include the name of each breach (default: false) |

**Example**
Expand All @@ -178,7 +179,7 @@ breachedAccount('foo')
```
**Example**
```js
breachedAccount('bar', { truncate: true })
breachedAccount('bar', { includeUnverified: true })
.then(data => {
if (data) {
// ...
Expand Down
14 changes: 14 additions & 0 deletions src/breachedAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ describe('breachedAccount', () => {
).resolves.toEqual(data));
});

describe('with includeUnverified', () => {
it('resolves with data from the remote API', () =>
expect(
breachedAccount('breached', { includeUnverified: true }),
).resolves.toEqual(data));
});

describe('with domain and truncateResults', () => {
it('resolves with data from the remote API', () =>
expect(
Expand Down Expand Up @@ -68,6 +75,13 @@ describe('breachedAccount', () => {
).resolves.toBeNull());
});

describe('with includeUnverified', () => {
it('resolves with null', () =>
expect(
breachedAccount('clean', { includeUnverified: true }),
).resolves.toBeNull());
});

describe('with domain and truncateResults', () => {
it('resolves with null', () =>
expect(
Expand Down
8 changes: 7 additions & 1 deletion src/breachedAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { Breach } from './types/remote-api.d';
* @param {object} [options] a configuration object
* @param {string} [options.domain] a domain by which to filter the results
* (default: all domains)
* @param {boolean} [options.includeUnverified] include "unverified" breaches in
* the results (by default, only verified breaches are included)
* @param {boolean} [options.truncate] truncate the results to only include
* the name of each breach (default: false)
* @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an
Expand All @@ -26,7 +28,7 @@ import { Breach } from './types/remote-api.d';
* // ...
* });
* @example
* breachedAccount('bar', { truncate: true })
* breachedAccount('bar', { includeUnverified: true })
* .then(data => {
* if (data) {
* // ...
Expand Down Expand Up @@ -55,6 +57,7 @@ const breachedAccount = (
account: string,
options: {
domain?: string;
includeUnverified?: boolean;
truncate?: boolean;
} = {},
): Promise<Breach[] | null> => {
Expand All @@ -63,6 +66,9 @@ const breachedAccount = (
if (options.domain) {
params.push(`domain=${encodeURIComponent(options.domain)}`);
}
if (options.includeUnverified) {
params.push('includeUnverified=true');
}
if (options.truncate) {
params.push('truncateResponse=true');
}
Expand Down
5 changes: 4 additions & 1 deletion types/hibp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export declare const breach: (breachName: string) => Promise<Breach | null>;
* @param {object} [options] a configuration object
* @param {string} [options.domain] a domain by which to filter the results
* (default: all domains)
* @param {boolean} [options.includeUnverified] include "unverified" breaches in
* the results (by default, only verified breaches are included)
* @param {boolean} [options.truncate] truncate the results to only include
* the name of each breach (default: false)
* @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an
Expand All @@ -89,7 +91,7 @@ export declare const breach: (breachName: string) => Promise<Breach | null>;
* // ...
* });
* @example
* breachedAccount('bar', { truncate: true })
* breachedAccount('bar', { includeUnverified: true })
* .then(data => {
* if (data) {
* // ...
Expand Down Expand Up @@ -118,6 +120,7 @@ export declare const breachedAccount: (
account: string,
options?: {
domain?: string | undefined;
includeUnverified?: boolean | undefined;
truncate?: boolean | undefined;
},
) => Promise<Breach[] | null>;
Expand Down

0 comments on commit be01ad1

Please sign in to comment.