https://github.com/planemad/lookup-csv
A node module to quickly search and lookup rows from a csv file
https://github.com/planemad/lookup-csv
csv csv-json lookup lookup-rows
Last synced: about 1 year ago
JSON representation
A node module to quickly search and lookup rows from a csv file
- Host: GitHub
- URL: https://github.com/planemad/lookup-csv
- Owner: planemad
- License: mit
- Created: 2019-05-05T17:05:30.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-13T19:18:21.000Z (about 6 years ago)
- Last Synced: 2025-03-02T05:32:10.487Z (about 1 year ago)
- Topics: csv, csv-json, lookup, lookup-rows
- Language: JavaScript
- Homepage:
- Size: 63.5 KB
- Stars: 0
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lookup-csv
A node module to quickly search and lookup rows from a CSV file using a JSON API.
An input CSV file is converted to an array of JSON objects using [treeize](https://www.npmjs.com/package/treeize). This is used to build a lookup table by specifying a coumn name as an index using [hasharray](https://www.npmjs.com/package/hasharray).
### Installation
Install module `npm i lookup-csv`
### Simple usage
For a given data.csv, ensure the first row contains the column names. Adding a `.` delimiter in the column names will nest the property in the JSON result
```csv
animal,type,sound.type,sound.pitch
cow,mammal,moo-moo,low
swiss cow,mammal,moo-moo,low
crow,bird,kaa-kaa,high
donkey,mammal,yee-haw,low
```
**Search a single column**
```js
const lookupCSV = require('lookup-csv');
// Create a lookup table using lookup column name to use from the csv data
const lookupTable = lookupCSV('./path/to/data.csv', 'animal')
// Get rows matching lookup value
matchingRows = lookupTable.get('cow')
// {
// animal: 'cow',
// type: 'mammal',
// sound: {
// type: 'moo-moo',
// pitch: 'low'
// }
// }
```