diff --git a/lib/idv.ts b/lib/idv.ts index c8339f5..5cf7d2b 100644 --- a/lib/idv.ts +++ b/lib/idv.ts @@ -7,7 +7,7 @@ const LEADING_WHITESPACE = /^([ \t]+)/; const ENTRY = /^(.+?):\s*(.*)/; export class Idv { - collections: Record = {}; + collections: Map = new Map(); public static parse(input: string): Idv { const idv = new Idv(); @@ -53,14 +53,16 @@ export class Idv { if (matches) { const [, collection, distinguisher] = matches; - if (this.collections[collection] == undefined) { - this.collections[collection] = []; + if (!this.collections.has(collection)) { + this.collections.set(collection, []); } currentDocument = []; currentIndent = undefined; // TODO: implement backslash escaping in the distinguisher - this.collections[collection].push([distinguisher, currentDocument]); + this.collections + .get(collection)! + .push([distinguisher, currentDocument]); } else { throw new Error("Failed to parse a property"); } @@ -71,12 +73,12 @@ export class Idv { } public getProperty(name: string, parse: UnionParser): T | undefined { - const firstEntry = this.collections[name]?.[0]; + const firstEntry = this.collections.get(name)?.[0]; return firstEntry && parse(firstEntry[0], firstEntry[1]); } public getList(name: string, parse: UnionParser): T[] { - return (this.collections[name] ?? []).map(([distinguisher, document]) => + return (this.collections.get(name) ?? []).map(([distinguisher, document]) => parse(distinguisher, document) ); } @@ -86,7 +88,7 @@ export class Idv { parseDocument: DocumentParser ): Record { return Object.fromEntries( - (this.collections[name] ?? []).map(([distinguisher, document]) => [ + (this.collections.get(name) ?? []).map(([distinguisher, document]) => [ distinguisher, parseDocument(document), ]) @@ -99,7 +101,7 @@ export class Idv { ): Record { const idvMap: Map = new Map(); - (this.collections[name] ?? []).forEach(([distinguisher, document]) => { + (this.collections.get(name) ?? []).forEach(([distinguisher, document]) => { let idv = idvMap.get(distinguisher); if (idv == undefined) { idvMap.set(distinguisher, (idv = new Idv())); diff --git a/tsconfig.json b/tsconfig.json index 41fc1da..d1ec214 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,6 +3,7 @@ "isolatedModules": true, "lib": ["ES2019", "DOM"], "strict": true, + "target": "ES2020", "noEmit": true } }