mapcode-ts 1.0.0 → 1.0.1

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/dist/index.d.cts CHANGED
@@ -683,6 +683,7 @@ declare class Mapcode {
683
683
  * matching the Java method-overload resolution.
684
684
  */
685
685
  private static resolveArgs;
686
+ private static checkPrecision;
686
687
  /**
687
688
  * These patterns and matchers are used internally in this module to match mapcodes.
688
689
  *
package/dist/index.d.ts CHANGED
@@ -683,6 +683,7 @@ declare class Mapcode {
683
683
  * matching the Java method-overload resolution.
684
684
  */
685
685
  private static resolveArgs;
686
+ private static checkPrecision;
686
687
  /**
687
688
  * These patterns and matchers are used internally in this module to match mapcodes.
688
689
  *
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
- if (precision < 0 || precision > 8) {
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
  /**
@@ -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
- checkNonnull("point", point);
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);