Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

agegate

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agegate - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

generator

14

CHANGELOG.md

@@ -0,3 +1,13 @@

# 1.0.0 (2015-04-27)
### Features
* Added the rest of the countries to the data file
### Bugs
* Re-written the method to serialize form data to be more secure
* Corrected the method for retrieval of input's checked value
* Renamed property `defaults` to `options`
* Indicated the base number on `parseInt()`
# 0.3.0 (2015-04-23)
### Additions
### Features
* Add `data` option to allow override of default country drinking age data

@@ -13,3 +23,3 @@ * JSDoc comments

# 0.2.0 (2015-04-20)
### Additions
### Features
* Build UMD modules, instead of purely CommonJS

@@ -16,0 +26,0 @@ * Test for saving cookies

341

dist/data.js
(function (global, factory) {
if (typeof define === 'function' && define.amd) {
define(['exports', 'module'], factory);
} else if (typeof exports !== 'undefined' && typeof module !== 'undefined') {
factory(exports, module);
define(['exports'], factory);
} else if (typeof exports !== 'undefined') {
factory(exports);
} else {

@@ -10,326 +10,25 @@ var mod = {

};
factory(mod.exports, mod);
factory(mod.exports);
global.data = mod.exports;
}
})(this, function (exports, module) {
// Africa =======================================================================
})(this, function (exports) {
'use strict';
var africa = [{
code: 'DZ',
name: 'Algeria',
age: 18
}, {
code: 'AO',
name: 'Angola',
age: 18
}, {
code: 'DZ',
name: 'Botswana',
age: 18
}, {
code: 'BI',
name: 'Burundi',
age: 18
}, {
code: 'CM',
name: 'Cameroon',
age: 21
}, {
code: 'CV',
name: 'Cape Verde',
age: 18
}, {
code: 'CF',
name: 'Central African Republic',
age: 18
}, {
code: 'KM',
name: 'Comoros',
age: 0
}, {
code: 'CD',
name: 'Democratic Republic of the Congo',
age: 18
}, {
code: 'EG',
name: 'Egypt',
age: 21
}, {
code: 'GQ',
name: 'Equatorial Guinea',
age: 0
}, {
code: 'ER',
name: 'Eritrea',
age: 18
}, {
code: 'ET',
name: 'Ethiopia',
age: 18
}, {
code: 'GA',
name: 'Gabon',
age: 18
}, {
code: 'GM',
name: 'Gambia',
age: 18
}, {
code: 'GH',
name: 'Ghana',
age: 18
}, {
code: 'GW',
name: 'Guinea-Bissau',
age: 0
}, {
code: 'KE',
name: 'Kenya',
age: 18
}, {
name: 'Lesotho',
age: 18
}, {
code: 'LY',
name: 'Libya',
age: Infinity
}, {
code: 'MW',
name: 'Malawi',
age: 18
}, {
code: 'MU',
name: 'Mauritius',
age: 18
}, {
code: 'MA',
name: 'Morocco',
age: 16
}, {
code: 'MZ',
name: 'Mozambique',
age: 18
}, {
code: 'NA',
name: 'Namibia',
age: 18
}, {
code: 'NE',
name: 'Niger',
age: 18
}, {
code: 'NG',
name: 'Nigeria',
age: 18
}, {
code: 'CG',
name: 'Republic of the Congo',
age: 18
}, {
code: 'RW',
name: 'Rwanda',
age: 18
}, {
code: 'SN',
name: 'Senegal',
age: 0
}, {
code: 'SC',
name: 'Seychelles',
age: 18
}, {
code: 'SO',
name: 'Somalia',
age: Infinity
}, {
code: 'ZA',
name: 'South Africa',
age: 18
}, {
code: 'SS',
name: 'South Sudan',
age: 18
}, {
code: 'SD',
name: 'Sudan',
age: Infinity
}, {
code: 'SZ',
name: 'Swaziland',
age: 18
}, {
code: 'TZ',
name: 'Tanzania',
age: 18
}, {
code: 'TG',
name: 'Togo',
age: 18
}, {
code: 'TN',
name: 'Tunisia',
age: 18
}, {
code: 'UG',
name: 'Uganda',
age: 18
}, {
code: 'ZM',
name: 'Zambia',
age: 18
}, {
code: 'ZW',
name: 'Zimbabwe',
age: 18
}];
Object.defineProperty(exports, '__esModule', {
value: true
});
var Africa = [{ code: 'DZ', name: 'Algeria', age: 18 }, { code: 'AO', name: 'Angola', age: 18 }, { code: 'DZ', name: 'Botswana', age: 18 }, { code: 'BI', name: 'Burundi', age: 18 }, { code: 'CM', name: 'Cameroon', age: 21 }, { code: 'CV', name: 'Cape Verde', age: 18 }, { code: 'CF', name: 'Central African Republic', age: 18 }, { code: 'KM', name: 'Comoros', age: 0 }, { code: 'CD', name: 'Democratic Republic of the Congo', age: 18 }, { code: 'EG', name: 'Egypt', age: 21 }, { code: 'GQ', name: 'Equatorial Guinea', age: 0 }, { code: 'ER', name: 'Eritrea', age: 18 }, { code: 'ET', name: 'Ethiopia', age: 18 }, { code: 'GA', name: 'Gabon', age: 18 }, { code: 'GM', name: 'Gambia', age: 18 }, { code: 'GH', name: 'Ghana', age: 18 }, { code: 'GW', name: 'Guinea-Bissau', age: 0 }, { code: 'KE', name: 'Kenya', age: 18 }, { code: 'LS', name: 'Lesotho', age: 18 }, { code: 'LY', name: 'Libya', age: Infinity }, { code: 'MW', name: 'Malawi', age: 18 }, { code: 'MU', name: 'Mauritius', age: 18 }, { code: 'MA', name: 'Morocco', age: 16 }, { code: 'MZ', name: 'Mozambique', age: 18 }, { code: 'NA', name: 'Namibia', age: 18 }, { code: 'NE', name: 'Niger', age: 18 }, { code: 'NG', name: 'Nigeria', age: 18 }, { code: 'CG', name: 'Republic of the Congo', age: 18 }, { code: 'RW', name: 'Rwanda', age: 18 }, { code: 'SN', name: 'Senegal', age: 0 }, { code: 'SC', name: 'Seychelles', age: 18 }, { code: 'SO', name: 'Somalia', age: Infinity }, { code: 'ZA', name: 'South Africa', age: 18 }, { code: 'SS', name: 'South Sudan', age: 18 }, { code: 'SD', name: 'Sudan', age: Infinity }, { code: 'SZ', name: 'Swaziland', age: 18 }, { code: 'TZ', name: 'Tanzania', age: 18 }, { code: 'TG', name: 'Togo', age: 18 }, { code: 'TN', name: 'Tunisia', age: 18 }, { code: 'UG', name: 'Uganda', age: 18 }, { code: 'ZM', name: 'Zambia', age: 18 }, { code: 'ZW', name: 'Zimbabwe', age: 18 }];
// America ======================================================================
var america = [{
code: 'AG',
name: 'Antigua and Barbuda',
age: 16
}, {
code: 'AR',
name: 'Argentina',
age: 18
}, {
code: 'BS',
name: 'Bahamas',
age: 18
}, {
code: 'BZ',
name: 'Belize',
age: 18
}, {
code: 'BM',
name: 'Bermuda',
age: 18
}, {
code: 'BO',
name: 'Bolivia',
age: 18
}, {
code: 'BR',
name: 'Brazil',
age: 18
}, {
code: 'VG',
name: 'British Virgin Islands',
age: 16
}, {
code: 'CA',
name: 'Canada',
age: 19
}, {
code: 'CA-2',
name: 'Canada (AB, MB, QC)',
age: 18
}, {
code: 'KY',
name: 'Cayman Islands',
age: 18
}, {
code: 'CL',
name: 'Chile',
age: 18
}, {
code: 'CO',
name: 'Colombia',
age: 18
}, {
code: 'CR',
name: 'Costa Rica',
age: 18
}, {
code: 'CU',
name: 'Cuba',
age: 18
}, {
code: 'DO',
name: 'Dominican Republic',
age: 18
}, {
code: 'EC',
name: 'Ecuador',
age: 18
}, {
code: 'SV',
name: 'El Salvador',
age: 18
}, {
code: 'FK',
name: 'Falkland Islands',
age: 18
}, {
code: 'GT',
name: 'Guatemala',
age: 18
}, {
code: 'GY',
name: 'Guyana',
age: 18
}, {
code: 'HT',
name: 'Haiti',
age: 16
}, {
code: 'HN',
name: 'Honduras',
age: 18
}, {
code: 'JM',
name: 'Jamaica',
age: 16
}, {
code: 'MX',
name: 'Mexico',
age: 18
}, {
code: 'NI',
name: 'Nicaragua',
age: 18
}, {
code: 'PA',
name: 'Panama',
age: 18
}, {
code: 'PY',
name: 'Paraguay',
age: 20
}, {
code: 'PE',
name: 'Peru',
age: 18
}, {
code: 'PR',
name: 'Puerto Rico',
age: 18
}, {
code: 'TT',
name: 'Trinidad and Tobago',
age: 18
}, {
code: 'US',
name: 'United States',
age: 21
}, {
code: 'VI',
name: 'United States Virgin Islands',
age: 18
}, {
code: 'UY',
name: 'Uruguay',
age: 18
}, {
code: 'VE',
name: 'Venezuela',
age: 18
}];
exports.Africa = Africa;
var America = [{ code: 'AG', name: 'Antigua and Barbuda', age: 16 }, { code: 'AR', name: 'Argentina', age: 18 }, { code: 'BS', name: 'Bahamas', age: 18 }, { code: 'BZ', name: 'Belize', age: 18 }, { code: 'BM', name: 'Bermuda', age: 18 }, { code: 'BO', name: 'Bolivia', age: 18 }, { code: 'BR', name: 'Brazil', age: 18 }, { code: 'VG', name: 'British Virgin Islands', age: 16 }, { code: 'CA', name: 'Canada', age: 19 }, { code: 'KY', name: 'Cayman Islands', age: 18 }, { code: 'CL', name: 'Chile', age: 18 }, { code: 'CO', name: 'Colombia', age: 18 }, { code: 'CR', name: 'Costa Rica', age: 18 }, { code: 'CU', name: 'Cuba', age: 18 }, { code: 'DO', name: 'Dominican Republic', age: 18 }, { code: 'EC', name: 'Ecuador', age: 18 }, { code: 'SV', name: 'El Salvador', age: 18 }, { code: 'FK', name: 'Falkland Islands', age: 18 }, { code: 'GT', name: 'Guatemala', age: 18 }, { code: 'GY', name: 'Guyana', age: 18 }, { code: 'HT', name: 'Haiti', age: 16 }, { code: 'HN', name: 'Honduras', age: 18 }, { code: 'JM', name: 'Jamaica', age: 16 }, { code: 'MX', name: 'Mexico', age: 18 }, { code: 'NI', name: 'Nicaragua', age: 18 }, { code: 'PA', name: 'Panama', age: 18 }, { code: 'PY', name: 'Paraguay', age: 20 }, { code: 'PE', name: 'Peru', age: 18 }, { code: 'PR', name: 'Puerto Rico', age: 18 }, { code: 'TT', name: 'Trinidad and Tobago', age: 18 }, { code: 'US', name: 'United States', age: 21 }, { code: 'VI', name: 'United States Virgin Islands', age: 18 }, { code: 'UY', name: 'Uruguay', age: 18 }, { code: 'VE', name: 'Venezuela', age: 18 }];
module.exports = {
Africa: africa,
America: america
// TODO the rest of the continents
};
exports.America = America;
var Asia = [{ code: 'AF', name: 'Afghanistan', age: Infinity }, { code: 'BD', name: 'Bangladesh', age: Infinity }, { code: 'BN', name: 'Brunei', age: Infinity }, { code: 'KH', name: 'Cambodia', age: 0 }, { code: 'CN', name: 'China', age: 18 }, { code: 'HK', name: 'Hong Kong', age: 18 }, { code: 'IN', name: 'India', age: 18 }, { code: 'ID', name: 'Indonesia', age: 21 }, { code: 'IR', name: 'Iran', age: 18 }, { code: 'JQ', name: 'Iraq', age: 18 }, { code: 'IL', name: 'Israel', age: 18 }, { code: 'JP', name: 'Japan', age: 20 }, { code: 'JO', name: 'Jordan', age: 18 }, { code: 'KZ', name: 'Kazakhstan', age: 21 }, { code: 'KW', name: 'Kuwait', age: Infinity }, { code: 'KG', name: 'Kyrgyzstan', age: 18 }, { code: 'LB', name: 'Lebanon', age: 18 }, { code: 'MO', name: 'Macau', age: 18 }, { code: 'MY', name: 'Malaysia', age: 18 }, { code: 'MV', name: 'Maldives', age: 18 }, { code: 'MN', name: 'Mongolia', age: 18 }, { code: 'NP', name: 'Nepal', age: 18 }, { code: 'KP', name: 'North Korea', age: 18 }, { code: 'OM', name: 'Oman', age: 21 }, { code: 'PK', name: 'Pakistan', age: 21 }, { code: 'PS', name: 'Palestine', age: 16 }, { code: 'PH', name: 'Philippines', age: 18 }, { code: 'QA', name: 'Qatar', age: 21 }, { code: 'SA', name: 'Saudi Arabia', age: Infinity }, { code: 'SG', name: 'Singapore', age: 18 }, { code: 'KR', name: 'South Korea', age: 19 }, { code: 'LK', name: 'Sri Lanka', age: 21 }, { code: 'SY', name: 'Syria', age: 18 }, { code: 'TW', name: 'Taiwan', age: 18 }, { code: 'TJ', name: 'Tajikistan', age: 21 }, { code: 'TH', name: 'Thailand', age: 21 }, { code: 'TM', name: 'Turkmenistan', age: 18 }, { code: 'AE', name: 'United Arab Emirates', age: 21 }, { code: 'VN', name: 'Vietnam', age: 0 }, { code: 'YE', name: 'Yemen', age: Infinity }];
exports.Asia = Asia;
var Europe = [{ code: 'AL', name: 'Albania', age: 18 }, { code: 'AM', name: 'Armenia', age: 18 }, { code: 'AT', name: 'Austria', age: 18 }, { code: 'AZ', name: 'Azerbaijan', age: 18 }, { code: 'BY', name: 'Belarus', age: 18 }, { code: 'BE', name: 'Belgium', age: 18 }, { code: 'BA', name: 'Bosnia and Herzegovina', age: 18 }, { code: 'BG', name: 'Bulgaria', age: 18 }, { code: 'HR', name: 'Croatia', age: 18 }, { code: 'CY', name: 'Cyprus', age: 17 }, { code: 'CZ', name: 'Czech Republic', age: 18 }, { code: 'DK', name: 'Denmark', age: 18 }, { code: 'EE', name: 'Estonia', age: 18 }, { code: 'FI', name: 'Finland', age: 18 }, { code: 'FR', name: 'France', age: 18 }, { code: 'GE', name: 'Georgia', age: 16 }, { code: 'DE', name: 'Germany', age: 18 }, { code: 'GI', name: 'Gibraltar', age: 18 }, { code: 'GR', name: 'Greece', age: 18 }, { code: 'HU', name: 'Hungary', age: 18 }, { code: 'IS', name: 'Iceland', age: 20 }, { code: 'IE', name: 'Ireland', age: 18 }, { code: 'IT', name: 'Italy', age: 18 }, { code: 'XK', name: 'Kosovo', age: 18 }, { code: 'LV', name: 'Latvia', age: 18 }, { code: 'LI', name: 'Liechtenstein', age: 18 }, { code: 'LT', name: 'Lithuania', age: 18 }, { code: 'LU', name: 'Luxembourg', age: 16 }, { code: 'MK', name: 'Macedonia', age: 18 }, { code: 'MT', name: 'Malta', age: 17 }, { code: 'MD', name: 'Moldova', age: 16 }, { code: 'ME', name: 'Montenegro', age: 18 }, { code: 'NL', name: 'Netherlands', age: 18 }, { code: 'NO', name: 'Norway', age: 20 }, { code: 'PL', name: 'Poland', age: 18 }, { code: 'PT', name: 'Portugal', age: 18 }, { code: 'RO', name: 'Romania', age: 18 }, { code: 'RU', name: 'Russia', age: 18 }, { code: 'RS', name: 'Serbia', age: 18 }, { code: 'SK', name: 'Slovakia', age: 18 }, { code: 'SI', name: 'Slovenia', age: 18 }, { code: 'ES', name: 'Spain', age: 18 }, { code: 'SE', name: 'Sweden', age: 18 }, { code: 'CH', name: 'Switzerland', age: 18 }, { code: 'TR', name: 'Turkey', age: 18 }, { code: 'UA', name: 'Ukraine', age: 18 }, { code: 'GB', name: 'United Kingdom', age: 18 }];
exports.Europe = Europe;
var Oceania = [{ code: 'AS', name: 'American Samoa', age: 21 }, { code: 'AU', name: 'Australia', age: 18 }, { code: 'FJ', name: 'Fiji', age: 18 }, { code: 'GU', name: 'Guam', age: 21 }, { code: 'FM', name: 'Federated States of Micronesia', age: 21 }, { code: 'NZ', name: 'New Zealand', age: 18 }, { code: 'MP', name: 'Northern Mariana Islands', age: 21 }, { code: 'PW', name: 'Palau', age: 21 }, { code: 'PG', name: 'Papua New Guinea', age: 18 }, { code: 'WS', name: 'Samoa', age: 18 }, { code: 'SB', name: 'Solomon Islands', age: 21 }, { code: 'TK', name: 'Tokelau', age: 18 }, { code: 'TO', name: 'Tonga', age: 21 }, { code: 'VU', name: 'Vanuatu', age: 18 }];
exports.Oceania = Oceania;
});

@@ -22,6 +22,6 @@ (function (global, factory) {

var _data2 = _interopRequire(_data);
var _cookies2 = _interopRequire(_cookies);
var FORM_ELEMENTS = ['year', 'month', 'day', 'country', 'remember'];
var AgeGate = (function () {

@@ -31,11 +31,9 @@ function AgeGate(opts, cb) {

// set defaults
this.defaults = opts;
this.options = opts;
this.callback = cb;
this.isEnabled.data && this.validateData(opts.data);
this.isEnabled.data && this.validateData(opts.data); // validate data
// render
this.isEnabled.countries && this.populate();
this.defaults.form.addEventListener('submit', this.submit.bind(this));
this.options.form.addEventListener('submit', this.submit.bind(this));
}

@@ -51,5 +49,5 @@

return {
age: !!this.defaults.age,
countries: !!this.defaults.countries,
data: !!this.defaults.data
age: !!this.options.age,
countries: !!this.options.countries,
data: !!this.options.data
};

@@ -60,3 +58,3 @@ }

get: function () {
return parseInt(this.defaults.age) || 18;
return parseInt(this.options.age, 10) || 18;
}

@@ -66,3 +64,3 @@ }, {

get: function () {
return this.defaults.data || _data2;
return this.options.data || _data;
}

@@ -78,3 +76,3 @@ }, {

if (this.defaults.data) {
if (this.options.data) {
ages = this.data.reduce(function (total, item) {

@@ -122,14 +120,12 @@ total[item.code] = item.age;

value: function populate() {
var _this = this;
var select = this.defaults.form.querySelector('select');
var select = this.options.form.querySelector('select');
select.innerHTML = ''; // assume it's not empty
// attempt to use user-supplied data
if (this.isEnabled.data) Object.keys(this.data).forEach(function (i) {
return select.appendChild(createOption(_this.data[i]));
if (this.isEnabled.data) this.data.forEach(function (country) {
return select.appendChild(createOption(country));
});
// fallback to default data (continent-separated)
else Object.keys(_data2).forEach(function (continent) {
else Object.keys(_data).forEach(function (continent) {
var group = document.createElement('optgroup');

@@ -139,4 +135,4 @@ group.label = continent;

// create the <option> for each country
for (var i = 0; i < _data2[continent].length; i++) {
var country = _data2[continent][i];
for (var i = 0; i < _data[continent].length; i++) {
var country = _data[continent][i];
group.appendChild(createOption(country));

@@ -173,18 +169,20 @@ }

// serialize form data
this.formData = {};
var form = e.srcElement,
elems = form.elements;
var elements = e.srcElement.elements;
for (var i = 0; i < elems.length; i++) {
switch (elems[i].tagName) {
case 'INPUT':
case 'SELECT':
this.formData[elems[i].name] = elems[i].value;
// create an object from the form data
this.formData = FORM_ELEMENTS.reduce(function (collection, key) {
if (!elements[key]) return collection;
switch (key) {
case 'remember':
collection[key] = elements[key].checked;
break;
default:
collection[key] = elements[key].value;
break;
}
}
return collection;
}, {});
this.respond(this.verify(this.formData));

@@ -206,7 +204,7 @@ }

legalAge = this.ages[formData.country] || this.legalAge;
var date = [parseInt(formData.year), parseInt(formData.month) || 1, parseInt(formData.day) || 1].join('/');
var age = ~ ~((new Date().getTime() - +new Date(date)) / 31557600000);
var bday = [parseInt(formData.year, 10), parseInt(formData.month, 10) || 1, parseInt(formData.day, 10) || 1].join('/');
var age = ~ ~((new Date().getTime() - +new Date(bday)) / 31557600000);
// set cookie if desired
if (!!formData.remember && formData.remember === 'on') this.saveCookie(this.defaults.expiry);else this.saveCookie();
if (!!formData.remember) this.saveCookie(this.options.expiry);else this.saveCookie();

@@ -213,0 +211,0 @@ if (age >= legalAge) ok = true;

{
"name": "agegate",
"version": "0.3.0",
"version": "1.0.0",
"description": "Limit access to your app with an age gate",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,322 +0,191 @@

// Africa =======================================================================
let africa = [
{
code: 'DZ',
name: 'Algeria',
age: 18
},{
code: 'AO',
name: 'Angola',
age: 18
},{
code: 'DZ',
name: 'Botswana',
age: 18
},{
code: 'BI',
name: 'Burundi',
age: 18
},{
code: 'CM',
name: 'Cameroon',
age: 21
},{
code: 'CV',
name: 'Cape Verde',
age: 18
},{
code: 'CF',
name: 'Central African Republic',
age: 18
},{
code: 'KM',
name: 'Comoros',
age: 0
},{
code: 'CD',
name: 'Democratic Republic of the Congo',
age: 18
},{
code: 'EG',
name: 'Egypt',
age: 21
},{
code: 'GQ',
name: 'Equatorial Guinea',
age: 0
},{
code: 'ER',
name: 'Eritrea',
age: 18
},{
code: 'ET',
name: 'Ethiopia',
age: 18
},{
code: 'GA',
name: 'Gabon',
age: 18
},{
code: 'GM',
name: 'Gambia',
age: 18
},{
code: 'GH',
name: 'Ghana',
age: 18
},{
code: 'GW',
name: 'Guinea-Bissau',
age: 0
},{
code: 'KE',
name: 'Kenya',
age: 18
}, {
name: 'Lesotho',
age: 18
}, {
code: 'LY',
name: 'Libya',
age: Infinity
}, {
code: 'MW',
name: 'Malawi',
age: 18
}, {
code: 'MU',
name: 'Mauritius',
age: 18
}, {
code: 'MA',
name: 'Morocco',
age: 16
}, {
code: 'MZ',
name: 'Mozambique',
age: 18
}, {
code: 'NA',
name: 'Namibia',
age: 18
}, {
code: 'NE',
name: 'Niger',
age: 18
}, {
code: 'NG',
name: 'Nigeria',
age: 18
}, {
code: 'CG',
name: 'Republic of the Congo',
age: 18
}, {
code: 'RW',
name: 'Rwanda',
age: 18
}, {
code: 'SN',
name: 'Senegal',
age: 0
}, {
code: 'SC',
name: 'Seychelles',
age: 18
}, {
code: 'SO',
name: 'Somalia',
age: Infinity
}, {
code: 'ZA',
name: 'South Africa',
age: 18
}, {
code: 'SS',
name: 'South Sudan',
age: 18
}, {
code: 'SD',
name: 'Sudan',
age: Infinity
}, {
code: 'SZ',
name: 'Swaziland',
age: 18
}, {
code: 'TZ',
name: 'Tanzania',
age: 18
}, {
code: 'TG',
name: 'Togo',
age: 18
}, {
code: 'TN',
name: 'Tunisia',
age: 18
}, {
code: 'UG',
name: 'Uganda',
age: 18
}, {
code: 'ZM',
name: 'Zambia',
age: 18
}, {
code: 'ZW',
name: 'Zimbabwe',
age: 18
}
export var Africa = [
{ code: 'DZ', name: 'Algeria', age: 18 },
{ code: 'AO', name: 'Angola', age: 18 },
{ code: 'DZ', name: 'Botswana', age: 18 },
{ code: 'BI', name: 'Burundi', age: 18 },
{ code: 'CM', name: 'Cameroon', age: 21 },
{ code: 'CV', name: 'Cape Verde', age: 18 },
{ code: 'CF', name: 'Central African Republic', age: 18 },
{ code: 'KM', name: 'Comoros', age: 0 },
{ code: 'CD', name: 'Democratic Republic of the Congo', age: 18 },
{ code: 'EG', name: 'Egypt', age: 21 },
{ code: 'GQ', name: 'Equatorial Guinea', age: 0 },
{ code: 'ER', name: 'Eritrea', age: 18 },
{ code: 'ET', name: 'Ethiopia', age: 18 },
{ code: 'GA', name: 'Gabon', age: 18 },
{ code: 'GM', name: 'Gambia', age: 18 },
{ code: 'GH', name: 'Ghana', age: 18 },
{ code: 'GW', name: 'Guinea-Bissau', age: 0 },
{ code: 'KE', name: 'Kenya', age: 18 },
{ code: 'LS', name: 'Lesotho', age: 18 },
{ code: 'LY', name: 'Libya', age: Infinity },
{ code: 'MW', name: 'Malawi', age: 18 },
{ code: 'MU', name: 'Mauritius', age: 18 },
{ code: 'MA', name: 'Morocco', age: 16 },
{ code: 'MZ', name: 'Mozambique', age: 18 },
{ code: 'NA', name: 'Namibia', age: 18 },
{ code: 'NE', name: 'Niger', age: 18 },
{ code: 'NG', name: 'Nigeria', age: 18 },
{ code: 'CG', name: 'Republic of the Congo', age: 18 },
{ code: 'RW', name: 'Rwanda', age: 18 },
{ code: 'SN', name: 'Senegal', age: 0 },
{ code: 'SC', name: 'Seychelles', age: 18 },
{ code: 'SO', name: 'Somalia', age: Infinity },
{ code: 'ZA', name: 'South Africa', age: 18 },
{ code: 'SS', name: 'South Sudan', age: 18 },
{ code: 'SD', name: 'Sudan', age: Infinity },
{ code: 'SZ', name: 'Swaziland', age: 18 },
{ code: 'TZ', name: 'Tanzania', age: 18 },
{ code: 'TG', name: 'Togo', age: 18 },
{ code: 'TN', name: 'Tunisia', age: 18 },
{ code: 'UG', name: 'Uganda', age: 18 },
{ code: 'ZM', name: 'Zambia', age: 18 },
{ code: 'ZW', name: 'Zimbabwe', age: 18 }
];
// America ======================================================================
let america = [
{
code: 'AG',
name: 'Antigua and Barbuda',
age: 16
},{
code: 'AR',
name: 'Argentina',
age: 18
},{
code: 'BS',
name: 'Bahamas',
age: 18
},{
code: 'BZ',
name: 'Belize',
age: 18
},{
code: 'BM',
name: 'Bermuda',
age: 18
},{
code: 'BO',
name: 'Bolivia',
age: 18
},{
code: 'BR',
name: 'Brazil',
age: 18
},{
code: 'VG',
name: 'British Virgin Islands',
age: 16
},{
code: 'CA',
name: 'Canada',
age: 19
},{
code: 'CA-2',
name: 'Canada (AB, MB, QC)',
age: 18
},{
code: 'KY',
name: 'Cayman Islands',
age: 18
},{
code: 'CL',
name: 'Chile',
age: 18
},{
code: 'CO',
name: 'Colombia',
age: 18
},{
code: 'CR',
name: 'Costa Rica',
age: 18
},{
code: 'CU',
name: 'Cuba',
age: 18
},{
code: 'DO',
name: 'Dominican Republic',
age: 18
},{
code: 'EC',
name: 'Ecuador',
age: 18
},{
code: 'SV',
name: 'El Salvador',
age: 18
},{
code: 'FK',
name: 'Falkland Islands',
age: 18
},{
code: 'GT',
name: 'Guatemala',
age: 18
},{
code: 'GY',
name: 'Guyana',
age: 18
},{
code: 'HT',
name: 'Haiti',
age: 16
},{
code: 'HN',
name: 'Honduras',
age: 18
},{
code: 'JM',
name: 'Jamaica',
age: 16
},{
code: 'MX',
name: 'Mexico',
age: 18
},{
code: 'NI',
name: 'Nicaragua',
age: 18
},{
code: 'PA',
name: 'Panama',
age: 18
},{
code: 'PY',
name: 'Paraguay',
age: 20
},{
code: 'PE',
name: 'Peru',
age: 18
},{
code: 'PR',
name: 'Puerto Rico',
age: 18
},{
code: 'TT',
name: 'Trinidad and Tobago',
age: 18
},{
code: 'US',
name: 'United States',
age: 21
},{
code: 'VI',
name: 'United States Virgin Islands',
age: 18
},{
code: 'UY',
name: 'Uruguay',
age: 18
},{
code: 'VE',
name: 'Venezuela',
age: 18
}
export var America = [
{ code: 'AG', name: 'Antigua and Barbuda', age: 16 },
{ code: 'AR', name: 'Argentina', age: 18 },
{ code: 'BS', name: 'Bahamas', age: 18 },
{ code: 'BZ', name: 'Belize', age: 18 },
{ code: 'BM', name: 'Bermuda', age: 18 },
{ code: 'BO', name: 'Bolivia', age: 18 },
{ code: 'BR', name: 'Brazil', age: 18 },
{ code: 'VG', name: 'British Virgin Islands', age: 16 },
{ code: 'CA', name: 'Canada', age: 19 },
{ code: 'KY', name: 'Cayman Islands', age: 18 },
{ code: 'CL', name: 'Chile', age: 18 },
{ code: 'CO', name: 'Colombia', age: 18 },
{ code: 'CR', name: 'Costa Rica', age: 18 },
{ code: 'CU', name: 'Cuba', age: 18 },
{ code: 'DO', name: 'Dominican Republic', age: 18 },
{ code: 'EC', name: 'Ecuador', age: 18 },
{ code: 'SV', name: 'El Salvador', age: 18 },
{ code: 'FK', name: 'Falkland Islands', age: 18 },
{ code: 'GT', name: 'Guatemala', age: 18 },
{ code: 'GY', name: 'Guyana', age: 18 },
{ code: 'HT', name: 'Haiti', age: 16 },
{ code: 'HN', name: 'Honduras', age: 18 },
{ code: 'JM', name: 'Jamaica', age: 16 },
{ code: 'MX', name: 'Mexico', age: 18 },
{ code: 'NI', name: 'Nicaragua', age: 18 },
{ code: 'PA', name: 'Panama', age: 18 },
{ code: 'PY', name: 'Paraguay', age: 20 },
{ code: 'PE', name: 'Peru', age: 18 },
{ code: 'PR', name: 'Puerto Rico', age: 18 },
{ code: 'TT', name: 'Trinidad and Tobago', age: 18 },
{ code: 'US', name: 'United States', age: 21 },
{ code: 'VI', name: 'United States Virgin Islands', age: 18 },
{ code: 'UY', name: 'Uruguay', age: 18 },
{ code: 'VE', name: 'Venezuela', age: 18 }
];
export default {
Africa: africa,
America: america
// TODO the rest of the continents
};
export var Asia = [
{ code: 'AF', name: 'Afghanistan', age: Infinity },
{ code: 'BD', name: 'Bangladesh', age: Infinity },
{ code: 'BN', name: 'Brunei', age: Infinity },
{ code: 'KH', name: 'Cambodia', age: 0 },
{ code: 'CN', name: 'China', age: 18 },
{ code: 'HK', name: 'Hong Kong', age: 18 },
{ code: 'IN', name: 'India', age: 18 },
{ code: 'ID', name: 'Indonesia', age: 21 },
{ code: 'IR', name: 'Iran', age: 18 },
{ code: 'JQ', name: 'Iraq', age: 18 },
{ code: 'IL', name: 'Israel', age: 18 },
{ code: 'JP', name: 'Japan', age: 20 },
{ code: 'JO', name: 'Jordan', age: 18 },
{ code: 'KZ', name: 'Kazakhstan', age: 21 },
{ code: 'KW', name: 'Kuwait', age: Infinity },
{ code: 'KG', name: 'Kyrgyzstan', age: 18 },
{ code: 'LB', name: 'Lebanon', age: 18 },
{ code: 'MO', name: 'Macau', age: 18 },
{ code: 'MY', name: 'Malaysia', age: 18 },
{ code: 'MV', name: 'Maldives', age: 18 },
{ code: 'MN', name: 'Mongolia', age: 18 },
{ code: 'NP', name: 'Nepal', age: 18 },
{ code: 'KP', name: 'North Korea', age: 18 },
{ code: 'OM', name: 'Oman', age: 21 },
{ code: 'PK', name: 'Pakistan', age: 21 },
{ code: 'PS', name: 'Palestine', age: 16 },
{ code: 'PH', name: 'Philippines', age: 18 },
{ code: 'QA', name: 'Qatar', age: 21 },
{ code: 'SA', name: 'Saudi Arabia', age: Infinity },
{ code: 'SG', name: 'Singapore', age: 18 },
{ code: 'KR', name: 'South Korea', age: 19 },
{ code: 'LK', name: 'Sri Lanka', age: 21 },
{ code: 'SY', name: 'Syria', age: 18 },
{ code: 'TW', name: 'Taiwan', age: 18 },
{ code: 'TJ', name: 'Tajikistan', age: 21 },
{ code: 'TH', name: 'Thailand', age: 21 },
{ code: 'TM', name: 'Turkmenistan', age: 18 },
{ code: 'AE', name: 'United Arab Emirates', age: 21 },
{ code: 'VN', name: 'Vietnam', age: 0 },
{ code: 'YE', name: 'Yemen', age: Infinity }
];
export var Europe = [
{ code: 'AL', name: 'Albania', age: 18 },
{ code: 'AM', name: 'Armenia', age: 18 },
{ code: 'AT', name: 'Austria', age: 18 },
{ code: 'AZ', name: 'Azerbaijan', age: 18 },
{ code: 'BY', name: 'Belarus', age: 18 },
{ code: 'BE', name: 'Belgium', age: 18 },
{ code: 'BA', name: 'Bosnia and Herzegovina', age: 18 },
{ code: 'BG', name: 'Bulgaria', age: 18 },
{ code: 'HR', name: 'Croatia', age: 18 },
{ code: 'CY', name: 'Cyprus', age: 17 },
{ code: 'CZ', name: 'Czech Republic', age: 18 },
{ code: 'DK', name: 'Denmark', age: 18 },
{ code: 'EE', name: 'Estonia', age: 18 },
{ code: 'FI', name: 'Finland', age: 18 },
{ code: 'FR', name: 'France', age: 18 },
{ code: 'GE', name: 'Georgia', age: 16 },
{ code: 'DE', name: 'Germany', age: 18 },
{ code: 'GI', name: 'Gibraltar', age: 18 },
{ code: 'GR', name: 'Greece', age: 18 },
{ code: 'HU', name: 'Hungary', age: 18 },
{ code: 'IS', name: 'Iceland', age: 20 },
{ code: 'IE', name: 'Ireland', age: 18 },
{ code: 'IT', name: 'Italy', age: 18 },
{ code: 'XK', name: 'Kosovo', age: 18 },
{ code: 'LV', name: 'Latvia', age: 18 },
{ code: 'LI', name: 'Liechtenstein', age: 18 },
{ code: 'LT', name: 'Lithuania', age: 18 },
{ code: 'LU', name: 'Luxembourg', age: 16 },
{ code: 'MK', name: 'Macedonia', age: 18 },
{ code: 'MT', name: 'Malta', age: 17 },
{ code: 'MD', name: 'Moldova', age: 16 },
{ code: 'ME', name: 'Montenegro', age: 18 },
{ code: 'NL', name: 'Netherlands', age: 18 },
{ code: 'NO', name: 'Norway', age: 20 },
{ code: 'PL', name: 'Poland', age: 18 },
{ code: 'PT', name: 'Portugal', age: 18 },
{ code: 'RO', name: 'Romania', age: 18 },
{ code: 'RU', name: 'Russia', age: 18 },
{ code: 'RS', name: 'Serbia', age: 18 },
{ code: 'SK', name: 'Slovakia', age: 18 },
{ code: 'SI', name: 'Slovenia', age: 18 },
{ code: 'ES', name: 'Spain', age: 18 },
{ code: 'SE', name: 'Sweden', age: 18 },
{ code: 'CH', name: 'Switzerland', age: 18 },
{ code: 'TR', name: 'Turkey', age: 18 },
{ code: 'UA', name: 'Ukraine', age: 18 },
{ code: 'GB', name: 'United Kingdom', age: 18 }
];
export var Oceania = [
{ code: 'AS', name: 'American Samoa', age: 21 },
{ code: 'AU', name: 'Australia', age: 18 },
{ code: 'FJ', name: 'Fiji', age: 18 },
{ code: 'GU', name: 'Guam', age: 21 },
{ code: 'FM', name: 'Federated States of Micronesia', age: 21 },
{ code: 'NZ', name: 'New Zealand', age: 18 },
{ code: 'MP', name: 'Northern Mariana Islands', age: 21 },
{ code: 'PW', name: 'Palau', age: 21 },
{ code: 'PG', name: 'Papua New Guinea', age: 18 },
{ code: 'WS', name: 'Samoa', age: 18 },
{ code: 'SB', name: 'Solomon Islands', age: 21 },
{ code: 'TK', name: 'Tokelau', age: 18 },
{ code: 'TO', name: 'Tonga', age: 21 },
{ code: 'VU', name: 'Vanuatu', age: 18 }
];

@@ -1,15 +0,15 @@

import data from './data';
import * as data from './data';
import cookies from './cookies';
const FORM_ELEMENTS = ['year', 'month', 'day', 'country', 'remember'];
export default class AgeGate {
constructor(opts, cb) {
// set defaults
this.defaults = opts;
this.options = opts;
this.callback = cb;
this.isEnabled.data && this.validateData(opts.data);
this.isEnabled.data && this.validateData(opts.data); // validate data
// render
this.isEnabled.countries && this.populate();
this.defaults.form.addEventListener('submit', this.submit.bind(this));
this.options.form.addEventListener('submit', this.submit.bind(this));
}

@@ -22,5 +22,5 @@

return {
age: !!this.defaults.age,
countries: !!this.defaults.countries,
data: !!this.defaults.data
age: !!this.options.age,
countries: !!this.options.countries,
data: !!this.options.data
};

@@ -30,7 +30,7 @@ }

get legalAge() {
return parseInt(this.defaults.age) || 18;
return parseInt(this.options.age, 10) || 18;
}
get data() {
return this.defaults.data || data;
return this.options.data || data;
}

@@ -44,3 +44,3 @@

if (this.defaults.data) {
if (this.options.data) {
ages = this.data.reduce((total, item) => {

@@ -82,3 +82,3 @@ total[item.code] = item.age;

populate() {
let select = this.defaults.form.querySelector('select');
let select = this.options.form.querySelector('select');
select.innerHTML = ''; // assume it's not empty

@@ -88,3 +88,3 @@

if (this.isEnabled.data)
Object.keys(this.data).forEach(i => select.appendChild( createOption(this.data[i]) ));
this.data.forEach(country => select.appendChild( createOption(country) ));

@@ -129,17 +129,20 @@ // fallback to default data (continent-separated)

// serialize form data
this.formData = {};
let form = e.srcElement, elems = form.elements;
let elements = e.srcElement.elements;
for (let i=0; i<elems.length; i++) {
switch (elems[i].tagName) {
case 'INPUT':
case 'SELECT':
this.formData[elems[i].name] = elems[i].value;
// create an object from the form data
this.formData = FORM_ELEMENTS.reduce((collection, key) => {
if (!elements[key]) return collection;
switch (key) {
case 'remember':
collection[key] = elements[key].checked;
break;
default:
collection[key] = elements[key].value;
break;
}
}
return collection;
}, {});
this.respond( this.verify(this.formData) );

@@ -158,10 +161,12 @@ }

let ok = false, legalAge = this.ages[formData.country] || this.legalAge;
let date = [
parseInt(formData.year), parseInt(formData.month) || 1, parseInt(formData.day) || 1
let bday = [
parseInt(formData.year, 10),
parseInt(formData.month, 10) || 1,
parseInt(formData.day, 10) || 1
].join('/');
let age = ~~((new Date().getTime() - +new Date(date)) / (31557600000));
let age = ~~((new Date().getTime() - +new Date(bday)) / (31557600000));
// set cookie if desired
if ( !!formData.remember && formData.remember === 'on' )
this.saveCookie(this.defaults.expiry);
if ( !!formData.remember )
this.saveCookie(this.options.expiry);
else

@@ -168,0 +173,0 @@ this.saveCookie();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc