Skip to content

it-me-joda/parse-my-file

Repository files navigation

Parse-My-File

Configuration

{
    // the character that separates columns
    delimiter: ',',
    // OPTIONAL: the javascript object shape to get from each row
    //// the value of each key is the header value of each column
    //// if not provided, a basic shape will be provided for you
    shape: {
        id: 'ID',
        name: 'NAME',
        pricing: {
            price: 'PRICE',
            quantity: 'QTY'
        }
    }
}

Usage

ID, NAME, PRICE, QTY
1, A THING, $0.99, 5
import { parseMyFile } from 'parse-my-file'

const result = parseMyFile('test.txt', {
    delimiter: ',',
    shape: {
        id: 'ID',
        name: 'NAME',
        pricing: {
            price: 'PRICE',
            quantity: 'QTY',
        }
    }
})

console.log('result', result)
// [ { id: '1', name: 'A THING', pricing: { price '$0.99', quantity: '5' } } ]

// Alternatively, if you choose to not provide a shape
// it will default to using the header value as the keys
// [ { ID: '1', NAME: 'A THING', PRICE: '$0.99', QTY: '5' } ]

About

NPM package for parsing data files to JavaScript objects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published