Skip to content

Commit e4d374b

Browse files
committed
feat: getGeoDiff
1 parent c52ff35 commit e4d374b

File tree

8 files changed

+602
-13
lines changed

8 files changed

+602
-13
lines changed

README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
# WHAT IS IT?
1313

14-
**Superdiff** provides a rich and readable diff for **arrays**, **objects** and **texts**. It supports **stream** and file inputs for handling large datasets efficiently, is battle-tested, has zero dependencies, and offers a **top-tier performance**.
14+
**Superdiff** provides a rich and readable diff for **arrays**, **objects**, **texts** and **coordinates**. It supports **stream** and file inputs for handling large datasets efficiently, is battle-tested, has zero dependencies, and offers a **top-tier performance**.
1515

1616
ℹ️ The documentation is also available on our [website](https://superdiff.gitbook.io/donedeal0-superdiff)!
1717

@@ -25,6 +25,7 @@
2525
- [getListDiff](#getlistdiff)
2626
- [streamListDiff](#streamlistdiff)
2727
- [getTextDiff](#gettextdiff)
28+
- [getGeoDiff](#getgeodiff)
2829

2930
<hr/>
3031

@@ -44,6 +45,7 @@
4445
| List diff ||| ⚠️ || ⚠️ |
4546
| Text diff ||||||
4647
| Streaming for huge datasets ||||||
48+
| Geo diff ||||||
4749
| Move detection ||||||
4850
| Output refinement ||||||
4951
| Zero dependencies ||||||
@@ -560,7 +562,7 @@ Compares two texts and returns a structured diff at a character, word, or senten
560562
- `high`: slower but exact tokenization. Handles all language subtleties (Unicode, emoji, CJK scripts, locale‑aware segmentation when a locale is provided).
561563
- `detectMoves`:
562564
- `false` (default): optimized for readability. Token moves are ignored so insertions don’t cascade and break equality (recommended for UI diffing).
563-
- `true`: semantically precise, but noiser — a single insertion shifts all following tokens, breaking equality.
565+
- `true`: semantically precise, but noisier — a single insertion shifts all following tokens, breaking equality.
564566
- `ignoreCase`: if `true`, `hello` and `HELLO` are considered equal.
565567
- `ignorePunctuation`: if `true`, `hello!` and `hello` are considered equal.
566568
- `locale`: the locale of your text. Enables locale‑aware segmentation in high accuracy mode.
@@ -721,6 +723,85 @@ getTextDiff(
721723

722724
<hr/>
723725

726+
### getGeoDiff
727+
728+
```js
729+
import { getGeoDiff } from "@donedeal0/superdiff";
730+
```
731+
732+
Returns a structured diff between two geographical coordinates. Supports 9 distance units (centimeters, feet, inches, kilometers, meters, miles, Scandinavian miles, millimeters, yards), locale-aware response, and two accuracy modes.
733+
734+
The high accuracy mode is based on the [Vincenty formulae](https://en.wikipedia.org/wiki/Vincenty%27s_formulae) (ellipsoidal Earth model, higher precision). The normal mode is based on the [Haversine formulae](https://en.wikipedia.org/wiki/Haversine_formula) (spherical Earth model, faster, slightly less precise).
735+
736+
#### FORMAT
737+
738+
**Input**
739+
740+
```ts
741+
previousCoordinates: [number, number] | null | undefined;
742+
coordinates: [number, number] | null | undefined;
743+
options?: {
744+
unit?: "centimeter", "foot", "inch", "kilometer", "meter", "mile", "mile-scandinavian", "millimeter" | "yard", // "kilometers" by default
745+
accuracy?: "normal" | "high", // "normal" by default
746+
maxDecimals?: number, // 2 by default,
747+
locale?: Intl.Locale | string // "en-US" by default
748+
}
749+
```
750+
- `previousCoordinates`: the original list (`[Longitude, Latitude]`).
751+
- `coordinates`: the new list (`[Longitude, Latitude]`).
752+
- `options`
753+
- `unit`: centimeter, foot, inch, kilometer, meter, mile, mile-scandinavian, millimeter or yard.
754+
- `accuracy`:
755+
- `normal` (default): fastest mode, with a small error margin, based on Haversine formula.
756+
- `high`: slower but exact distance. Based on Vincenty formula.
757+
- `maxDecimals`: maximal decimals for the distance. Defaults to 2.
758+
- `locale`: the locale of your distance. Enables a locale‑aware distance label.
759+
760+
**Output**
761+
762+
```ts
763+
type GeoDiff = {
764+
type: "geo";
765+
status: "added" | "deleted" | "error" | "equal" | "updated";
766+
diff: {
767+
coordinates: [number, number] | null;
768+
previousCoordinates: [number, number] | null;
769+
distance: number;
770+
unit: "centimeters", "feet", "inches", "kilometers", "meters", "miles", "scandinavian miles", "millimeters" | "yards";
771+
label: string,
772+
direction: "east" | "north" |"south" | "west" | "north-east" | "north-west" | "south-east" | "south-west" | "stationary";
773+
};
774+
}
775+
```
776+
#### USAGE
777+
778+
**Input**
779+
780+
```diff
781+
getGeoDiff(
782+
- [2.3522, 48.8566],
783+
+ [-0.1278, 51.5074]
784+
);
785+
```
786+
787+
**Output**
788+
789+
```diff
790+
{
791+
type: "geo",
792+
+ status: "updated",
793+
diff: {
794+
+ coordinates: [-0.1278, 51.5074],
795+
previousCoordinates": [2.3522, 48.8566],
796+
+ direction: "north-west",
797+
+ distance: 343.56,
798+
+ label: "343.56 kilometers",
799+
+ unit: "kilometer"
800+
}
801+
}
802+
```
803+
<hr/>
804+
724805
### ℹ️ More examples are available in the source code tests.
725806

726807
<hr/>

package.json

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "@donedeal0/superdiff",
3-
"version": "4.1.0",
3+
"version": "4.2.0",
44
"type": "module",
5-
"description": "Superdiff provides a rich and readable diff for arrays, objects and texts. It supports stream and file inputs for handling large datasets efficiently, is battle-tested, has zero dependencies, and offers a top-tier performance.",
5+
"description": "Superdiff provides a rich and readable diff for arrays, objects, texts and coordinates. It supports stream and file inputs for handling large datasets efficiently, is battle-tested, has zero dependencies, and offers a top-tier performance.",
66
"main": "dist/index.js",
77
"module": "dist/index.js",
88
"types": "dist/index.d.ts",
@@ -49,33 +49,37 @@
4949
"array-comparison",
5050
"array-diff",
5151
"chunks",
52+
"code-diff",
5253
"compare",
5354
"comparison-tool",
55+
"coordinates",
5456
"data-diff",
5557
"deep-comparison",
5658
"deep-diff",
5759
"deep-object-diff",
5860
"diff",
5961
"file-diff",
62+
"geo-diff",
63+
"geo-distance",
64+
"haversine",
6065
"isequal",
6166
"json-diff",
6267
"json",
68+
"lat-long",
69+
"lcs",
6370
"list-diff",
6471
"object-comparison",
6572
"object-diff",
6673
"object-difference",
6774
"object",
68-
"stream",
6975
"stream-diff",
70-
"streaming",
7176
"streaming-diff",
77+
"streaming",
78+
"string-diff",
7279
"text-diff",
7380
"textdiff",
74-
"string-diff",
75-
"word-diff",
76-
"code-diff",
77-
"diff-match-patch",
78-
"lcs"
81+
"vincenty",
82+
"word-diff"
7983
],
8084
"scripts": {
8185
"benchmark": "tsx benchmark/index.ts",

0 commit comments

Comments
 (0)