Skip to content
Merged
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: 4 additions & 7 deletions src/main/ts/ingrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type TIngridParse = (input: string) => TIngridResponse

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

type TLineDigest = {
spaces: number[],
Expand Down Expand Up @@ -128,20 +127,18 @@ 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 hl = headers.length
const limit = roundUp(lines[0].length)
const ll = headline.length

if (lines.every(l => roundUp(l.length) === limit)) {
if (lines.every(l => ll / l.length < 2)) {
const spaces = Array
.from({ length: limit })
.from({ length: ll })
.map((_, i) =>
lines.every(l => l[i] === ' ')
)
Expand All @@ -157,7 +154,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] || limit
const e = borders[+i + 1] || ll
const v = line.slice(s, e).trim()
props.push([k, [v || EMPTY]])
}
Expand Down