Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/main/ts/ingrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type TIngridParse = (input: string) => TIngridResponse

const EOL = /\r?\n|\r|\n/
const EMPTY = '-'
const LL = 80
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The constant LL is a magic number and its purpose (fixed column width) isn’t immediately clear. Consider renaming it to something descriptive (e.g., COLUMN_CHUNK_SIZE) or adding a comment explaining why it’s set to 80.

Suggested change
const LL = 80
// Fixed column width for text formatting, commonly set to 80 characters.
const COLUMN_CHUNK_SIZE = 80

Copilot uses AI. Check for mistakes.

type TLineDigest = {
spaces: number[],
Expand Down Expand Up @@ -127,18 +128,20 @@ const gridToData = (grid: string[][][]): TIngridResponse => {
return data
}

const roundUp = (l: number) => Math.ceil(l / LL) * LL

// eslint-disable-next-line sonarjs/cognitive-complexity
export const parseWinGrid = (input: string): TIngridResponse => {
const _lines = input.split(/\r?\n/)
const lines = _lines.filter(Boolean)
const headline = lines.shift()!
const headers = headline.split(/\s+/)
const ll = lines[0].length
const hl = headers.length
const limit = roundUp(lines[0].length)

if (lines.every(l => l.length === ll)) {
if (lines.every(l => roundUp(l.length) === limit)) {
const spaces = Array
.from({ length: ll })
.from({ length: limit })
.map((_, i) =>
lines.every(l => l[i] === ' ')
)
Expand All @@ -154,7 +157,7 @@ export const parseWinGrid = (input: string): TIngridResponse => {
for (const i in headers) {
const k = headers[i]
const s = borders[i]
const e = borders[+i + 1] || ll
const e = borders[+i + 1] || limit
const v = line.slice(s, e).trim()
props.push([k, [v || EMPTY]])
}
Expand Down
Loading