Skip to content

Commit

Permalink
Merge pull request #163 from hed-standard/fix-tsv-constructor-test
Browse files Browse the repository at this point in the history
Fix type-checking bug in BidsTsvFile constructor
  • Loading branch information
happy5214 authored Jul 31, 2024
2 parents 3be833f + 21e5fb4 commit 1aa57f1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions bids/types/tsv.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import isPlainObject from 'lodash/isPlainObject'

import { BidsFile } from './basic'
import { convertParsedTSVData, parseTSV } from '../tsvParser'
import { BidsSidecar } from './json'
Expand Down Expand Up @@ -47,17 +49,18 @@ export class BidsTsvFile extends BidsFile {
*/
constructor(name, tsvData, file, potentialSidecars = [], mergedDictionary = {}) {
super(name, file, BidsHedTsvValidator)
let parsedTsvData

if (typeof tsvData === 'string') {
parsedTsvData = parseTSV(tsvData)
} else if (tsvData === Object(tsvData)) {
parsedTsvData = convertParsedTSVData(tsvData)
this.parsedTsv = parseTSV(tsvData)
} else if (tsvData instanceof Map) {
this.parsedTsv = tsvData
} else if (isPlainObject(tsvData)) {
this.parsedTsv = convertParsedTSVData(tsvData)
} else {
parsedTsvData = tsvData
throw new Error('parsedTsv has an invalid type')
}
this.parsedTsv = parsedTsvData
this.potentialSidecars = potentialSidecars

this.potentialSidecars = potentialSidecars
this.mergedSidecar = new BidsSidecar(name, mergedDictionary, null)
this.sidecarHedData = this.mergedSidecar.hedData
this._parseHedColumn()
Expand Down

0 comments on commit 1aa57f1

Please sign in to comment.