diff --git a/lib/idv.ts b/lib/idv.ts index ddccc28..4db02a6 100644 --- a/lib/idv.ts +++ b/lib/idv.ts @@ -8,11 +8,18 @@ export class Idv { collections: Record = {}; public static parse(input: string): Idv { - const lines = input.split("\n").map((line) => line.trimEnd()); - return Idv.parseLines(lines); - } - static parseLines(input: string[]): Idv { const idv = new Idv(); + return idv.import(input); + } + public static parseLines(input: string[]): Idv { + const idv = new Idv(); + return idv.importLines(input); + } + public import(input: string): Idv { + const lines = input.split("\n").map((line) => line.trimEnd()); + return this.importLines(lines); + } + public importLines(input: string[]): Idv { let currentDocument: string[] | undefined = undefined; let currentIndent: string | undefined = undefined; let bufferedBlankLines: string[] = []; @@ -44,20 +51,20 @@ export class Idv { if (matches) { const [, collection, distinguisher] = matches; - if (idv.collections[collection] == undefined) { - idv.collections[collection] = []; + if (this.collections[collection] == undefined) { + this.collections[collection] = []; } currentDocument = []; currentIndent = undefined; - idv.collections[collection].push([distinguisher, currentDocument]); + this.collections[collection].push([distinguisher, currentDocument]); } else { throw new Error("Failed to parse a property"); } } }); - return idv; + return this; } public getProperty(