Validate user's date of birth in relation to selected location using cookies.
import { agCookieName, agCookieDaysExpire, loadLocations, agReturnCookie } from 'age-gate-location';
agCookieName('example-cookie-name') # sets age gate cookie name
agCookieDaysExpire(30) # sets days until cookie expiration
loadLocations('locations.json') # set path to local file that will populate select dropdown locations and respected legal age
agReturnCookie() # get cookie value from cookie name set using agCookieName
Please advise that this package supports a JSON file structure of an array of objects with keys "short", "name", and "legalAge".
Below is an example for Canada.
[
{ "short":"disabled", "name":"Select Location","legalAge": null },
{ "short":"AB", "name":"Alberta","legalAge": 18 },
{ "short":"BC", "name":"British Columbia","legalAge": 19 },
{ "short":"MB", "name":"Manitoba","legalAge": 19 },
{ "short":"NB", "name":"New Brunswick","legalAge": 19 },
{ "short":"NL", "name":"Newfoundland and Labrador","legalAge": 19 },
{ "short":"NS", "name":"Nova Scotia","legalAge": 19 },
{ "short":"ON", "name":"Ontario","legalAge": 19 },
{ "short":"PE", "name":"Prince Edward Island","legalAge": 19 },
{ "short":"QC", "name":"Quebec","legalAge": 18 },
{ "short":"SK", "name":"Saskatchewan","legalAge": 19 },
{ "short":"NT", "name":"Northwest Territories","legalAge": 19 },
{ "short":"NU", "name":"Nunavut","legalAge": 19 },
{ "short":"YT", "name":"Yukon","legalAge": 19 },
{ "short":"OC", "name":"Outside Canada","legalAge": 21 }
]
Below is an example using countries.
[
{ "short":"disabled", "name":"Select Country","legalAge": null },
{ "short":"CA", "name":"Canada","legalAge": 19 },
{ "short":"US", "name":"United States","legalAge": 21 },
{ "short":"UG", "name":"Uruguay","legalAge": 18 }
]