Support allowing specific phone types by kurayama · Pull Request #151 · uphold/validator.js-asserts

@kurayama

This PR adds the ability to specify the phones types allowed in the Phone assert.
With this we can, for example, only allow land line and mobile phones (avoid premium numbers).

ruimarinho

if (!isArray(allowedTypes) || intersection(allowedTypes, keys(PhoneNumberType)).length !== allowedTypes.length) {
throw new Error('Phone types specified are not valid.');
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why .map but not Array.isArray?

}
});

it('should accept a valid phone in the e164 format', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test where a number belonging to an allowed type is accepted.

* The allowed phone number types.
*/

if (allowedTypes) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.keys?