Skip to content

Commit

Permalink
Merge pull request #858 from idrisakmal/master
Browse files Browse the repository at this point in the history
Created includes function for array to cater older browsers
  • Loading branch information
chriso authored Jun 27, 2018
2 parents 74ab5d7 + f630697 commit 641bd6e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/isDecimal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import merge from './util/merge';
import assertString from './util/assertString';
import includes from './util/includes';
import { decimal } from './alpha';

function decimalRegExp(options) {
Expand All @@ -19,7 +20,7 @@ export default function isDecimal(str, options) {
assertString(str);
options = merge(options, default_decimal_options);
if (options.locale in decimal) {
return !blacklist.includes(str.replace(/ /g, '')) && decimalRegExp(options).test(str);
return !includes(blacklist, str.replace(/ /g, '')) && decimalRegExp(options).test(str);
}
throw new Error(`Invalid locale '${options.locale}'`);
}
3 changes: 2 additions & 1 deletion src/lib/isISO31661Alpha2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assertString from './util/assertString';
import includes from './util/includes';

// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
const validISO31661Alpha2CountriesCodes = [
Expand Down Expand Up @@ -31,5 +32,5 @@ const validISO31661Alpha2CountriesCodes = [

export default function isISO31661Alpha2(str) {
assertString(str);
return validISO31661Alpha2CountriesCodes.includes(str.toUpperCase());
return includes(validISO31661Alpha2CountriesCodes, str.toUpperCase());
}
3 changes: 2 additions & 1 deletion src/lib/isISO31661Alpha3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assertString from './util/assertString';
import includes from './util/includes';

// from https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
const validISO31661Alpha3CountriesCodes = [
Expand All @@ -22,5 +23,5 @@ const validISO31661Alpha3CountriesCodes = [

export default function isISO31661Alpha3(str) {
assertString(str);
return validISO31661Alpha3CountriesCodes.includes(str.toUpperCase());
return includes(validISO31661Alpha3CountriesCodes, str.toUpperCase());
}
3 changes: 3 additions & 0 deletions src/lib/util/includes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const includes = (arr, val) => arr.some(arrVal => val === arrVal);

export default includes;

0 comments on commit 641bd6e

Please sign in to comment.