Skip to content

Commit

Permalink
enable legacy mode (geohash tags with length 2 only)
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Feb 5, 2024
1 parent 7a55e1c commit 22725b4
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 166 deletions.
40 changes: 21 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ Here two `alpha2` codes are returned, the original `ISO-3166-1` code, and the ch
Here is the default response when `lat`, `lon`, `countryCode`, `regionName`, **and** `planet` are provided, with everything else default
```
[
[ 'g', 'u2mwdd8q4' ],
[ 'g', 'u2mwdd8q' ],
[ 'g', 'u2mwdd8' ],
[ 'g', 'u2mwdd' ],
[ 'g', 'u2mwd' ],
[ 'g', 'u2mw' ],
[ 'g', 'u2m' ],
[ 'g', 'u2' ],
[ 'g', 'u' ],
[ 'G', 'geohash' ],
[ 'g', 'u2mwdd8q4', 'geohash' ],
[ 'g', 'u2mwdd8q', 'geohash' ],
[ 'g', 'u2mwdd8', 'geohash' ],
[ 'g', 'u2mwdd', 'geohash' ],
[ 'g', 'u2mwd', 'geohash' ],
[ 'g', 'u2mw', 'geohash' ],
[ 'g', 'u2m', 'geohash' ],
[ 'g', 'u2', 'geohash' ],
[ 'g', 'u', 'geohash' ],
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
Expand All @@ -180,7 +181,7 @@ Here is the default response when `lat`, `lon`, `countryCode`, `regionName`, **a
This is a response with all options enabled (deduped, `dedupe: true`)

```
[
[
[ 'G', 'dd' ],
[ 'g', '47.5636, 19.0947', 'dd' ],
[ 'G', 'lat' ],
Expand All @@ -193,15 +194,16 @@ This is a response with all options enabled (deduped, `dedupe: true`)
[ 'g', '19.094', 'lon' ],
[ 'g', '19.09', 'lon' ],
[ 'g', '19', 'lon' ],
[ 'g', 'u2mwdd8q4' ],
[ 'g', 'u2mwdd8q' ],
[ 'g', 'u2mwdd8' ],
[ 'g', 'u2mwdd' ],
[ 'g', 'u2mwd' ],
[ 'g', 'u2mw' ],
[ 'g', 'u2m' ],
[ 'g', 'u2' ],
[ 'g', 'u' ],
[ 'G', 'geohash' ],
[ 'g', 'u2mwdd8q4', 'geohash' ],
[ 'g', 'u2mwdd8q', 'geohash' ],
[ 'g', 'u2mwdd8', 'geohash' ],
[ 'g', 'u2mwdd', 'geohash' ],
[ 'g', 'u2mwd', 'geohash' ],
[ 'g', 'u2mw', 'geohash' ],
[ 'g', 'u2m', 'geohash' ],
[ 'g', 'u2', 'geohash' ],
[ 'g', 'u', 'geohash' ],
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
Expand Down
97 changes: 55 additions & 42 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('generateTags()', () => {
};

const options: Options = {
//dedupe: true,
sort: false,
iso31661: true,
iso31662: true,
Expand All @@ -46,46 +45,46 @@ describe('generateTags()', () => {
const result = ngeotags(input, options);
console.log('all defaults', result)
expect(result).toEqual(expect.arrayContaining([
[ 'G', 'dd' ],
[ 'g', '47.5636, 19.0947', 'dd' ],
[ 'G', 'lat' ],
[ 'g', '47.5636', 'lat' ],
[ 'g', '47.563', 'lat' ],
[ 'g', '47.56', 'lat' ],
[ 'g', '47.5', 'lat' ],
[ 'G', 'lon' ],
[ 'g', '19.0947', 'lon' ],
[ 'g', '19.094', 'lon' ],
[ 'g', '19.09', 'lon' ],
[ 'g', '19', 'lon' ],
[ 'g', 'u2mwdd8q4' ],
[ 'g', 'u2mwdd8q' ],
[ 'g', 'u2mwdd8' ],
[ 'g', 'u2mwdd' ],
[ 'g', 'u2mwd' ],
[ 'g', 'u2mw' ],
[ 'g', 'u2m' ],
[ 'g', 'u2' ],
[ 'g', 'u' ],
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode' ],
[ 'G', 'countryName' ],
[ 'g', 'Hungary', 'countryName' ],
[ 'G', 'regionCode' ],
[ 'g', 'HU-BU', 'regionCode' ],
[ 'G', 'cityName' ],
[ 'g', 'Budapest', 'cityName' ],
[ 'G', 'planetName' ],
[ 'g', 'Earth', 'planetName' ]
]));
[ 'G', 'dd' ],
[ 'g', '47.5636, 19.0947', 'dd' ],
[ 'G', 'lat' ],
[ 'g', '47.5636', 'lat' ],
[ 'g', '47.563', 'lat' ],
[ 'g', '47.56', 'lat' ],
[ 'g', '47.5', 'lat' ],
[ 'G', 'lon' ],
[ 'g', '19.0947', 'lon' ],
[ 'g', '19.094', 'lon' ],
[ 'g', '19.09', 'lon' ],
[ 'g', '19', 'lon' ],
[ 'G', 'geohash' ],
[ 'g', 'u2mwdd8q4', 'geohash' ],
[ 'g', 'u2mwdd8q', 'geohash' ],
[ 'g', 'u2mwdd8', 'geohash' ],
[ 'g', 'u2mwdd', 'geohash' ],
[ 'g', 'u2mwd', 'geohash' ],
[ 'g', 'u2mw', 'geohash' ],
[ 'g', 'u2m', 'geohash' ],
[ 'g', 'u2', 'geohash' ],
[ 'g', 'u', 'geohash' ],
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode' ],
[ 'G', 'countryName' ],
[ 'g', 'Hungary', 'countryName' ],
[ 'G', 'regionCode' ],
[ 'g', 'HU-BU', 'regionCode' ],
[ 'G', 'cityName' ],
[ 'g', 'Budapest', 'cityName' ],
[ 'G', 'planetName' ],
[ 'g', 'Earth', 'planetName' ]
]));
});


it('null options should produce correct output', () => {
const input: InputData = {
//dedupe: true,
lat: 47.5636,
lon: 19.0947,
cityName: 'Budapest',
Expand All @@ -98,7 +97,6 @@ describe('generateTags()', () => {
};

const options: Options = {
//dedupe: true,
iso31661: true,
iso31662: true,
iso31663: true,
Expand Down Expand Up @@ -131,7 +129,6 @@ describe('generateTags()', () => {

it('should generate tags correctly with all high specificity options enabled', () => {
const input: InputData = {
//dedupe: true,
lat: 47.5636,
lon: 19.0947,
cityName: 'Budapest',
Expand All @@ -144,7 +141,6 @@ describe('generateTags()', () => {
};

const options: Options = {
//dedupe: true,
iso31661: true,
iso31662: true,
iso31663: true,
Expand Down Expand Up @@ -172,12 +168,30 @@ describe('generateTags()', () => {

const result = ngeotags(input, options);
console.log('all high specificity', result.length, result)
expect(result).toHaveLength(33);
expect(result).toHaveLength(34);
})

it('should generate legacy tags when opts.legacy is true', () => {
const input: InputData = {
countryCode: 'HU',
regionName: 'Budapest',
geohash: 'u2mwdd8q4'
};

const options: Options = {
legacy: true
}

const result = ngeotags(input, options);
console.log('legacy', result.length, result)
expect(result).toEqual(expect.arrayContaining([
['g', 'u2mwdd8q4']
]))
// expect(result).toHaveLength(34);
})

it('should generate tags correctly when ISO-3166-1 generated properties are disabled in response', () => {
const input: InputData = {
//dedupe: true,
countryCode: 'HU',
regionName: 'Budapest'
};
Expand All @@ -194,7 +208,6 @@ describe('generateTags()', () => {

it('should generate tags correctly with default options', () => {
const input: InputData = {
//dedupe: true,
lat: 47.5636,
lon: 19.0947,
cityName: 'Budapest',
Expand Down
Loading

0 comments on commit 22725b4

Please sign in to comment.