Skip to content

Commit

Permalink
Don't use Object.values, fixes #681
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Aug 22, 2017
1 parent b3e45da commit c2ad3a1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
([#688](https://github.com/chriso/validator.js/issues/688))
- Allow comma in email display names
([#692](https://github.com/chriso/validator.js/pull/692))
- Add missing string to unescape
- Add missing string to `unescape()`
([#690](https://github.com/chriso/validator.js/pull/690))
- Fix `isMobilePhone()` with Node <= 6.x
([#681](https://github.com/chriso/validator.js/issues/681))
- New locales
([#692](https://github.com/chriso/validator.js/pull/692))

Expand Down
12 changes: 9 additions & 3 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ function isMobilePhone(str, locale) {
if (locale in phones) {
return phones[locale].test(str);
} else if (locale === 'any') {
return !!Object.values(phones).find(function (phone) {
return phone.test(str);
});
for (var key in phones) {
if (phones.hasOwnProperty(key)) {
var phone = phones[key];
if (phone.test(str)) {
return true;
}
}
}
return false;
}
throw new Error('Invalid locale \'' + locale + '\'');
}
Expand Down
10 changes: 9 additions & 1 deletion src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,15 @@ export default function isMobilePhone(str, locale) {
if (locale in phones) {
return phones[locale].test(str);
} else if (locale === 'any') {
return !!Object.values(phones).find(phone => phone.test(str));
for (const key in phones) {
if (phones.hasOwnProperty(key)) {
const phone = phones[key];
if (phone.test(str)) {
return true;
}
}
}
return false;
}
throw new Error(`Invalid locale '${locale}'`);
}
12 changes: 9 additions & 3 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,15 @@ function isMobilePhone(str, locale) {
if (locale in phones) {
return phones[locale].test(str);
} else if (locale === 'any') {
return !!Object.values(phones).find(function (phone) {
return phone.test(str);
});
for (var key in phones) {
if (phones.hasOwnProperty(key)) {
var phone = phones[key];
if (phone.test(str)) {
return true;
}
}
}
return false;
}
throw new Error('Invalid locale \'' + locale + '\'');
}
Expand Down
Loading

0 comments on commit c2ad3a1

Please sign in to comment.