Browse Source

Add csv parser

pull/341/head
Hironsan 5 years ago
parent
commit
a61d230c7f
4 changed files with 27 additions and 0 deletions
  1. 1
      frontend/package.json
  2. 9
      frontend/services/parsers/csv.service.js
  3. 12
      frontend/test/unit/services/csv.service.spec.js
  4. 5
      frontend/yarn.lock

1
frontend/package.json

@ -19,6 +19,7 @@
"@toast-ui/vue-editor": "^1.1.1", "@toast-ui/vue-editor": "^1.1.1",
"codemirror": "^5.48.2", "codemirror": "^5.48.2",
"nuxt": "^2.0.0", "nuxt": "^2.0.0",
"papaparse": "^5.0.2",
"tui-editor": "^1.4.5", "tui-editor": "^1.4.5",
"vuetify": "^2.0.2" "vuetify": "^2.0.2"
}, },

9
frontend/services/parsers/csv.service.js

@ -0,0 +1,9 @@
import Papa from 'papaparse'
class CSVParser {
parse(text, options = { header: true }) {
return Papa.parse(text, options)
}
}
export default CSVParser

12
frontend/test/unit/services/csv.service.spec.js

@ -0,0 +1,12 @@
import CSVParser from '@/services/parsers/csv.service'
describe('Request', () => {
const parser = new CSVParser()
test('can parse text', () => {
const text = 'col 1,col 2\n1,2'
const parsed = parser.parse(text)
expect(parsed.meta.fields).toEqual(['col 1', 'col 2'])
expect(parsed.data[0]['col 1']).toEqual('1')
})
})

5
frontend/yarn.lock

@ -6910,6 +6910,11 @@ pako@=1.0.10, pako@~1.0.5:
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.10.tgz#4328badb5086a426aa90f541977d4955da5c9732" resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.10.tgz#4328badb5086a426aa90f541977d4955da5c9732"
integrity sha512-0DTvPVU3ed8+HNXOu5Bs+o//Mbdj9VNQMUOe9oKCwh8l0GNwpTDMKCWbRjgtD291AWnkAgkqA/LOnQS8AmS1tw== integrity sha512-0DTvPVU3ed8+HNXOu5Bs+o//Mbdj9VNQMUOe9oKCwh8l0GNwpTDMKCWbRjgtD291AWnkAgkqA/LOnQS8AmS1tw==
papaparse@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/papaparse/-/papaparse-5.0.2.tgz#447ef95a42015e0b0e52df717b44aedc78252dc9"
integrity sha512-FoaaFfNlCztJ7c+XD1Fgb0zIJ530HwSr6FBfM1mcMzLtIWoTxE5paBNJWiCWFjDrTzGiEG/uIUfqVzgKxqd+Sw==
parallel-transform@^1.1.0: parallel-transform@^1.1.0:
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/parallel-transform/-/parallel-transform-1.1.0.tgz#d410f065b05da23081fcd10f28854c29bda33b06" resolved "https://registry.yarnpkg.com/parallel-transform/-/parallel-transform-1.1.0.tgz#d410f065b05da23081fcd10f28854c29bda33b06"

Loading…
Cancel
Save