How to use the maxmind.validate function in maxmind

To help you get started, we’ve selected a few maxmind examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / fxa / packages / fxa-geodb / lib / fxa-geodb.js View on Github external
return (ip, options = {}) => {
    const userLocale = options.userLocale || DEFAULTS.USER_LOCALE;

    // check if ip is valid
    if (!maxmind.validate(ip)) {
      throw new Error(ERRORS.IS_INVALID);
    }

    const locationData = dbLookup.get(ip);
    if (locationData == null) {
      throw new Error(ERRORS.UNABLE_TO_FETCH_DATA);
    }

    // return an object with city, country, continent,
    // latitude, and longitude, and timezone
    return new Location(locationData, userLocale);
  };
};
github Jigsaw-Code / outline-server / src / shadowbox / infrastructure / ip_location.ts View on Github external
return this.db.then((reader) => {
      if (!reader) {
        throw new Error('MMDB reader is not valid');
      }
      if (!maxmind.validate(ipAddress)) {
        throw new Error('Invalid IP address');
      }
      const result = reader.get(ipAddress);
      return (result && result.country && result.country.iso_code) || 'ZZ';
    });
  }

maxmind

IP lookup using Maxmind databases

MIT
Latest version published 5 months ago

Package Health Score

79 / 100
Full package analysis