mapcode-ts 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +8 -0
- package/README.md +3 -3
- package/dist/index.cjs +29 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +29 -16
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1246,16 +1246,14 @@ var _Mapcode = class _Mapcode {
|
|
|
1246
1246
|
}
|
|
1247
1247
|
getCode(precisionOrAlphabet, alphabet) {
|
|
1248
1248
|
const { precision, alpha } = _Mapcode.resolveArgs(precisionOrAlphabet, alphabet);
|
|
1249
|
+
_Mapcode.checkPrecision(precision);
|
|
1249
1250
|
if (precision === 0) {
|
|
1250
1251
|
return convertStringToAlphabet(this.codePrecision8.substring(0, this.codePrecision8.length - 9), alpha);
|
|
1251
|
-
} else if (precision <= 8) {
|
|
1252
|
-
return convertStringToAlphabet(
|
|
1253
|
-
this.codePrecision8.substring(0, this.codePrecision8.length - 8 + precision),
|
|
1254
|
-
alpha
|
|
1255
|
-
);
|
|
1256
|
-
} else {
|
|
1257
|
-
throw new IllegalArgumentError("getCodePrecision: precision must be in [0, 8]");
|
|
1258
1252
|
}
|
|
1253
|
+
return convertStringToAlphabet(
|
|
1254
|
+
this.codePrecision8.substring(0, this.codePrecision8.length - 8 + precision),
|
|
1255
|
+
alpha
|
|
1256
|
+
);
|
|
1259
1257
|
}
|
|
1260
1258
|
getCodeWithTerritoryFullname(precisionOrAlphabet, alphabet) {
|
|
1261
1259
|
const { precision, alpha } = _Mapcode.resolveArgs(precisionOrAlphabet, alphabet);
|
|
@@ -1284,6 +1282,11 @@ var _Mapcode = class _Mapcode {
|
|
|
1284
1282
|
}
|
|
1285
1283
|
return { precision: precisionOrAlphabet, alpha: alphabet ?? null };
|
|
1286
1284
|
}
|
|
1285
|
+
static checkPrecision(precision) {
|
|
1286
|
+
if (!Number.isInteger(precision) || precision < 0 || precision > 8) {
|
|
1287
|
+
throw new IllegalArgumentError("precision must be an integer in [0, 8]");
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1287
1290
|
/**
|
|
1288
1291
|
* Return the mapcode precision format, given a mapcode string. Throws if the format is invalid.
|
|
1289
1292
|
*
|
|
@@ -1332,9 +1335,7 @@ var _Mapcode = class _Mapcode {
|
|
|
1332
1335
|
* Get a safe maximum for the distance between a decoded mapcode and its original location.
|
|
1333
1336
|
*/
|
|
1334
1337
|
static getSafeMaxOffsetInMeters(precision) {
|
|
1335
|
-
|
|
1336
|
-
throw new IllegalArgumentError("precision must be in [0, 8]");
|
|
1337
|
-
}
|
|
1338
|
+
_Mapcode.checkPrecision(precision);
|
|
1338
1339
|
return _Mapcode.PRECISION_0_MAX_OFFSET_METERS[precision];
|
|
1339
1340
|
}
|
|
1340
1341
|
/**
|
|
@@ -2301,7 +2302,7 @@ _Territory.LIE = new _Territory(24, "Liechtenstein", null, null, null, null);
|
|
|
2301
2302
|
_Territory.ABW = new _Territory(25, "Aruba", null, null, null, null);
|
|
2302
2303
|
_Territory.MHL = new _Territory(26, "Marshall Islands", null, null, ["WAK"], null);
|
|
2303
2304
|
_Territory.ASM = new _Territory(27, "American Samoa", null, null, ["US-AS", "USA-AS"], ["Samoa, American"]);
|
|
2304
|
-
_Territory.COK = new _Territory(28, "Cook
|
|
2305
|
+
_Territory.COK = new _Territory(28, "Cook Islands", null, null, null, null);
|
|
2305
2306
|
_Territory.SPM = new _Territory(29, "Saint Pierre and Miquelon", null, null, null, ["Miquelon"]);
|
|
2306
2307
|
_Territory.NIU = new _Territory(30, "Niue", null, null, null, null);
|
|
2307
2308
|
_Territory.KNA = new _Territory(31, "Saint Kitts and Nevis", null, null, null, ["Nevis"]);
|
|
@@ -2362,11 +2363,11 @@ _Territory.BHS = new _Territory(85, "Bahamas", null, null, null, null);
|
|
|
2362
2363
|
_Territory.TLS = new _Territory(86, "East Timor", [Alphabet.ROMAN, Alphabet.ARABIC], null, null, null);
|
|
2363
2364
|
_Territory.SWZ = new _Territory(87, "Swaziland", null, null, null, null);
|
|
2364
2365
|
_Territory.KWT = new _Territory(88, "Kuwait", [Alphabet.ARABIC, Alphabet.ROMAN], null, null, null);
|
|
2365
|
-
_Territory.FJI = new _Territory(89, "Fiji
|
|
2366
|
+
_Territory.FJI = new _Territory(89, "Republic of Fiji", [Alphabet.ROMAN, Alphabet.DEVANAGARI], null, null, null);
|
|
2366
2367
|
_Territory.NCL = new _Territory(90, "New Caledonia", null, null, null, null);
|
|
2367
2368
|
_Territory.SVN = new _Territory(91, "Slovenia", null, null, null, null);
|
|
2368
2369
|
_Territory.ISR = new _Territory(92, "Israel", [Alphabet.HEBREW, Alphabet.ARABIC, Alphabet.ROMAN], null, null, null);
|
|
2369
|
-
_Territory.PSE = new _Territory(93, "
|
|
2370
|
+
_Territory.PSE = new _Territory(93, "Palestine", [Alphabet.HEBREW, Alphabet.ARABIC, Alphabet.ROMAN], null, null, null);
|
|
2370
2371
|
_Territory.SLV = new _Territory(94, "El Salvador", null, null, null, null);
|
|
2371
2372
|
_Territory.BLZ = new _Territory(95, "Belize", null, null, null, null);
|
|
2372
2373
|
_Territory.DJI = new _Territory(96, "Djibouti", [Alphabet.ARABIC, Alphabet.ROMAN], null, null, null);
|
|
@@ -2673,7 +2674,7 @@ _Territory.CA_ON = new _Territory(396, "Ontario", null, _Territory.CAN, null, nu
|
|
|
2673
2674
|
_Territory.CA_QC = new _Territory(397, "Quebec", null, _Territory.CAN, null, null);
|
|
2674
2675
|
_Territory.CA_SK = new _Territory(398, "Saskatchewan", null, _Territory.CAN, null, null);
|
|
2675
2676
|
_Territory.CA_MB = new _Territory(399, "Manitoba", null, _Territory.CAN, null, null);
|
|
2676
|
-
_Territory.CA_NL = new _Territory(400, "Newfoundland", null, _Territory.CAN, null, null);
|
|
2677
|
+
_Territory.CA_NL = new _Territory(400, "Newfoundland and Labrador", null, _Territory.CAN, null, null);
|
|
2677
2678
|
_Territory.CA_NB = new _Territory(401, "New Brunswick", null, _Territory.CAN, null, null);
|
|
2678
2679
|
_Territory.CA_NS = new _Territory(402, "Nova Scotia", null, _Territory.CAN, null, null);
|
|
2679
2680
|
_Territory.CA_PE = new _Territory(403, "Prince Edward Island", null, _Territory.CAN, null, null);
|
|
@@ -2683,7 +2684,7 @@ _Territory.CA_NU = new _Territory(406, "Nunavut", null, _Territory.CAN, null, nu
|
|
|
2683
2684
|
_Territory.RU_MOW = new _Territory(412, "Moscow", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2684
2685
|
_Territory.RU_SPE = new _Territory(413, "Saint Petersburg", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2685
2686
|
_Territory.RU_KGD = new _Territory(414, "Kaliningrad Oblast", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2686
|
-
_Territory.RU_IN = new _Territory(415, "Ingushetia
|
|
2687
|
+
_Territory.RU_IN = new _Territory(415, "Republic of Ingushetia", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2687
2688
|
_Territory.RU_AD = new _Territory(416, "Adygea Republic", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2688
2689
|
_Territory.RU_SE = new _Territory(417, "North Ossetia-Alania Republic", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2689
2690
|
_Territory.RU_KB = new _Territory(418, "Kabardino-Balkar Republic", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
@@ -3875,6 +3876,11 @@ var DATA_MODEL4 = DataModel.getInstance();
|
|
|
3875
3876
|
var createBoundaryForTerritoryRecord2 = Boundary.createBoundaryForTerritoryRecord.bind(Boundary);
|
|
3876
3877
|
var { X_SIDE, Y_SIDE, NC, xDivider, countCityCoordinatesForCountry, getFirstNamelessRecord } = Common;
|
|
3877
3878
|
var ENCODE_CHARS2 = Data.ENCODE_CHARS;
|
|
3879
|
+
function checkFiniteCoordinate(param, value) {
|
|
3880
|
+
if (!Number.isFinite(value)) {
|
|
3881
|
+
throw new IllegalArgumentError(`Parameter ${param} must be a finite number`);
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3878
3884
|
function encodeExtension(pointToEncode, extrax4, extray, dividerx4, dividery, ydirection) {
|
|
3879
3885
|
let extraDigits = 8;
|
|
3880
3886
|
let factorx = Point.MAX_PRECISION_FACTOR * dividerx4;
|
|
@@ -4195,6 +4201,8 @@ var Encoder = class {
|
|
|
4195
4201
|
constructor() {
|
|
4196
4202
|
}
|
|
4197
4203
|
static encode(latDeg, lonDeg, territory, limitToOneResult) {
|
|
4204
|
+
checkFiniteCoordinate("latDeg", latDeg);
|
|
4205
|
+
checkFiniteCoordinate("lonDeg", lonDeg);
|
|
4198
4206
|
return encodeInternal(latDeg, lonDeg, territory, limitToOneResult, null);
|
|
4199
4207
|
}
|
|
4200
4208
|
};
|
|
@@ -4236,7 +4244,7 @@ function encode(arg0, arg1, arg2) {
|
|
|
4236
4244
|
if (arg0 instanceof Point) {
|
|
4237
4245
|
const point = arg0;
|
|
4238
4246
|
const restrictToTerritory2 = arg1 ?? null;
|
|
4239
|
-
|
|
4247
|
+
checkDefined("point", point);
|
|
4240
4248
|
return encode(point.getLatDeg(), point.getLonDeg(), restrictToTerritory2);
|
|
4241
4249
|
}
|
|
4242
4250
|
const latDeg = arg0;
|
|
@@ -4350,6 +4358,11 @@ function decode2(mapcode, defaultTerritoryContext) {
|
|
|
4350
4358
|
function decodeToRectangle(mapcode, defaultTerritoryContext) {
|
|
4351
4359
|
checkNonnull("mapcode", mapcode);
|
|
4352
4360
|
const mapcodeZone = decodeToMapcodeZone(mapcode, defaultTerritoryContext ?? null);
|
|
4361
|
+
if (mapcodeZone.isEmpty()) {
|
|
4362
|
+
throw new UnknownMapcodeError(
|
|
4363
|
+
"Unknown mapcode, mapcode=" + mapcode + ", territoryContext=" + defaultTerritoryContext
|
|
4364
|
+
);
|
|
4365
|
+
}
|
|
4353
4366
|
const southWest = Point.fromLatLonFractions(mapcodeZone.getLatFractionMin(), mapcodeZone.getLonFractionMin());
|
|
4354
4367
|
const northEast = Point.fromLatLonFractions(mapcodeZone.getLatFractionMax(), mapcodeZone.getLonFractionMax());
|
|
4355
4368
|
const rectangle = new Rectangle(southWest, northEast);
|