Skip to content

Commit

Permalink
remove numeric, has collisions with geohash
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Feb 14, 2024
1 parent 4bd8c69 commit bb4be8a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ Which tags you use depend on use-case. If your concerns are namely geospacial, u
- **`isoAsNamespace==false [default]`**
- Alpha-2 code: `[ 'g', 'HU', 'countryCode' ]`
- Alpha-3 code: `[ 'g', 'HUN', 'countryCode']`
- Numeric code: `[ 'g', '348', 'countryCode' ]`
- **`isoAsNamespace==true`**
- Alpha-2 code: `[ 'g', 'HU', 'ISO-3166-1' ]`
- Alpha-3 code: `[ 'g', 'HUN', 'ISO-3166-1']`
- Numeric code: `[ 'g', '348', 'ISO-3166-1' ]`

4. **ISO-3166-2 Codes**:
- These tags represent region information derived from the `iso-3166` library and are based on the `countryCode` and `regionCode` input values. They are not passthrough values.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nostr-geotags",
"version": "0.4.1",
"version": "0.5.0",
"description": "Give an object of geodata, returns standardized nostr geotags ",
"type": "module",
"main": "dist/index.js",
Expand Down
13 changes: 1 addition & 12 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ describe('generateTags()', () => {
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode' ],
[ 'G', 'countryName' ],
[ 'g', 'Hungary', 'countryName' ],
[ 'G', 'regionCode' ],
Expand Down Expand Up @@ -168,7 +167,7 @@ describe('generateTags()', () => {

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

it('should generate legacy tags when opts.legacy is true', () => {
Expand Down Expand Up @@ -245,7 +244,6 @@ describe('generateTags()', () => {
[ 'g', '19', 'lon' ],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode' ],
[ 'g', 'Hungary', 'countryName' ],
[ 'g', 'HU-BU', 'regionCode' ]
])
Expand All @@ -270,7 +268,6 @@ describe('generateTags()', () => {
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode'],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode' ],
[ 'G', 'countryName' ],
[ 'g', 'Hungary', 'countryName' ],
[ 'G', 'regionCode' ],
Expand Down Expand Up @@ -454,7 +451,6 @@ describe('generateTags()', () => {
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode'],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode' ],
[ 'G', 'countryName' ],
[ 'g', 'Hungary', 'countryName' ]
]));
Expand Down Expand Up @@ -507,7 +503,6 @@ describe('generateTags()', () => {
[ 'G', 'countryCode' ],
[ 'g', 'AI', 'countryCode'],
[ 'g', 'AIA', 'countryCode' ],
[ 'g', '660', 'countryCode' ],
[ 'G', 'countryName' ],
[ 'g', 'Anguilla', 'countryName' ],
[ 'G', 'countryCode' ],
Expand Down Expand Up @@ -535,7 +530,6 @@ describe('generateTags()', () => {
['G', 'countryCode'],
[ 'g', 'DE', 'countryCode' ],
[ 'g', 'DEU', 'countryCode' ],
[ 'g', '276', 'countryCode' ],
]))
});

Expand Down Expand Up @@ -585,7 +579,6 @@ describe('generateTags()', () => {
['G', 'countryCode'],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode' ],
[ 'G', 'countryName' ],
[ 'g', 'Hungary', 'countryName' ]
]))
Expand Down Expand Up @@ -674,7 +667,6 @@ describe('namespace inflection', () => {
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode'],
[ 'G', 'countryName' ],
[ 'g', 'Hungary', 'countryName' ]
]));
Expand Down Expand Up @@ -753,7 +745,6 @@ describe('sortTagsByKey()', () => {
[ 'g', 'HU', 'countryCode'],
[ 'G', 'countryCode' ],
[ 'g', 'HUN', 'countryCode' ],
[ 'g', '348', 'countryCode' ]
];

console.log('before sort', tags)
Expand All @@ -764,7 +755,6 @@ describe('sortTagsByKey()', () => {
[ 'G', 'countryCode' ],
[ 'g', 'HU', 'countryCode' ],
[ 'g', 'HUN', 'countryCode'],
[ 'g', '348', 'countryCode' ]
]);
});
})
Expand All @@ -774,7 +764,6 @@ describe('filterOutType()', () => {
const tags: GeoTags[] = [
['g', 'HU', 'countryCode'],
['g', 'HUN', 'countryCode'],
['g', '348', 'countryCode'],
['g', 'HU-BU', 'regionCode']
];

Expand Down
9 changes: 4 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const DD_MAX_RES_DEFAULT = 9
/**
* Retrieves updated ISO-3166-3 values based on a given code.
*
* @param {ISO31663FieldType} type - The type of the ISO-3166-3 field (alpha2, alpha3, numeric, name).
* @param {ISO31663FieldType} type - The type of the ISO-3166-3 field (alpha2, alpha3, name).
* @param {string} code - The ISO-3166-3 code to find updated values for.
* @returns {string[]} An array of updated ISO-3166-3 values.
*
Expand Down Expand Up @@ -227,7 +227,6 @@ const generateTags = (input: InputData, opts: Options): GeoTags[] => {
if (countryData) {
iso31661Tags.push(['g', countryData.alpha2, namespace]);
iso31661Tags.push(['g', countryData.alpha3, namespace]);
iso31661Tags.push(['g', countryData.numeric, namespace]);
if(countryData.name) {
iso31661Tags.push(['G', 'countryName']);
iso31661Tags.push(['g', countryData.name, 'countryName']);
Expand Down Expand Up @@ -261,7 +260,7 @@ const generateTags = (input: InputData, opts: Options): GeoTags[] => {
const iso31663Tags: LabelTag[] = [];

// Iterate over all types and check for updated values
(['alpha2', 'alpha3', 'numeric', 'name'] as const).forEach(type => {
(['alpha2', 'alpha3', 'name'] as const).forEach(type => {

const originalValue = countryData[type as keyof ISO31661Entry];
const updatedValues = getUpdatedIso31663Values(type, originalValue);
Expand All @@ -281,12 +280,12 @@ const generateTags = (input: InputData, opts: Options): GeoTags[] => {
}
}

if ((opts.city || opts.cityName) && input.cityName && !opts.legacy) {
if ((opts.city || opts.cityName) && input.cityName) {
tags.push(['G', 'cityName']);
tags.push(['g', input.cityName, 'cityName']);
}

if ((opts.planet || opts.planetName) && input.planetName && !opts.legacy) {
if ((opts.planet || opts.planetName) && input.planetName) {
tags.push(['G', 'planetName']);
tags.push(['g', input.planetName, 'planetName']);
}
Expand Down

0 comments on commit bb4be8a

Please sign in to comment.