Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dekkai

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dekkai

Modern and fast, really fast, CSV parser for the browser and node.js

  • 0.1.0
  • npm
  • Socket score

Version published
Weekly downloads
27
increased by80%
Maintainers
1
Weekly downloads
 
Created
Source

dekkai

Modern and fast, really fast, CSV parser for the browser and node.js

WARNING: This is pre-release code, although stable, some features have not been implemented yet.

Installation

yarn add dekkai

or

npm install dekkai

Usage

Loading a file

In the browser:

import {dekkai} from 'dekkai';

async function main() {
    const fileInput = document.createElement('input');
    fileInput.setAttribute('type', 'file');
    fileInput.setAttribute('name', 'dataFile');
    document.body.appendChild(fileInput);
    
    fileInput.addEventListener('change', async e => {
        e.preventDefault();
        await dekkai.init(/* number of threads, blank for auto-detect */);
        
        const table = await dekkai.loadLocalFile(fileInput.files[0]);
    });
}

main();

In Node.js

const dekkai = require('dekkai/dist/umd/dekkai');
const path = require('path');
const fs = require('fs');

function open(file) {
    return new Promise((resolve, reject) => {
        fs.open(path.resolve(file), (err ,fd) => {
            if (err) {
                reject(err);
            } else {
                resolve(fd);
            }
        });
    });
}

async function main() {
    await dekkai.init(/* number of threads, blank for auto-detect */);
    const file = await open(path.resolve(__dirname, '../Airports2.csv'));
    const table = await dekkai.loadLocalFile(file);
}

main();
Accessing the data
/* access the data through the table methods */
table.setColumnType('Fly_date', 'string'); // overwrite the specified column's detected type
table.setColumnType(13, 'int'); // can be done by column index

/* iterate through all the rows */
await table.forEach(row => {
    console.log(row.valueByName('Origin_city')); // get a value by column name
    console.log(row.valueByNameTyped('Passengers')); // parse the value as its type
    console.log(row.valueByIndex(0)); // get a value by column index
    console.log(row.valueByNameTyped(6)); // parse the value as its type
});

/* get arbitrary row numbers */
for (let i = 100; i < 200 && i < table.rowCount; ++i) {
    const row = await table.getRow(i);
    let str = '';
    /* iterate over all the values in the row */
    row.forEach(value => {
        str += value + '\t';
    });
    console.log(str);
}
Teardown
/* terminate dekkai */
dekkai.terminate();

Example

  • Checkout this repo
  • Install yarn if needed.
  • On the command line navigate to the repo's folder
  • Run yarn install
  • Run yarn start and wait for project to build
  • In your browser, navigate to localhost:8090
  • Load a CSV huge CSV file!

Benchmark

CPU: 6 cores, 2.6 GHz, Core i7 (I7-8850H)
File: Airports2.csv, 15 columns, 3606803 rows, 509MB

LanguageLibraryTypedSingle-threadMulti-thread(6)
JS (Node)dekkaiYes5629ms1088ms
JS (Web)dekkaiYes5311ms1156ms
C++11fast-cpp-csv-parserYes1797msN/A
Goencoding/csvN/A2135msN/A
Goweberc2/fastcsvN/A3075msN/A
C++11AriaFallah/csv-parserN/A4011msN/A
JS (Web)Papa Parse 4No11913msN/A
JS (Web)Papa Parse 4Yes19508msN/A
JS (Node)fast-csvN/A35789msN/A

Keywords

FAQs

Package last updated on 17 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc