From fdace2deb193ae83fa32fb2b43bd29a462281ba0 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 17 Sep 2018 08:32:52 -0700 Subject: [PATCH] Type regionParser --- js/{regionParser.js => regionParser.ts} | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) rename js/{regionParser.js => regionParser.ts} (79%) diff --git a/js/regionParser.js b/js/regionParser.ts similarity index 79% rename from js/regionParser.js rename to js/regionParser.ts index 53290ba4..089a0e62 100644 --- a/js/regionParser.js +++ b/js/regionParser.ts @@ -1,6 +1,6 @@ import { parseIni } from "./utils"; -export function pointPairs(arr) { +export function pointPairs(arr: string[]) { const pairedValues = []; for (let i = 0; i < arr.length; i += 2) { pairedValues.push(`${arr[i]},${arr[i + 1]}`); @@ -8,9 +8,11 @@ export function pointPairs(arr) { return pairedValues; } -export default function regionParser(regionStr) { +type RegionData = { [section: string]: string[] }; + +export default function regionParser(regionStr: string) { const iniData = parseIni(regionStr); - const data = {}; + const data: RegionData = {}; Object.keys(iniData).forEach(section => { const { numpoints, pointlist } = iniData[section]; if (!numpoints || !pointlist) { @@ -32,7 +34,9 @@ export default function regionParser(regionStr) { pointIndex += num; return polygon; }); - const validPolygons = polygons.filter(polygon => polygon != null); + const validPolygons = polygons.filter( + polygon => polygon != null + ) as string[]; if (validPolygons.length) { data[section] = validPolygons; }