@aprestmo/norway-geodata 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,7 +46,7 @@ export declare function getCountyById(id: string): County | undefined;
46
46
  export declare function getCountyByName(name: string, exactMatch?: boolean): County | undefined;
47
47
  /**
48
48
  * Get all municipalities in a given county.
49
- * @param countyId - 2-digit county ID (first two digits of municipality k_id)
49
+ * @param countyId - 2-digit county ID (first two digits of municipality id)
50
50
  * @returns Array of municipalities in the county
51
51
  * @throws {TypeError} If countyId is not a string
52
52
  */
@@ -70,7 +70,7 @@ export declare function getPostalCodesByMunicipality(municipalityId: string): re
70
70
  * @returns Array of postal codes or postal code objects
71
71
  */
72
72
  export declare function getAllPostalCodes(includeDetails?: boolean): readonly string[] | readonly {
73
- zip: string;
73
+ code: string;
74
74
  place: string;
75
75
  municipalityId: string;
76
76
  municipalityName: string;
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import municipalitiesData from '../data/kommuner-2025.json';
2
- import countiesData from '../data/fylker-2025.json';
1
+ import municipalitiesData from '../data/municipalities-2025.json';
2
+ import countiesData from '../data/counties-2025.json';
3
3
  import postalCodesData from '../data/postal-codes-2025.json';
4
4
  import packageJson from '../package.json';
5
5
  // Type-safe data imports
@@ -30,7 +30,7 @@ export function getMunicipalityById(id) {
30
30
  if (typeof id !== 'string') {
31
31
  throw new TypeError('Municipality ID must be a string');
32
32
  }
33
- return municipalities.find(m => m.k_id === id);
33
+ return municipalities.find(m => m.id === id);
34
34
  }
35
35
  /**
36
36
  * Get municipalities by name (case-insensitive partial match by default).
@@ -47,8 +47,8 @@ export function getMunicipalitiesByName(name, options = {}) {
47
47
  const searchTerm = caseSensitive ? name : name.toLowerCase();
48
48
  return municipalities.filter(m => {
49
49
  const namesToSearch = includeAllNames
50
- ? [m.k_name, m.k_name_no]
51
- : [m.k_name];
50
+ ? [m.name, m.name_no]
51
+ : [m.name];
52
52
  return namesToSearch.some(municipalityName => {
53
53
  const compareString = caseSensitive
54
54
  ? municipalityName
@@ -76,7 +76,7 @@ export function getCountyById(id) {
76
76
  if (typeof id !== 'string') {
77
77
  throw new TypeError('County ID must be a string');
78
78
  }
79
- return counties.find(f => f.f_id === id);
79
+ return counties.find(f => f.id === id);
80
80
  }
81
81
  /**
82
82
  * Get county by name (case-insensitive partial match).
@@ -91,13 +91,13 @@ export function getCountyByName(name, exactMatch = false) {
91
91
  }
92
92
  const searchTerm = name.toLowerCase();
93
93
  return counties.find(f => {
94
- const countyName = f.f_name.toLowerCase();
94
+ const countyName = f.name.toLowerCase();
95
95
  return exactMatch ? countyName === searchTerm : countyName.includes(searchTerm);
96
96
  });
97
97
  }
98
98
  /**
99
99
  * Get all municipalities in a given county.
100
- * @param countyId - 2-digit county ID (first two digits of municipality k_id)
100
+ * @param countyId - 2-digit county ID (first two digits of municipality id)
101
101
  * @returns Array of municipalities in the county
102
102
  * @throws {TypeError} If countyId is not a string
103
103
  */
@@ -105,7 +105,7 @@ export function getMunicipalitiesByCounty(countyId) {
105
105
  if (typeof countyId !== 'string') {
106
106
  throw new TypeError('County ID must be a string');
107
107
  }
108
- return municipalities.filter(m => m.k_id.startsWith(countyId));
108
+ return municipalities.filter(m => m.id.startsWith(countyId));
109
109
  }
110
110
  /**
111
111
  * Get municipality by postal code.
@@ -118,7 +118,7 @@ export function getMunicipalityByPostalCode(postalCode) {
118
118
  if (!code.match(/^\d{4}$/)) {
119
119
  throw new TypeError('Postal code must be a valid 4-digit number');
120
120
  }
121
- return municipalities.find(m => m.k_postal_codes.some(pc => pc.postal_code === code));
121
+ return municipalities.find(m => m.postal_codes.some(pc => pc.code === code));
122
122
  }
123
123
  /**
124
124
  * Get all postal codes for a specific municipality.
@@ -127,7 +127,7 @@ export function getMunicipalityByPostalCode(postalCode) {
127
127
  */
128
128
  export function getPostalCodesByMunicipality(municipalityId) {
129
129
  const municipality = getMunicipalityById(municipalityId);
130
- return municipality ? municipality.k_postal_codes.map(pc => pc.postal_code) : undefined;
130
+ return municipality ? municipality.postal_codes.map(pc => pc.code) : undefined;
131
131
  }
132
132
  /**
133
133
  * Get all postal codes from all municipalities.
@@ -138,22 +138,22 @@ export function getAllPostalCodes(includeDetails = false) {
138
138
  if (includeDetails) {
139
139
  const allPostalCodes = [];
140
140
  municipalities.forEach(municipality => {
141
- municipality.k_postal_codes.forEach(pc => {
141
+ municipality.postal_codes.forEach(pc => {
142
142
  allPostalCodes.push({
143
- zip: pc.postal_code,
144
- place: pc.postal_place,
145
- municipalityId: municipality.k_id,
146
- municipalityName: municipality.k_name
143
+ code: pc.code,
144
+ place: pc.place,
145
+ municipalityId: municipality.id,
146
+ municipalityName: municipality.name
147
147
  });
148
148
  });
149
149
  });
150
- return allPostalCodes.sort((a, b) => a.zip.localeCompare(b.zip));
150
+ return allPostalCodes.sort((a, b) => a.code.localeCompare(b.code));
151
151
  }
152
152
  else {
153
153
  const allPostalCodes = new Set();
154
154
  municipalities.forEach(municipality => {
155
- municipality.k_postal_codes.forEach(pc => {
156
- allPostalCodes.add(pc.postal_code);
155
+ municipality.postal_codes.forEach(pc => {
156
+ allPostalCodes.add(pc.code);
157
157
  });
158
158
  });
159
159
  return Array.from(allPostalCodes).sort();
@@ -165,7 +165,7 @@ export function getAllPostalCodes(includeDetails = false) {
165
165
  * @returns Array of municipalities sorted by population
166
166
  */
167
167
  export function getMunicipalitiesByPopulation(ascending = false) {
168
- const sorted = [...municipalities].sort((a, b) => ascending ? a.k_population - b.k_population : b.k_population - a.k_population);
168
+ const sorted = [...municipalities].sort((a, b) => ascending ? a.population - b.population : b.population - a.population);
169
169
  return sorted;
170
170
  }
171
171
  /**
@@ -174,7 +174,7 @@ export function getMunicipalitiesByPopulation(ascending = false) {
174
174
  * @returns Array of municipalities sorted by area
175
175
  */
176
176
  export function getMunicipalitiesByArea(ascending = false) {
177
- const sorted = [...municipalities].sort((a, b) => ascending ? a.k_area - b.k_area : b.k_area - a.k_area);
177
+ const sorted = [...municipalities].sort((a, b) => ascending ? a.area - b.area : b.area - a.area);
178
178
  return sorted;
179
179
  }
180
180
  /**
@@ -187,7 +187,7 @@ export function getMunicipalitiesByLanguage(language) {
187
187
  if (typeof language !== 'string') {
188
188
  throw new TypeError('Language must be a string');
189
189
  }
190
- return municipalities.filter(m => m.k_language === language);
190
+ return municipalities.filter(m => m.language === language);
191
191
  }
192
192
  /**
193
193
  * Get municipalities with advanced filtering options.
@@ -196,17 +196,17 @@ export function getMunicipalitiesByLanguage(language) {
196
196
  */
197
197
  export function getMunicipalitiesFiltered(options) {
198
198
  return municipalities.filter(m => {
199
- if (options.minPopulation !== undefined && m.k_population < options.minPopulation)
199
+ if (options.minPopulation !== undefined && m.population < options.minPopulation)
200
200
  return false;
201
- if (options.maxPopulation !== undefined && m.k_population > options.maxPopulation)
201
+ if (options.maxPopulation !== undefined && m.population > options.maxPopulation)
202
202
  return false;
203
- if (options.minArea !== undefined && m.k_area < options.minArea)
203
+ if (options.minArea !== undefined && m.area < options.minArea)
204
204
  return false;
205
- if (options.maxArea !== undefined && m.k_area > options.maxArea)
205
+ if (options.maxArea !== undefined && m.area > options.maxArea)
206
206
  return false;
207
- if (options.language !== undefined && m.k_language !== options.language)
207
+ if (options.language !== undefined && m.language !== options.language)
208
208
  return false;
209
- if (options.countyId !== undefined && !m.k_id.startsWith(options.countyId))
209
+ if (options.countyId !== undefined && !m.id.startsWith(options.countyId))
210
210
  return false;
211
211
  return true;
212
212
  });
@@ -216,21 +216,21 @@ export function getMunicipalitiesFiltered(options) {
216
216
  * @returns Total population
217
217
  */
218
218
  export function getTotalPopulation() {
219
- return municipalities.reduce((total, m) => total + m.k_population, 0);
219
+ return municipalities.reduce((total, m) => total + m.population, 0);
220
220
  }
221
221
  /**
222
222
  * Get total area of all municipalities.
223
223
  * @returns Total area in square kilometers
224
224
  */
225
225
  export function getTotalArea() {
226
- return municipalities.reduce((total, m) => total + m.k_area, 0);
226
+ return municipalities.reduce((total, m) => total + m.area, 0);
227
227
  }
228
228
  /**
229
229
  * Get population density statistics.
230
230
  * @returns Object with min, max, and average population density
231
231
  */
232
232
  export function getPopulationDensityStats() {
233
- const densities = municipalities.map(m => m.k_population / m.k_area);
233
+ const densities = municipalities.map(m => m.population / m.area);
234
234
  return {
235
235
  min: Math.min(...densities),
236
236
  max: Math.max(...densities),
@@ -245,7 +245,7 @@ export function getPopulationDensityStats() {
245
245
  */
246
246
  export function getMunicipalitiesByPopulationDensity(minDensity = 0, maxDensity = Infinity) {
247
247
  return municipalities.filter(m => {
248
- const density = m.k_population / m.k_area;
248
+ const density = m.population / m.area;
249
249
  return density >= minDensity && density <= maxDensity;
250
250
  });
251
251
  }
@@ -285,7 +285,7 @@ export function getPostalCodeByCode(code) {
285
285
  if (typeof code !== 'string') {
286
286
  throw new TypeError('Postal code must be a string');
287
287
  }
288
- return postalCodes.find(pc => pc.k_postal_code === code);
288
+ return postalCodes.find(pc => pc.code === code);
289
289
  }
290
290
  /**
291
291
  * Get postal codes by postal place (case-insensitive partial match by default).
@@ -302,8 +302,8 @@ export function getPostalCodesByPlace(place, options = {}) {
302
302
  const searchTerm = caseSensitive ? place : place.toLowerCase();
303
303
  return postalCodes.filter(pc => {
304
304
  const placeName = caseSensitive
305
- ? pc.k_postal_place
306
- : pc.k_postal_place.toLowerCase();
305
+ ? pc.place
306
+ : pc.place.toLowerCase();
307
307
  return exactMatch
308
308
  ? placeName === searchTerm
309
309
  : placeName.includes(searchTerm);
@@ -319,7 +319,7 @@ export function getPostalCodesByMunicipalityId(municipalityId) {
319
319
  if (typeof municipalityId !== 'string') {
320
320
  throw new TypeError('Municipality ID must be a string');
321
321
  }
322
- return postalCodes.filter(pc => pc.k_id === municipalityId);
322
+ return postalCodes.filter(pc => pc.id === municipalityId);
323
323
  }
324
324
  /**
325
325
  * Get unique postal places.
@@ -327,7 +327,7 @@ export function getPostalCodesByMunicipalityId(municipalityId) {
327
327
  */
328
328
  export function getUniquePostalPlaces() {
329
329
  const uniquePlaces = new Set();
330
- postalCodes.forEach(pc => uniquePlaces.add(pc.k_postal_place));
330
+ postalCodes.forEach(pc => uniquePlaces.add(pc.place));
331
331
  return Array.from(uniquePlaces).sort();
332
332
  }
333
333
  /**
@@ -341,7 +341,7 @@ export function getPostalCodesInRange(startCode, endCode) {
341
341
  if (typeof startCode !== 'string' || typeof endCode !== 'string') {
342
342
  throw new TypeError('Start and end codes must be strings');
343
343
  }
344
- return postalCodes.filter(pc => pc.k_postal_code >= startCode && pc.k_postal_code <= endCode);
344
+ return postalCodes.filter(pc => pc.code >= startCode && pc.code <= endCode);
345
345
  }
346
346
  /**
347
347
  * Get postal codes statistics.
@@ -351,8 +351,8 @@ export function getPostalCodesStats() {
351
351
  const uniquePlaces = new Set();
352
352
  const uniqueMunicipalities = new Set();
353
353
  postalCodes.forEach(pc => {
354
- uniquePlaces.add(pc.k_postal_place);
355
- uniqueMunicipalities.add(pc.k_id);
354
+ uniquePlaces.add(pc.place);
355
+ uniqueMunicipalities.add(pc.id);
356
356
  });
357
357
  return {
358
358
  totalPostalCodes: postalCodes.length,
@@ -367,8 +367,8 @@ export function getPostalCodesStats() {
367
367
  */
368
368
  export function getPostalCodesSorted(ascending = true) {
369
369
  const sorted = [...postalCodes].sort((a, b) => ascending
370
- ? a.k_postal_code.localeCompare(b.k_postal_code)
371
- : b.k_postal_code.localeCompare(a.k_postal_code));
370
+ ? a.code.localeCompare(b.code)
371
+ : b.code.localeCompare(a.code));
372
372
  return sorted;
373
373
  }
374
374
  /**
@@ -380,7 +380,7 @@ export function isValidPostalCode(code) {
380
380
  if (typeof code !== 'string') {
381
381
  return false;
382
382
  }
383
- return postalCodes.some(pc => pc.k_postal_code === code);
383
+ return postalCodes.some(pc => pc.code === code);
384
384
  }
385
385
  /**
386
386
  * Get postal codes by municipality name.
@@ -391,7 +391,7 @@ export function isValidPostalCode(code) {
391
391
  */
392
392
  export function getPostalCodesByMunicipalityName(municipalityName, exactMatch = false) {
393
393
  const matchingMunicipalities = getMunicipalitiesByName(municipalityName, { exactMatch });
394
- const municipalityIds = matchingMunicipalities.map(m => m.k_id);
395
- return postalCodes.filter(pc => municipalityIds.includes(pc.k_id));
394
+ const municipalityIds = matchingMunicipalities.map(m => m.id);
395
+ return postalCodes.filter(pc => municipalityIds.includes(pc.id));
396
396
  }
397
397
  //# sourceMappingURL=index.js.map
@@ -1,33 +1,33 @@
1
1
  /**
2
2
  * Language status for Norwegian municipalities
3
3
  */
4
- export type LanguageStatus = 'Nøytral' | 'Bokmål' | 'Nynorsk' | 'Sami' | 'Kvensk';
4
+ export type LanguageStatus = 'Nøytral' | 'Bokmål' | 'Nynorsk';
5
5
  /**
6
6
  * Municipality (Kommune) data structure
7
7
  */
8
8
  export interface Municipality {
9
9
  /** 4-digit municipality ID */
10
- readonly k_id: string;
10
+ readonly id: string;
11
11
  /** Municipality name */
12
- readonly k_name: string;
12
+ readonly name: string;
13
13
  /** Municipality name in Norwegian */
14
- readonly k_name_no: string;
14
+ readonly name_no: string;
15
15
  /** Administrative center */
16
- readonly k_adm_center: string;
16
+ readonly adm_center: string;
17
17
  /** Population count */
18
- readonly k_population: number;
18
+ readonly population: number;
19
19
  /** Area in square kilometers */
20
- readonly k_area: number;
20
+ readonly area: number;
21
21
  /** Official language status */
22
- readonly k_language: LanguageStatus;
22
+ readonly language: LanguageStatus;
23
23
  /** Official website URL */
24
- readonly k_url: string;
24
+ readonly url: string;
25
25
  /** Array of postal codes with place names */
26
- readonly k_postal_codes: readonly {
26
+ readonly postal_codes: readonly {
27
27
  /** 4-digit postal code */
28
- readonly postal_code: string;
28
+ readonly code: string;
29
29
  /** Place name */
30
- readonly postal_place: string;
30
+ readonly place: string;
31
31
  }[];
32
32
  }
33
33
  /**
@@ -35,11 +35,11 @@ export interface Municipality {
35
35
  */
36
36
  export interface County {
37
37
  /** 2-digit county ID */
38
- readonly f_id: string;
38
+ readonly id: string;
39
39
  /** County name */
40
- readonly f_name: string;
40
+ readonly name: string;
41
41
  /** Official website URL */
42
- readonly f_url: string;
42
+ readonly url: string;
43
43
  }
44
44
  /**
45
45
  * Population density statistics
@@ -93,11 +93,11 @@ export interface MunicipalityFilterOptions {
93
93
  */
94
94
  export interface PostalCode {
95
95
  /** 4-digit postal code */
96
- readonly k_postal_code: string;
96
+ readonly code: string;
97
97
  /** Postal place name */
98
- readonly k_postal_place: string;
98
+ readonly place: string;
99
99
  /** 4-digit municipality ID */
100
- readonly k_id: string;
100
+ readonly id: string;
101
101
  }
102
102
  /**
103
103
  * Search options for postal codes
package/dist/index.d.ts CHANGED
@@ -46,7 +46,7 @@ export declare function getCountyById(id: string): County | undefined;
46
46
  export declare function getCountyByName(name: string, exactMatch?: boolean): County | undefined;
47
47
  /**
48
48
  * Get all municipalities in a given county.
49
- * @param countyId - 2-digit county ID (first two digits of municipality k_id)
49
+ * @param countyId - 2-digit county ID (first two digits of municipality id)
50
50
  * @returns Array of municipalities in the county
51
51
  * @throws {TypeError} If countyId is not a string
52
52
  */
@@ -70,7 +70,7 @@ export declare function getPostalCodesByMunicipality(municipalityId: string): re
70
70
  * @returns Array of postal codes or postal code objects
71
71
  */
72
72
  export declare function getAllPostalCodes(includeDetails?: boolean): readonly string[] | readonly {
73
- zip: string;
73
+ code: string;
74
74
  place: string;
75
75
  municipalityId: string;
76
76
  municipalityName: string;