@aprestmo/norway-geodata 0.1.0 → 0.1.4

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.
package/dist/index.js CHANGED
@@ -34,13 +34,13 @@ exports.getPostalCodesStats = getPostalCodesStats;
34
34
  exports.getPostalCodesSorted = getPostalCodesSorted;
35
35
  exports.isValidPostalCode = isValidPostalCode;
36
36
  exports.getPostalCodesByMunicipalityName = getPostalCodesByMunicipalityName;
37
- const kommuner_2025_json_1 = __importDefault(require("../data/kommuner-2025.json"));
38
- const fylker_2025_json_1 = __importDefault(require("../data/fylker-2025.json"));
37
+ const municipalities_2025_json_1 = __importDefault(require("../data/municipalities-2025.json"));
38
+ const counties_2025_json_1 = __importDefault(require("../data/counties-2025.json"));
39
39
  const postal_codes_2025_json_1 = __importDefault(require("../data/postal-codes-2025.json"));
40
40
  const package_json_1 = __importDefault(require("../package.json"));
41
41
  // Type-safe data imports
42
- const municipalities = kommuner_2025_json_1.default;
43
- const counties = fylker_2025_json_1.default;
42
+ const municipalities = municipalities_2025_json_1.default;
43
+ const counties = counties_2025_json_1.default;
44
44
  const postalCodes = postal_codes_2025_json_1.default;
45
45
  /**
46
46
  * Get the library version following semantic versioning.
@@ -66,7 +66,7 @@ function getMunicipalityById(id) {
66
66
  if (typeof id !== 'string') {
67
67
  throw new TypeError('Municipality ID must be a string');
68
68
  }
69
- return municipalities.find(m => m.k_id === id);
69
+ return municipalities.find(m => m.id === id);
70
70
  }
71
71
  /**
72
72
  * Get municipalities by name (case-insensitive partial match by default).
@@ -83,8 +83,8 @@ function getMunicipalitiesByName(name, options = {}) {
83
83
  const searchTerm = caseSensitive ? name : name.toLowerCase();
84
84
  return municipalities.filter(m => {
85
85
  const namesToSearch = includeAllNames
86
- ? [m.k_name, m.k_name_no]
87
- : [m.k_name];
86
+ ? [m.name, m.name_no]
87
+ : [m.name];
88
88
  return namesToSearch.some(municipalityName => {
89
89
  const compareString = caseSensitive
90
90
  ? municipalityName
@@ -112,7 +112,7 @@ function getCountyById(id) {
112
112
  if (typeof id !== 'string') {
113
113
  throw new TypeError('County ID must be a string');
114
114
  }
115
- return counties.find(f => f.f_id === id);
115
+ return counties.find(f => f.id === id);
116
116
  }
117
117
  /**
118
118
  * Get county by name (case-insensitive partial match).
@@ -127,13 +127,13 @@ function getCountyByName(name, exactMatch = false) {
127
127
  }
128
128
  const searchTerm = name.toLowerCase();
129
129
  return counties.find(f => {
130
- const countyName = f.f_name.toLowerCase();
130
+ const countyName = f.name.toLowerCase();
131
131
  return exactMatch ? countyName === searchTerm : countyName.includes(searchTerm);
132
132
  });
133
133
  }
134
134
  /**
135
135
  * Get all municipalities in a given county.
136
- * @param countyId - 2-digit county ID (first two digits of municipality k_id)
136
+ * @param countyId - 2-digit county ID (first two digits of municipality id)
137
137
  * @returns Array of municipalities in the county
138
138
  * @throws {TypeError} If countyId is not a string
139
139
  */
@@ -141,7 +141,7 @@ function getMunicipalitiesByCounty(countyId) {
141
141
  if (typeof countyId !== 'string') {
142
142
  throw new TypeError('County ID must be a string');
143
143
  }
144
- return municipalities.filter(m => m.k_id.startsWith(countyId));
144
+ return municipalities.filter(m => m.id.startsWith(countyId));
145
145
  }
146
146
  /**
147
147
  * Get municipality by postal code.
@@ -154,7 +154,7 @@ function getMunicipalityByPostalCode(postalCode) {
154
154
  if (!code.match(/^\d{4}$/)) {
155
155
  throw new TypeError('Postal code must be a valid 4-digit number');
156
156
  }
157
- return municipalities.find(m => m.k_postal_codes.some(pc => pc.postal_code === code));
157
+ return municipalities.find(m => m.postal_codes.some(pc => pc.code === code));
158
158
  }
159
159
  /**
160
160
  * Get all postal codes for a specific municipality.
@@ -163,7 +163,7 @@ function getMunicipalityByPostalCode(postalCode) {
163
163
  */
164
164
  function getPostalCodesByMunicipality(municipalityId) {
165
165
  const municipality = getMunicipalityById(municipalityId);
166
- return municipality ? municipality.k_postal_codes.map(pc => pc.postal_code) : undefined;
166
+ return municipality ? municipality.postal_codes.map(pc => pc.code) : undefined;
167
167
  }
168
168
  /**
169
169
  * Get all postal codes from all municipalities.
@@ -174,22 +174,22 @@ function getAllPostalCodes(includeDetails = false) {
174
174
  if (includeDetails) {
175
175
  const allPostalCodes = [];
176
176
  municipalities.forEach(municipality => {
177
- municipality.k_postal_codes.forEach(pc => {
177
+ municipality.postal_codes.forEach(pc => {
178
178
  allPostalCodes.push({
179
- zip: pc.postal_code,
180
- place: pc.postal_place,
181
- municipalityId: municipality.k_id,
182
- municipalityName: municipality.k_name
179
+ code: pc.code,
180
+ place: pc.place,
181
+ municipalityId: municipality.id,
182
+ municipalityName: municipality.name
183
183
  });
184
184
  });
185
185
  });
186
- return allPostalCodes.sort((a, b) => a.zip.localeCompare(b.zip));
186
+ return allPostalCodes.sort((a, b) => a.code.localeCompare(b.code));
187
187
  }
188
188
  else {
189
189
  const allPostalCodes = new Set();
190
190
  municipalities.forEach(municipality => {
191
- municipality.k_postal_codes.forEach(pc => {
192
- allPostalCodes.add(pc.postal_code);
191
+ municipality.postal_codes.forEach(pc => {
192
+ allPostalCodes.add(pc.code);
193
193
  });
194
194
  });
195
195
  return Array.from(allPostalCodes).sort();
@@ -201,7 +201,7 @@ function getAllPostalCodes(includeDetails = false) {
201
201
  * @returns Array of municipalities sorted by population
202
202
  */
203
203
  function getMunicipalitiesByPopulation(ascending = false) {
204
- const sorted = [...municipalities].sort((a, b) => ascending ? a.k_population - b.k_population : b.k_population - a.k_population);
204
+ const sorted = [...municipalities].sort((a, b) => ascending ? a.population - b.population : b.population - a.population);
205
205
  return sorted;
206
206
  }
207
207
  /**
@@ -210,7 +210,7 @@ function getMunicipalitiesByPopulation(ascending = false) {
210
210
  * @returns Array of municipalities sorted by area
211
211
  */
212
212
  function getMunicipalitiesByArea(ascending = false) {
213
- const sorted = [...municipalities].sort((a, b) => ascending ? a.k_area - b.k_area : b.k_area - a.k_area);
213
+ const sorted = [...municipalities].sort((a, b) => ascending ? a.area - b.area : b.area - a.area);
214
214
  return sorted;
215
215
  }
216
216
  /**
@@ -223,7 +223,7 @@ function getMunicipalitiesByLanguage(language) {
223
223
  if (typeof language !== 'string') {
224
224
  throw new TypeError('Language must be a string');
225
225
  }
226
- return municipalities.filter(m => m.k_language === language);
226
+ return municipalities.filter(m => m.language === language);
227
227
  }
228
228
  /**
229
229
  * Get municipalities with advanced filtering options.
@@ -232,17 +232,17 @@ function getMunicipalitiesByLanguage(language) {
232
232
  */
233
233
  function getMunicipalitiesFiltered(options) {
234
234
  return municipalities.filter(m => {
235
- if (options.minPopulation !== undefined && m.k_population < options.minPopulation)
235
+ if (options.minPopulation !== undefined && m.population < options.minPopulation)
236
236
  return false;
237
- if (options.maxPopulation !== undefined && m.k_population > options.maxPopulation)
237
+ if (options.maxPopulation !== undefined && m.population > options.maxPopulation)
238
238
  return false;
239
- if (options.minArea !== undefined && m.k_area < options.minArea)
239
+ if (options.minArea !== undefined && m.area < options.minArea)
240
240
  return false;
241
- if (options.maxArea !== undefined && m.k_area > options.maxArea)
241
+ if (options.maxArea !== undefined && m.area > options.maxArea)
242
242
  return false;
243
- if (options.language !== undefined && m.k_language !== options.language)
243
+ if (options.language !== undefined && m.language !== options.language)
244
244
  return false;
245
- if (options.countyId !== undefined && !m.k_id.startsWith(options.countyId))
245
+ if (options.countyId !== undefined && !m.id.startsWith(options.countyId))
246
246
  return false;
247
247
  return true;
248
248
  });
@@ -252,21 +252,21 @@ function getMunicipalitiesFiltered(options) {
252
252
  * @returns Total population
253
253
  */
254
254
  function getTotalPopulation() {
255
- return municipalities.reduce((total, m) => total + m.k_population, 0);
255
+ return municipalities.reduce((total, m) => total + m.population, 0);
256
256
  }
257
257
  /**
258
258
  * Get total area of all municipalities.
259
259
  * @returns Total area in square kilometers
260
260
  */
261
261
  function getTotalArea() {
262
- return municipalities.reduce((total, m) => total + m.k_area, 0);
262
+ return municipalities.reduce((total, m) => total + m.area, 0);
263
263
  }
264
264
  /**
265
265
  * Get population density statistics.
266
266
  * @returns Object with min, max, and average population density
267
267
  */
268
268
  function getPopulationDensityStats() {
269
- const densities = municipalities.map(m => m.k_population / m.k_area);
269
+ const densities = municipalities.map(m => m.population / m.area);
270
270
  return {
271
271
  min: Math.min(...densities),
272
272
  max: Math.max(...densities),
@@ -281,7 +281,7 @@ function getPopulationDensityStats() {
281
281
  */
282
282
  function getMunicipalitiesByPopulationDensity(minDensity = 0, maxDensity = Infinity) {
283
283
  return municipalities.filter(m => {
284
- const density = m.k_population / m.k_area;
284
+ const density = m.population / m.area;
285
285
  return density >= minDensity && density <= maxDensity;
286
286
  });
287
287
  }
@@ -321,7 +321,7 @@ function getPostalCodeByCode(code) {
321
321
  if (typeof code !== 'string') {
322
322
  throw new TypeError('Postal code must be a string');
323
323
  }
324
- return postalCodes.find(pc => pc.k_postal_code === code);
324
+ return postalCodes.find(pc => pc.code === code);
325
325
  }
326
326
  /**
327
327
  * Get postal codes by postal place (case-insensitive partial match by default).
@@ -338,8 +338,8 @@ function getPostalCodesByPlace(place, options = {}) {
338
338
  const searchTerm = caseSensitive ? place : place.toLowerCase();
339
339
  return postalCodes.filter(pc => {
340
340
  const placeName = caseSensitive
341
- ? pc.k_postal_place
342
- : pc.k_postal_place.toLowerCase();
341
+ ? pc.place
342
+ : pc.place.toLowerCase();
343
343
  return exactMatch
344
344
  ? placeName === searchTerm
345
345
  : placeName.includes(searchTerm);
@@ -355,7 +355,7 @@ function getPostalCodesByMunicipalityId(municipalityId) {
355
355
  if (typeof municipalityId !== 'string') {
356
356
  throw new TypeError('Municipality ID must be a string');
357
357
  }
358
- return postalCodes.filter(pc => pc.k_id === municipalityId);
358
+ return postalCodes.filter(pc => pc.id === municipalityId);
359
359
  }
360
360
  /**
361
361
  * Get unique postal places.
@@ -363,7 +363,7 @@ function getPostalCodesByMunicipalityId(municipalityId) {
363
363
  */
364
364
  function getUniquePostalPlaces() {
365
365
  const uniquePlaces = new Set();
366
- postalCodes.forEach(pc => uniquePlaces.add(pc.k_postal_place));
366
+ postalCodes.forEach(pc => uniquePlaces.add(pc.place));
367
367
  return Array.from(uniquePlaces).sort();
368
368
  }
369
369
  /**
@@ -377,7 +377,7 @@ function getPostalCodesInRange(startCode, endCode) {
377
377
  if (typeof startCode !== 'string' || typeof endCode !== 'string') {
378
378
  throw new TypeError('Start and end codes must be strings');
379
379
  }
380
- return postalCodes.filter(pc => pc.k_postal_code >= startCode && pc.k_postal_code <= endCode);
380
+ return postalCodes.filter(pc => pc.code >= startCode && pc.code <= endCode);
381
381
  }
382
382
  /**
383
383
  * Get postal codes statistics.
@@ -387,8 +387,8 @@ function getPostalCodesStats() {
387
387
  const uniquePlaces = new Set();
388
388
  const uniqueMunicipalities = new Set();
389
389
  postalCodes.forEach(pc => {
390
- uniquePlaces.add(pc.k_postal_place);
391
- uniqueMunicipalities.add(pc.k_id);
390
+ uniquePlaces.add(pc.place);
391
+ uniqueMunicipalities.add(pc.id);
392
392
  });
393
393
  return {
394
394
  totalPostalCodes: postalCodes.length,
@@ -403,8 +403,8 @@ function getPostalCodesStats() {
403
403
  */
404
404
  function getPostalCodesSorted(ascending = true) {
405
405
  const sorted = [...postalCodes].sort((a, b) => ascending
406
- ? a.k_postal_code.localeCompare(b.k_postal_code)
407
- : b.k_postal_code.localeCompare(a.k_postal_code));
406
+ ? a.code.localeCompare(b.code)
407
+ : b.code.localeCompare(a.code));
408
408
  return sorted;
409
409
  }
410
410
  /**
@@ -416,7 +416,7 @@ function isValidPostalCode(code) {
416
416
  if (typeof code !== 'string') {
417
417
  return false;
418
418
  }
419
- return postalCodes.some(pc => pc.k_postal_code === code);
419
+ return postalCodes.some(pc => pc.code === code);
420
420
  }
421
421
  /**
422
422
  * Get postal codes by municipality name.
@@ -427,7 +427,7 @@ function isValidPostalCode(code) {
427
427
  */
428
428
  function getPostalCodesByMunicipalityName(municipalityName, exactMatch = false) {
429
429
  const matchingMunicipalities = getMunicipalitiesByName(municipalityName, { exactMatch });
430
- const municipalityIds = matchingMunicipalities.map(m => m.k_id);
431
- return postalCodes.filter(pc => municipalityIds.includes(pc.k_id));
430
+ const municipalityIds = matchingMunicipalities.map(m => m.id);
431
+ return postalCodes.filter(pc => municipalityIds.includes(pc.id));
432
432
  }
433
433
  //# sourceMappingURL=index.js.map
package/dist/types.d.ts CHANGED
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aprestmo/norway-geodata",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "description": "Administrative geographic data for Norway including municipalities, counties, and postal codes.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,8 +10,8 @@
10
10
  "require": "./dist/index.js",
11
11
  "import": "./dist/index.js"
12
12
  },
13
- "./data/municipalities": "./data/kommuner-2025.json",
14
- "./data/counties": "./data/fylker-2025.json",
13
+ "./data/municipalities": "./data/municipalities-2025.json",
14
+ "./data/counties": "./data/counties-2025.json",
15
15
  "./types": {
16
16
  "types": "./dist/types.d.ts",
17
17
  "require": "./dist/types.js",
@@ -1,77 +0,0 @@
1
- [
2
- {
3
- "f_id": "03",
4
- "f_name": "Oslo",
5
- "f_url": "www.oslo.kommune.no"
6
- },
7
- {
8
- "f_id": "11",
9
- "f_name": "Rogaland",
10
- "f_url": "www.rogfk.no"
11
- },
12
- {
13
- "f_id": "15",
14
- "f_name": "Møre og Romsdal",
15
- "f_url": "www.mrfylke.no"
16
- },
17
- {
18
- "f_id": "18",
19
- "f_name": "Nordland",
20
- "f_url": "www.nfk.no"
21
- },
22
- {
23
- "f_id": "31",
24
- "f_name": "Østfold",
25
- "f_url": "www.ofk.no"
26
- },
27
- {
28
- "f_id": "32",
29
- "f_name": "Akershus",
30
- "f_url": "www.afk.no"
31
- },
32
- {
33
- "f_id": "33",
34
- "f_name": "Buskerud",
35
- "f_url": "www.bfk.no"
36
- },
37
- {
38
- "f_id": "34",
39
- "f_name": "Innlandet",
40
- "f_url": "www.innlandetfylke.no"
41
- },
42
- {
43
- "f_id": "39",
44
- "f_name": "Vestfold",
45
- "f_url": "www.vestfoldfylke.no"
46
- },
47
- {
48
- "f_id": "40",
49
- "f_name": "Telemark",
50
- "f_url": "www.telemarkfylke.no"
51
- },
52
- {
53
- "f_id": "42",
54
- "f_name": "Agder",
55
- "f_url": "www.agderfk.no"
56
- },
57
- {
58
- "f_id": "46",
59
- "f_name": "Vestland",
60
- "f_url": "www.vestlandfylke.no"
61
- },
62
- {
63
- "f_id": "50",
64
- "f_name": "Trøndelag",
65
- "f_url": "www.trondelagfylke.no"
66
- },
67
- {
68
- "f_id": "55",
69
- "f_name": "Troms",
70
- "f_url": "www.tromsfylke.no"
71
- },
72
- {
73
- "f_id": "56",
74
- "f_name": "Finnmark",
75
- "f_url": "www.ffk.no"
76
- }
77
- ]