parse-my-file
v1.1.2
Published
Give your file and a simple configuration to Parse My File and let it do all of the work for you
Downloads
2
Maintainers
Readme
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' } ]