geofeed-validator
Version:
A utility to validate geofeed file (RFC8805)
87 lines (85 loc) • 5.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _iso = _interopRequireDefault(require("./dataset/iso3166-1.json"));
var _iso2 = _interopRequireDefault(require("./dataset/iso3166-2.json"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var IsoAbstraction = exports["default"] = /*#__PURE__*/_createClass(function IsoAbstraction() {
var _this = this;
_classCallCheck(this, IsoAbstraction);
_defineProperty(this, "_createIndex", function () {
var _iterator = _createForOfIteratorHelper(_iso["default"]["3166-1"].map(function (i) {
return i["alpha_2"];
})),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var alpha2 = _step.value;
_this.indexCountries[alpha2] = true;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
var _iterator2 = _createForOfIteratorHelper(_iso2["default"]["3166-2"].map(function (i) {
return i["code"];
})),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var item = _step2.value;
_this.indexSubdivisions[item] = item.split("-")[0];
}
} catch (err) {
_iterator2.e(err);
} finally {
_iterator2.f();
}
_this._applyCorrectionsSubdivisions();
});
_defineProperty(this, "_applyCorrectionsSubdivisions", function () {
_this.indexSubdivisions["CN-HK"] = "HK";
// const rename = [["PL-DS", "PL-02"], ["PL-KP", "PL-04"], ["PL-LB", "PL-08"], ["PL-LD", "PL-10"], ["PL-LU", "PL-06"], ["PL-MA", "PL-12"], ["PL-MZ", "PL-14"], ["PL-OP", "PL-16"], ["PL-PD", "PL-20"], ["PL-PK", "PL-18"], ["PL-PM", "PL-22"], ["PL-SK", "PL-26"], ["PL-SL", "PL-24"], ["PL-WN", "PL-28"], ["PL-WP", "PL-30"], ["PL-ZP", "PL-32"]];
// for (let [from, to] of rename) {
// this.indexSubdivisions[to] = this.indexSubdivisions[from];
// delete this.indexSubdivisions[from];
// }
});
_defineProperty(this, "isValidCountryCode", function (code) {
try {
return _this.indexCountries[code.toUpperCase()] || false;
} catch (e) {
return false;
}
});
_defineProperty(this, "isValidSubdivisionCode", function (code) {
try {
return !!_this.indexSubdivisions[code.toUpperCase()] || false;
} catch (e) {
return false;
}
});
_defineProperty(this, "isSubdivisionInCountry", function (subdivisionCode, countryCode) {
try {
return _this.indexSubdivisions[subdivisionCode.toUpperCase()] === countryCode.toUpperCase();
} catch (e) {
return false;
}
});
this.indexCountries = {};
this.indexSubdivisions = {};
this._createIndex();
});