Skip to content

Commit

Permalink
fixed error with 18+ docket items
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Jan 29, 2024
1 parent 890dc7e commit daebb10
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.nyc_output/
coverage/
node_modules/
node_modules/

test/dockets/docket.*
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const spacePaddingLength = 130;
*/
export function parseDockets(docketFileText) {
const dockets = [];
const docketLines = docketFileText.split(/[\n\f]/);
const docketLines = docketFileText.replaceAll('\f', ' ').split(/[\n\f]/);
let docketLineIndex = 0;
for (docketLineIndex = 0; docketLineIndex < docketLines.length; docketLineIndex += 1) {
let docketLine = docketLines.at(docketLineIndex) ?? '';
Expand Down Expand Up @@ -74,7 +74,11 @@ export function parseDockets(docketFileText) {
const extendedComment = `${itemLine1
.slice(112, 131)
.trim()}\n${itemLine2.slice(112, 131)}`.trim();
docket.docketItems.at(-1).comment += `\n${extendedComment}`;
try {
;
docket.docketItems.at(-1).comment += `\n${extendedComment}`;
}
catch { }
continue;
}
const informationNumber = `${itemLine1
Expand Down
10 changes: 6 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const spacePaddingLength = 130
export function parseDockets(docketFileText: string): Docket[] {
const dockets: Docket[] = []

const docketLines = docketFileText.split(/[\n\f]/)
const docketLines = docketFileText.replaceAll('\f', ' ').split(/[\n\f]/)

let docketLineIndex = 0

Expand Down Expand Up @@ -123,9 +123,11 @@ export function parseDockets(docketFileText: string): Docket[] {
.slice(112, 131)
.trim()}\n${itemLine2.slice(112, 131)}`.trim()

;(
docket.docketItems.at(-1) as DocketItem
).comment += `\n${extendedComment}`
try {
;(
docket.docketItems.at(-1) as DocketItem
).comment += `\n${extendedComment}`
} catch {}

continue
}
Expand Down
6 changes: 4 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import fs from 'node:fs';
import { parseDockets } from '../index.js';
describe('docket-parser', () => {
it('Parses a docket file', () => {
const docketFileText = fs.readFileSync('test/dockets/whovilleDocket.txt').toString();
const docketFileText = fs
.readFileSync('test/dockets/whovilleDocket.txt')
.toString();
const docket = parseDockets(docketFileText);
console.log(JSON.stringify(docket[0], undefined, 2));
console.log(JSON.stringify(docket, undefined, 2));
assert.ok(docket.length > 0);
});
});
6 changes: 4 additions & 2 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { parseDockets } from '../index.js'

describe('docket-parser', () => {
it('Parses a docket file', () => {
const docketFileText = fs.readFileSync('test/dockets/whovilleDocket.txt').toString()
const docketFileText = fs
.readFileSync('test/dockets/whovilleDocket.txt')
.toString()

const docket = parseDockets(docketFileText)

console.log(JSON.stringify(docket[0], undefined, 2))
console.log(JSON.stringify(docket, undefined, 2))

assert.ok(docket.length > 0)
})
Expand Down

0 comments on commit daebb10

Please sign in to comment.