age-gate-location

1.0.12 • Public • Published

What is this?

Validate user's date of birth in relation to selected location using cookies.

Installation

npm i age-gate-location --save

Usage

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

Basic Markup

<form id="ag-form" action=""> # id 'ag-form' for age gate form
  <select name="ag-select"></select> # name 'ag-select' for locations select drop down
  <input type="number" name="ag-month"> # name 'ag-month'
  <input type="number" name="ag-day"> # name 'ag-day'
  <input type="number" name="ag-year"> # name 'ag-year'
  <input type="submit">
</form>

Example 'locations.json' File Layout

Please advise that this package supports a JSON file structure of an array of objects with keys "short", "name", and "legalAge".

The first object in the array will ALWAYS be disabled and used as the pre-selected option of age gate on load.

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 }
]
 

Readme

Keywords

Package Sidebar

Install

npm i age-gate-location

Weekly Downloads

14

Version

1.0.12

License

ISC

Unpacked Size

6.32 kB

Total Files

3

Last publish

Collaborators

  • ianauxly