Support allowing specific phone types by kurayama · Pull Request #151 · uphold/validator.js-asserts
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).
| 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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters