Skip to content

Commit

Permalink
Merge pull request #8 from tropy/custom-delimiter-#7
Browse files Browse the repository at this point in the history
Add delimiter as a setting, use that in parsing and stringifying csv
  • Loading branch information
inukshuk authored May 13, 2022
2 parents b3ba570 + 081bc65 commit 57d355a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
"type": "template",
"hint": "The id of the Tropy template to use for photos. The template determines which fields will be exported. If left empty, the template for the first item's first photo will be used. For import, the selected template will be applied to imported photos."
},
{
"field": "delimiter",
"label": "Delimiter",
"hint": "The character used to separate fields in the CSV file.",
"default": ",",
"required": true
},
{
"field": "tags",
"label": "Export tags?",
Expand Down
11 changes: 7 additions & 4 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class CSVPlugin {
return stringify([this.columns(itemTemplate, photoTemplate, item)], {
quoted: this.options.quotes,
quoted_empty: this.options.quotes,
quoted_string: this.options.quotes
quoted_string: this.options.quotes,
delimiter: this.options.delimiter
})
}

Expand Down Expand Up @@ -94,7 +95,8 @@ class CSVPlugin {
return stringify([this.header(itemTemplate, photoTemplate, maxPhotos)], {
quoted: this.options.quotes,
quoted_empty: this.options.quotes,
quoted_string: this.options.quotes
quoted_string: this.options.quotes,
delimiter: this.options.delimiter
})
}

Expand Down Expand Up @@ -214,7 +216,7 @@ class CSVPlugin {
try {
const csvRows = parse(
await readFile(file),
{ relaxColumnCount: true }
{ relaxColumnCount: true, delimiter: this.options.delimiter }
)

const headerRow = csvRows[0]
Expand Down Expand Up @@ -253,7 +255,8 @@ CSVPlugin.defaults = {
quotes: true,
tags: true,
itemTemplate: '',
photoTemplate: ''
photoTemplate: '',
delimiter: ','
}

class ClipboardWriter {
Expand Down

0 comments on commit 57d355a

Please sign in to comment.