UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

74 lines (72 loc) • 2.97 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var validation_exports = {}; __export(validation_exports, { assertIdentifier: () => assertIdentifier, assertRegion: () => assertRegion, assertRegionListener: () => assertRegionListener }); module.exports = __toCommonJS(validation_exports); function isFiniteNumber(value) { return typeof value === "number" && Number.isFinite(value); } function assertCenter(center, verb) { if (!center || typeof center !== "object") { throw new TypeError(`Location.${verb}: region center must be an object`); } var candidate = center; if (!isFiniteNumber(candidate.latitude) || Math.abs(candidate.latitude) > 90) { throw new TypeError(`Location.${verb}: region center latitude must be a number from -90 to 90`); } if (!isFiniteNumber(candidate.longitude) || Math.abs(candidate.longitude) > 180) { throw new TypeError(`Location.${verb}: region center longitude must be a number from -180 to 180`); } } function assertRegion(region, verb) { if (!region || typeof region !== "object") { throw new TypeError(`Location.${verb}: region must be an object`); } var candidate = region; if (typeof candidate.identifier !== "string" || candidate.identifier.trim() === "") { throw new TypeError(`Location.${verb}: region identifier must be a non-empty string`); } assertCenter(candidate.center, verb); if (!isFiniteNumber(candidate.radius) || candidate.radius <= 0) { throw new TypeError(`Location.${verb}: region radius must be a number greater than 0`); } if (candidate.notifyOnEntry !== void 0 && typeof candidate.notifyOnEntry !== "boolean") { throw new TypeError(`Location.${verb}: region notifyOnEntry must be a boolean`); } if (candidate.notifyOnExit !== void 0 && typeof candidate.notifyOnExit !== "boolean") { throw new TypeError(`Location.${verb}: region notifyOnExit must be a boolean`); } } function assertIdentifier(identifier, verb) { if (typeof identifier !== "string" || identifier.trim() === "") { throw new TypeError(`Location.${verb}: region identifier must be a non-empty string`); } } function assertRegionListener(listener, verb) { if (typeof listener !== "function") { throw new TypeError(`Location.${verb}: listener must be a function`); } }