All Projects → izolate → agegate

izolate / agegate

Licence: MIT License
A simple function that verifies a date of birth against a country's legal drinking age.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to agegate

Nager.Country
Worldwide Country Informations (ISO-3166-1 Alpha2, ISO-3166-1 Alpha3, ISO 639-1)
Stars: ✭ 68 (+325%)
Mutual labels:  countries
world
A Laravel package which provides a list of the countries, states, cities, currencies, timezones and languages.
Stars: ✭ 479 (+2893.75%)
Mutual labels:  countries
jbanking
A Java banking API
Stars: ✭ 58 (+262.5%)
Mutual labels:  countries
socrates
PHP package to Validate and Extract information from National Identification Numbers.
Stars: ✭ 46 (+187.5%)
Mutual labels:  countries
flagpack
A lightweight flag icon toolkit for the web.
Stars: ✭ 51 (+218.75%)
Mutual labels:  countries
billy
An opensource invoicing engine --
Stars: ✭ 28 (+75%)
Mutual labels:  countries
countrynames
Utility library to turn country names into ISO two-letter codes
Stars: ✭ 55 (+243.75%)
Mutual labels:  countries
covid-19
COVID-19 World is yet another Project to build a Dashboard like app to showcase the data related to the COVID-19(Corona Virus).
Stars: ✭ 28 (+75%)
Mutual labels:  countries
RESTCountries.NET
.NET Standard wrapper library around the API provided by REST Countries https://restcountries.com. The world in .NET 🔥.
Stars: ✭ 33 (+106.25%)
Mutual labels:  country-data
visited-countries
🌎 Countries I Have visited
Stars: ✭ 25 (+56.25%)
Mutual labels:  countries
country-to-emoji-flag
Convert an ISO 3166-1 alpha2 code to a unicode emoji flag
Stars: ✭ 26 (+62.5%)
Mutual labels:  countries
flag-icons
A beautiful svg + png + sass + css collection of 261 flags.
Stars: ✭ 61 (+281.25%)
Mutual labels:  countries
china regions
Ruby Library for China Regions
Stars: ✭ 23 (+43.75%)
Mutual labels:  countries
database-of-embassies
Database of embassies and consulates. Download as CSV, no registration, public domain. Powered by Wikidata.
Stars: ✭ 33 (+106.25%)
Mutual labels:  countries
travel
Visualization of Sourabh's adventures
Stars: ✭ 16 (+0%)
Mutual labels:  countries
top-regional-repositories
🌍 The most-relevant repositories for all countries and many cities worldwide.
Stars: ✭ 18 (+12.5%)
Mutual labels:  countries
vue-flagpack
Flagpack contains 260+ easily implementable flag icons to use in your design or code project.
Stars: ✭ 42 (+162.5%)
Mutual labels:  countries
countriesNowAPI
CountriesNow is an Open source API for retrieving geo-information for countries, including their states, cities, population, etc. 🌎
Stars: ✭ 78 (+387.5%)
Mutual labels:  countries
rails-countries
Integration between Rails and countries gem.
Stars: ✭ 17 (+6.25%)
Mutual labels:  countries
geo-sql-database
Continents, Sub-Continents, Countries, States, Cities, Timezones, Currencies SQL database.
Stars: ✭ 30 (+87.5%)
Mutual labels:  countries

Agegate

A simple function that verifies a date of birth against a country's legal drinking age.

npm i agegate

Usage

import agegate from "agegate";

var user = {
  dateOfBirth: new Date("2015-02-14"), // strings are also accepted
  country: "US",
};

var isLegal = agegate(user.dateOfBirth, user.country); // false

⚠️ If an invalid date is supplied, the result will be falsy. If an invalid country code is supplied, it will validate against a default legal drinking age of 18.

Use with frameworks (e.g. React)

In order to use this library with frontend UI frameworks, the underlying dataset used to validate is also exported.

import React, { useState } from "react";
import agegate, { getData } from "agegate";

const countries = getData();

function Modal() {
  const [date, setDate] = useState("");
  const [country, setCountry] = useState(countries[0].code);
  const [legal, setLegal] = useState(false);

  const submitHandler = e => {
    e.preventDefault();

    if (date && country) {
      const result = agegate(new Date(date), country);
      setLegal(result);
    }
  };

  return (
    <div>
      <form onSubmit={submitHandler}>
        <h3>Enter your date of birth</h3>
        <input
          type="date"
          value={date}
          onChange={e => setDate(e.target.value)}
        />

        <h3>Enter your country</h3>
        <select value={country} onChange={e => setCountry(e.target.value)}>
          {countries.map(({ code, name }) => (
            <option key={name} value={code}>
              {name}
            </option>
          ))}
        </select>

        <button type="submit">Submit</button>
      </form>

      <p style={{ color: legal ? "green" : "red" }}>
        RESULT: You are {legal ? "" : "NOT"} old enough!
      </p>
    </div>
  );
}

Please file a new issue if you find any inconsistencies in the countries dataset.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].