Webpack loader to convert CSV to simple objects. There are already many CSV loaders available, but I needed one that returned a hashed object.
$ npm install --save-dev csvtoobj-loader
File (lang.csv):
key,en,pt
greeding,Hi,Oi
confirm,Confirm,Confirmar
key | en | pt |
---|---|---|
greeding | Hi | Oi |
confirm | Confirm | Confirmar |
Code:
require('csvtoobj!./lang.csv')
Output:
{
greeding: {
key: 'greeding',
en: 'Hi',
pt: 'Oi'
},
confirm: {
key: 'confirm',
en: 'Confirm',
pt: 'Confirmar'
}
}
Code:
require('csvtoobj?col=pt!./lang.csv')
Output:
{
greeding: 'Oi',
confirm: 'Confirmar'
}
Process:
key
(default: 'key') - name of the column to use as hash keycol
- the name of the desired column to be returned, leave blank to receive the entire object
Parse:
delimiter
- the delimiting character, leave blank to auto-detectnewline
- the newline sequence, leave blank to auto-detectcomment
- character that marks a line as a commenttyping
- if true, numeric and boolean data will be converted to their type instead of remaining strings
For more information about the parse options, check out the documentation of the parser
csvtoobj-loader is free and unencumbered public domain software. For more information, see the accompanying LICENSE file.