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/NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-------------------------------------------------------------------------------
|
|
2
|
+
MAPCODE TYPESCRIPT LIBRARY
|
|
3
|
+
-------------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
Original C library created by Pieter Geelen. Work on TypeScript version
|
|
6
|
+
of the Mapcode library by Rijn Buve.
|
|
7
|
+
|
|
8
|
+
Copyright (C) 2014-2026, Stichting Mapcode Foundation (http://www.mapcode.com)
|
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ This is a faithful TypeScript port of the [mapcode-java](https://github.com/mapc
|
|
|
11
11
|
(version 2.4.19).
|
|
12
12
|
|
|
13
13
|
Licensed under the [Apache License, Version 2.0](LICENSE).
|
|
14
|
-
Copyright (C) 2014-
|
|
14
|
+
Copyright (C) 2014-2026, Stichting Mapcode Foundation.
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
@@ -101,8 +101,8 @@ console.log(t.getFullName()); // "Netherlands"
|
|
|
101
101
|
|
|
102
102
|
// Request a mapcode rendered in a specific alphabet:
|
|
103
103
|
const m = encodeToShortest(37.9715, 23.7263, Territory.GRC);
|
|
104
|
-
console.log(m.getCode()); // Roman: "
|
|
105
|
-
console.log(m.getCode(Alphabet.GREEK)); // Greek script
|
|
104
|
+
console.log(m.getCode()); // Roman: "HJ.Q5"
|
|
105
|
+
console.log(m.getCode(Alphabet.GREEK)); // Greek script: "ΗΠ.485"
|
|
106
106
|
```
|
|
107
107
|
|
|
108
108
|
---
|
package/dist/index.cjs
CHANGED
|
@@ -1294,16 +1294,14 @@ var _Mapcode = class _Mapcode {
|
|
|
1294
1294
|
}
|
|
1295
1295
|
getCode(precisionOrAlphabet, alphabet) {
|
|
1296
1296
|
const { precision, alpha } = _Mapcode.resolveArgs(precisionOrAlphabet, alphabet);
|
|
1297
|
+
_Mapcode.checkPrecision(precision);
|
|
1297
1298
|
if (precision === 0) {
|
|
1298
1299
|
return convertStringToAlphabet(this.codePrecision8.substring(0, this.codePrecision8.length - 9), alpha);
|
|
1299
|
-
} else if (precision <= 8) {
|
|
1300
|
-
return convertStringToAlphabet(
|
|
1301
|
-
this.codePrecision8.substring(0, this.codePrecision8.length - 8 + precision),
|
|
1302
|
-
alpha
|
|
1303
|
-
);
|
|
1304
|
-
} else {
|
|
1305
|
-
throw new IllegalArgumentError("getCodePrecision: precision must be in [0, 8]");
|
|
1306
1300
|
}
|
|
1301
|
+
return convertStringToAlphabet(
|
|
1302
|
+
this.codePrecision8.substring(0, this.codePrecision8.length - 8 + precision),
|
|
1303
|
+
alpha
|
|
1304
|
+
);
|
|
1307
1305
|
}
|
|
1308
1306
|
getCodeWithTerritoryFullname(precisionOrAlphabet, alphabet) {
|
|
1309
1307
|
const { precision, alpha } = _Mapcode.resolveArgs(precisionOrAlphabet, alphabet);
|
|
@@ -1332,6 +1330,11 @@ var _Mapcode = class _Mapcode {
|
|
|
1332
1330
|
}
|
|
1333
1331
|
return { precision: precisionOrAlphabet, alpha: alphabet ?? null };
|
|
1334
1332
|
}
|
|
1333
|
+
static checkPrecision(precision) {
|
|
1334
|
+
if (!Number.isInteger(precision) || precision < 0 || precision > 8) {
|
|
1335
|
+
throw new IllegalArgumentError("precision must be an integer in [0, 8]");
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1335
1338
|
/**
|
|
1336
1339
|
* Return the mapcode precision format, given a mapcode string. Throws if the format is invalid.
|
|
1337
1340
|
*
|
|
@@ -1380,9 +1383,7 @@ var _Mapcode = class _Mapcode {
|
|
|
1380
1383
|
* Get a safe maximum for the distance between a decoded mapcode and its original location.
|
|
1381
1384
|
*/
|
|
1382
1385
|
static getSafeMaxOffsetInMeters(precision) {
|
|
1383
|
-
|
|
1384
|
-
throw new IllegalArgumentError("precision must be in [0, 8]");
|
|
1385
|
-
}
|
|
1386
|
+
_Mapcode.checkPrecision(precision);
|
|
1386
1387
|
return _Mapcode.PRECISION_0_MAX_OFFSET_METERS[precision];
|
|
1387
1388
|
}
|
|
1388
1389
|
/**
|
|
@@ -2349,7 +2350,7 @@ _Territory.LIE = new _Territory(24, "Liechtenstein", null, null, null, null);
|
|
|
2349
2350
|
_Territory.ABW = new _Territory(25, "Aruba", null, null, null, null);
|
|
2350
2351
|
_Territory.MHL = new _Territory(26, "Marshall Islands", null, null, ["WAK"], null);
|
|
2351
2352
|
_Territory.ASM = new _Territory(27, "American Samoa", null, null, ["US-AS", "USA-AS"], ["Samoa, American"]);
|
|
2352
|
-
_Territory.COK = new _Territory(28, "Cook
|
|
2353
|
+
_Territory.COK = new _Territory(28, "Cook Islands", null, null, null, null);
|
|
2353
2354
|
_Territory.SPM = new _Territory(29, "Saint Pierre and Miquelon", null, null, null, ["Miquelon"]);
|
|
2354
2355
|
_Territory.NIU = new _Territory(30, "Niue", null, null, null, null);
|
|
2355
2356
|
_Territory.KNA = new _Territory(31, "Saint Kitts and Nevis", null, null, null, ["Nevis"]);
|
|
@@ -2410,11 +2411,11 @@ _Territory.BHS = new _Territory(85, "Bahamas", null, null, null, null);
|
|
|
2410
2411
|
_Territory.TLS = new _Territory(86, "East Timor", [Alphabet.ROMAN, Alphabet.ARABIC], null, null, null);
|
|
2411
2412
|
_Territory.SWZ = new _Territory(87, "Swaziland", null, null, null, null);
|
|
2412
2413
|
_Territory.KWT = new _Territory(88, "Kuwait", [Alphabet.ARABIC, Alphabet.ROMAN], null, null, null);
|
|
2413
|
-
_Territory.FJI = new _Territory(89, "Fiji
|
|
2414
|
+
_Territory.FJI = new _Territory(89, "Republic of Fiji", [Alphabet.ROMAN, Alphabet.DEVANAGARI], null, null, null);
|
|
2414
2415
|
_Territory.NCL = new _Territory(90, "New Caledonia", null, null, null, null);
|
|
2415
2416
|
_Territory.SVN = new _Territory(91, "Slovenia", null, null, null, null);
|
|
2416
2417
|
_Territory.ISR = new _Territory(92, "Israel", [Alphabet.HEBREW, Alphabet.ARABIC, Alphabet.ROMAN], null, null, null);
|
|
2417
|
-
_Territory.PSE = new _Territory(93, "
|
|
2418
|
+
_Territory.PSE = new _Territory(93, "Palestine", [Alphabet.HEBREW, Alphabet.ARABIC, Alphabet.ROMAN], null, null, null);
|
|
2418
2419
|
_Territory.SLV = new _Territory(94, "El Salvador", null, null, null, null);
|
|
2419
2420
|
_Territory.BLZ = new _Territory(95, "Belize", null, null, null, null);
|
|
2420
2421
|
_Territory.DJI = new _Territory(96, "Djibouti", [Alphabet.ARABIC, Alphabet.ROMAN], null, null, null);
|
|
@@ -2721,7 +2722,7 @@ _Territory.CA_ON = new _Territory(396, "Ontario", null, _Territory.CAN, null, nu
|
|
|
2721
2722
|
_Territory.CA_QC = new _Territory(397, "Quebec", null, _Territory.CAN, null, null);
|
|
2722
2723
|
_Territory.CA_SK = new _Territory(398, "Saskatchewan", null, _Territory.CAN, null, null);
|
|
2723
2724
|
_Territory.CA_MB = new _Territory(399, "Manitoba", null, _Territory.CAN, null, null);
|
|
2724
|
-
_Territory.CA_NL = new _Territory(400, "Newfoundland", null, _Territory.CAN, null, null);
|
|
2725
|
+
_Territory.CA_NL = new _Territory(400, "Newfoundland and Labrador", null, _Territory.CAN, null, null);
|
|
2725
2726
|
_Territory.CA_NB = new _Territory(401, "New Brunswick", null, _Territory.CAN, null, null);
|
|
2726
2727
|
_Territory.CA_NS = new _Territory(402, "Nova Scotia", null, _Territory.CAN, null, null);
|
|
2727
2728
|
_Territory.CA_PE = new _Territory(403, "Prince Edward Island", null, _Territory.CAN, null, null);
|
|
@@ -2731,7 +2732,7 @@ _Territory.CA_NU = new _Territory(406, "Nunavut", null, _Territory.CAN, null, nu
|
|
|
2731
2732
|
_Territory.RU_MOW = new _Territory(412, "Moscow", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2732
2733
|
_Territory.RU_SPE = new _Territory(413, "Saint Petersburg", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2733
2734
|
_Territory.RU_KGD = new _Territory(414, "Kaliningrad Oblast", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2734
|
-
_Territory.RU_IN = new _Territory(415, "Ingushetia
|
|
2735
|
+
_Territory.RU_IN = new _Territory(415, "Republic of Ingushetia", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2735
2736
|
_Territory.RU_AD = new _Territory(416, "Adygea Republic", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2736
2737
|
_Territory.RU_SE = new _Territory(417, "North Ossetia-Alania Republic", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
2737
2738
|
_Territory.RU_KB = new _Territory(418, "Kabardino-Balkar Republic", [Alphabet.CYRILLIC, Alphabet.ROMAN], _Territory.RUS, null, null);
|
|
@@ -3923,6 +3924,11 @@ var DATA_MODEL4 = DataModel.getInstance();
|
|
|
3923
3924
|
var createBoundaryForTerritoryRecord2 = Boundary.createBoundaryForTerritoryRecord.bind(Boundary);
|
|
3924
3925
|
var { X_SIDE, Y_SIDE, NC, xDivider, countCityCoordinatesForCountry, getFirstNamelessRecord } = Common;
|
|
3925
3926
|
var ENCODE_CHARS2 = Data.ENCODE_CHARS;
|
|
3927
|
+
function checkFiniteCoordinate(param, value) {
|
|
3928
|
+
if (!Number.isFinite(value)) {
|
|
3929
|
+
throw new IllegalArgumentError(`Parameter ${param} must be a finite number`);
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3926
3932
|
function encodeExtension(pointToEncode, extrax4, extray, dividerx4, dividery, ydirection) {
|
|
3927
3933
|
let extraDigits = 8;
|
|
3928
3934
|
let factorx = Point.MAX_PRECISION_FACTOR * dividerx4;
|
|
@@ -4243,6 +4249,8 @@ var Encoder = class {
|
|
|
4243
4249
|
constructor() {
|
|
4244
4250
|
}
|
|
4245
4251
|
static encode(latDeg, lonDeg, territory, limitToOneResult) {
|
|
4252
|
+
checkFiniteCoordinate("latDeg", latDeg);
|
|
4253
|
+
checkFiniteCoordinate("lonDeg", lonDeg);
|
|
4246
4254
|
return encodeInternal(latDeg, lonDeg, territory, limitToOneResult, null);
|
|
4247
4255
|
}
|
|
4248
4256
|
};
|
|
@@ -4284,7 +4292,7 @@ function encode(arg0, arg1, arg2) {
|
|
|
4284
4292
|
if (arg0 instanceof Point) {
|
|
4285
4293
|
const point = arg0;
|
|
4286
4294
|
const restrictToTerritory2 = arg1 ?? null;
|
|
4287
|
-
|
|
4295
|
+
checkDefined("point", point);
|
|
4288
4296
|
return encode(point.getLatDeg(), point.getLonDeg(), restrictToTerritory2);
|
|
4289
4297
|
}
|
|
4290
4298
|
const latDeg = arg0;
|
|
@@ -4398,6 +4406,11 @@ function decode2(mapcode, defaultTerritoryContext) {
|
|
|
4398
4406
|
function decodeToRectangle(mapcode, defaultTerritoryContext) {
|
|
4399
4407
|
checkNonnull("mapcode", mapcode);
|
|
4400
4408
|
const mapcodeZone = decodeToMapcodeZone(mapcode, defaultTerritoryContext ?? null);
|
|
4409
|
+
if (mapcodeZone.isEmpty()) {
|
|
4410
|
+
throw new UnknownMapcodeError(
|
|
4411
|
+
"Unknown mapcode, mapcode=" + mapcode + ", territoryContext=" + defaultTerritoryContext
|
|
4412
|
+
);
|
|
4413
|
+
}
|
|
4401
4414
|
const southWest = Point.fromLatLonFractions(mapcodeZone.getLatFractionMin(), mapcodeZone.getLonFractionMin());
|
|
4402
4415
|
const northEast = Point.fromLatLonFractions(mapcodeZone.getLatFractionMax(), mapcodeZone.getLonFractionMax());
|
|
4403
4416
|
const rectangle = new Rectangle(southWest, northEast);
|