Skip to content

Instantly share code, notes, and snippets.

@boutell
Created June 16, 2020 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boutell/bc2bc2f56ed7e65b7a5c06b958bd3708 to your computer and use it in GitHub Desktop.
Save boutell/bc2bc2f56ed7e65b7a5c06b958bd3708 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const content = fs.readFileSync('court-docket.txt', 'utf8').split(/\s*\n\s*/);
const data = {};
data.origin = readOrigin();
data.type = readType();
data.docketNumber = readDocketNumber();
data.subtype = readSubtype();
data.case = readCase();
console.log(data);
function readOrigin() {
const origin = readLine().trim();
if (!origin.match(/COURT/i)) {
throw 'First line is not a court of origin';
}
return origin;
}
function readType() {
const type = readLine().trim();
if (!type.match(/DOCKET/i)) {
throw 'type line is not DOCKET';
}
return type;
}
function readDocketNumber() {
const line = readLine().trim();
const matches = line.match(/Docket Number: ([\w\-]+)/i);
if (!matches) {
throw 'docket number line not found';
}
return matches[1];
}
function readSubtype() {
const line = readLine().trim();
if (!line.match(/docket/i)) {
throw 'subtype line does not contain DOCKET';
}
return line;
}
function readCase() {
const header = readLine();
if (!header.match(/court case/i)) {
throw 'Court Case does not appear before case name';
}
let caseName = '';
let vSeen = false;
while (true) {
const line = readLine().trim();
caseName += line + ' ';
if (vSeen) {
break;
}
if (line === 'v.') {
vSeen = true;
}
}
return caseName.trim();
}
function readLine() {
const line = content.shift();
if (line.match(/Page \d+ of \d+/)) {
return readLine();
}
return line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment