npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

age-gate-location

v1.0.12

Published

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

Downloads

6

Readme

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