Skip to content

Commit

Permalink
Added MobilePhone Options Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
oleersoy committed Mar 5, 2020
1 parent 93162e9 commit 82828bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion projects/validatorjs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@fireflysemantics/validatorts",
"description": "String validation and sanitization",
"version": "12.2.10",
"version": "12.2.11",
"homepage": "https://github.com/fireflysemantics/validatorts",
"scripts": {
"test": "jest",
Expand Down
18 changes: 17 additions & 1 deletion projects/validatorjs/src/lib/validators/isMobilePhone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,28 @@ phones['fr-BE'] = phones['nl-BE'];
phones['zh-HK'] = phones['en-HK'];
phones['zh-MO'] = phones['en-MO'];


/**
* Optional configuration
* If `strictMode` is set to true,
* the mobile phone number must be supplied
* with the country code and therefore must start with +.
* The supported localelist is exported via isMobilePhoneLocales.
*/
export interface IsMobilePhoneOptions {
strictMode:boolean
}

/**
* Checks whether the `target` string is a valid Mobile Phone Number
*
* @param target The target string
* @param locale The locale
* @param options The options
* @throws Error If the local passed in is not supported.
* @return true if the `target` is a valid Mobile Phone Number, false otherwise
*/
export function isMobilePhone(target:string, locale:string, options) {
export function isMobilePhone(target:string, locale:string, options?:IsMobilePhoneOptions) {
assertString(target);
if (options && options.strictMode && !target.startsWith('+')) {
return false;
Expand Down Expand Up @@ -141,4 +154,7 @@ export function isMobilePhone(target:string, locale:string, options) {
throw new Error(`Invalid locale '${locale}'`);
}

/**
* The supported locale list.
*/
export const isMobilePhoneLocales = Object.keys(phones);

0 comments on commit 82828bb

Please sign in to comment.