parse-my-file
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i parse-my-file

Weekly Downloads

2

Version

1.1.2

License

ISC

Unpacked Size

4.92 kB

Total Files

4

Last publish

Collaborators

  • josephdanielbartley