Skip to content

bassarisse/csvtoobj-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

csvtoobj-loader

NPM version

Webpack loader to convert CSV to simple objects. There are already many CSV loaders available, but I needed one that returned a hashed object.

Installation

$ npm install --save-dev csvtoobj-loader

Basic usage

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'
}

Options (inline)

Process:

  • key (default: 'key') - name of the column to use as hash key
  • col - 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-detect
  • newline - the newline sequence, leave blank to auto-detect
  • comment - character that marks a line as a comment
  • typing - 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

License

csvtoobj-loader is free and unencumbered public domain software. For more information, see the accompanying LICENSE file.

About

Webpack loader to convert CSV to simple objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published