|
11 | 11 |
|
12 | 12 | # WHAT IS IT? |
13 | 13 |
|
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**. |
15 | 15 |
|
16 | 16 | ℹ️ The documentation is also available on our [website](https://superdiff.gitbook.io/donedeal0-superdiff)! |
17 | 17 |
|
|
25 | 25 | - [getListDiff](#getlistdiff) |
26 | 26 | - [streamListDiff](#streamlistdiff) |
27 | 27 | - [getTextDiff](#gettextdiff) |
| 28 | +- [getGeoDiff](#getgeodiff) |
28 | 29 |
|
29 | 30 | <hr/> |
30 | 31 |
|
|
44 | 45 | | List diff | ✅ | ❌ | ⚠️ | ❌ | ⚠️ | |
45 | 46 | | Text diff | ✅ | ❌ | ✅ | ✅ | ❌ | |
46 | 47 | | Streaming for huge datasets | ✅ | ❌ | ❌ | ❌ | ❌ | |
| 48 | +| Geo diff | ✅ | ❌ | ❌ | ❌ | ❌ | |
47 | 49 | | Move detection | ✅ | ❌ | ❌ | ❌ | ❌ | |
48 | 50 | | Output refinement | ✅ | ❌ | ❌ | ❌ | ❌ | |
49 | 51 | | Zero dependencies | ✅ | ✅ | ❌ | ✅ | ✅ | |
@@ -560,7 +562,7 @@ Compares two texts and returns a structured diff at a character, word, or senten |
560 | 562 | - `high`: slower but exact tokenization. Handles all language subtleties (Unicode, emoji, CJK scripts, locale‑aware segmentation when a locale is provided). |
561 | 563 | - `detectMoves`: |
562 | 564 | - `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. |
564 | 566 | - `ignoreCase`: if `true`, `hello` and `HELLO` are considered equal. |
565 | 567 | - `ignorePunctuation`: if `true`, `hello!` and `hello` are considered equal. |
566 | 568 | - `locale`: the locale of your text. Enables locale‑aware segmentation in high accuracy mode. |
@@ -721,6 +723,85 @@ getTextDiff( |
721 | 723 |
|
722 | 724 | <hr/> |
723 | 725 |
|
| 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 | + |
724 | 805 | ### ℹ️ More examples are available in the source code tests. |
725 | 806 |
|
726 | 807 | <hr/> |
|
0 commit comments