Skip to content

Commit

Permalink
Updated readme with documentation for new function
Browse files Browse the repository at this point in the history
  • Loading branch information
florianchrometz committed Oct 22, 2023
1 parent b13bddc commit 3623e01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ A js package for easy consumption of german metadata such as phone prefixes and

# Usage

```
npm install german-metadata
```

## City objects

The german meta data package is based on an array that consists of single city objects and a set of functions that allows to query them. Here is a basic city object sample for Frankfurt am Main. If a functions states to return a city object, this is what you will get.
Expand Down Expand Up @@ -34,13 +38,17 @@ const cityForPrefix = germanMetadata.getCityByPhonePrefix(89);
// get the specific number only prefix for a non cleaned phone number
// output will be 69 as number
const prefixForPhoneNumber = germanMetadata.getPrefixOfPhoneNumber('069472111');

// validate if a city name is valid
// output will be true
const isValidCityName = germanMetadata.doesCityExistWithName('Frankfurt am Main');
```

# Functions

## find entries in data

### getCityByPhoneNumber### `getCityByPhoneNumber(phonenumber)` -> `Object:City`
### `getCityByPhoneNumber(phonenumber)` -> `Object:City`

This function takes a phone number as input and returns the corresponding city object. The input phone number is normalized before the lookup.

Expand All @@ -56,6 +64,10 @@ This function takes a city name as input and returns the phone prefix (area code

This function takes a phone number as input and returns the phone prefix (area code) of that phone number. The input phone number is normalized before the lookup.

### `doesCityExistWithName(cityname)` -> `Boolean`

This function takes a city name as input and returns true if the city exists in the data set. The input city name is normalized before the lookup.

## Helper Functions

### `normalizeCityName(cityname)` -> Returns string representing a normalized city name
Expand All @@ -77,22 +89,26 @@ Every character that is not `0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9` as well as l
- `normalizePhoneNumber("07171492482")` -> `7171492482`
- `normalizePhoneNumber("0049671-492482#433,222")` -> `671492482433222`

### `rawCityArray()` -> `[{...}]`
### `cities` -> `[{...}]`

This allows direct access to the data that is used by this package and returns the contents of `cities.json` which represents an array of cities.

```const germanCities = geme.rawCityArray()
```

# Licensing Information

Make sure to apply propper attribution when using this package in public facing projects. As this project is using data from OpenStreetMap and German GovData Portal, the following licensing information applies:

## Project Code License

As per the terms of this project's license, the project code is released under the MIT License. You can find the full text of the MIT License in the `LICENSE` file within this repository.

## Attribution to OpenStreetMap

A significant portion of the data in this package is based on the Open Database License (ODbL) as provided by OpenStreetMap.
This package is using data provided by OpenStreetMap based on the Open Database License (ODbL).

- OpenStreetMap: [https://www.openstreetmap.org](https://www.openstreetmap.org)

## Attribution to GovData

This package is using data provided by GovData based on the German Data License (dl-de-by-2.0).

- GovData: [https://www.govdata.de](https://www.govdata.de)
1 change: 0 additions & 1 deletion german-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function getPhonePrefixByCityName(cityname) {
function getPrefixOfPhoneNumber(phonenumber) {
const normalizedNumber = normalizePhoneNumber(phonenumber);
const prefixLengths = [5, 4, 3, 2];

for (const length of prefixLengths) {
const prefix = Number(normalizedNumber.substring(0, length));
const city = cities.find((p) => p.prefix === prefix);
Expand Down

0 comments on commit 3623e01

Please sign in to comment.