npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

datable

v1.0.3

Published

A light weight tool for handle data in table.

Downloads

9

Readme

datable

NPM version Downloads

A light weight tool for handle data in table.

Datable是一个轻量级的数据处理工具,它可以将一个二维的数据进行Fiter,Group等操作。 Datable非常灵活,没有太多规则,比如说Group的操作如下:

// This is a GroupBy demo.
d.groupby(['date'] /* 指定按照date这一列来group */, function (res) {
    // date相同的行最后会被合并为一行,这里是对最终要输出的那一行的初始化
    res.successCount = 0
    res.errorCount = 0
}, function (res, item) {
    // 每一行都会被被交给这个函数处理,这里收到两个参数,第一个res是最终要合并输出的结果,item是当前遍历到的数据行
    if (item.code == '200') {
        res.successCount += parseInt(item.cnt)
    } else {
        res.errorCount += parseInt(item.cnt)
    }
})

Installation

npm install datable

Usage


var Datable = require('datable')

var d = new Datable({
    SPLIT_FLAG: ','
})
d.readDataFromFile('./input.csv')

console.log(d.getData())

d.filter(function (item) {
    return item.country != 'TT'
})

console.log(d.getData())

API

Refer to demo/demo.js, This demo will transfer data in demo/input.csv to demo/output.csv

Datable

new Datable([options, data])

options:

  • SPLIT_FLAG : default is '\t'

data:

A array.

filter

Filter out some rows according to a condition.

Before:

date,country,code,cnt
2014-01-01,US,500,1001
2014-01-02,CN,500,500
2014-01-02,US,200,1001
2014-01-01,CN,200,500
2014-01-01,CN,200,1001
2014-01-01,TT,500,500

Code:

d.filter(function (item) {
    return item.country != 'TT'
})

After:

date,country,code,cnt
2014-01-01,US,500,1001
2014-01-02,CN,500,500
2014-01-02,US,200,1001
2014-01-01,CN,200,500
2014-01-01,CN,200,1001

groupby

Group by with some colomns, you can handler other colomns with your custom handler.

Before:

date,country,code,cnt
2014-01-01,US,500,1001
2014-01-02,CN,500,500
2014-01-02,US,200,1001
2014-01-01,CN,200,500
2014-01-01,CN,200,1001

Code:

d.groupby(['date'], function (res) {
    res.successCount = 0
    res.errorCount = 0
}, function (res, item) {
    if (item.code == '200') {
        res.successCount += parseInt(item.cnt)
    } else {
        res.errorCount += parseInt(item.cnt)
    }
})

After:

date,successCount,errorCount
2014-01-01,1501,1001
2014-01-02,1001,500

pipeline

pipeline is a helper function for processing data one by one

Before:

date,successCount,errorCount
2014-01-01,1501,1001
2014-01-02,1001,500

Code:

d.pipeline(function (item) {
    item.date += ' 00:00'
})

After:

date,successCount,errorCount
2014-01-01 00:00,1501,1001
2014-01-02 00:00,1001,500

expand

Before:

date,successCount,errorCount
2014-01-01 00:00,1501,1001
2014-01-02 00:00,1001,500

Code:

d.expand('index', ['1','2'], function (val, item) {
    item.name = 'index_' + val
})

After:

date,successCount,errorCount,index,name
2014-01-01 00:00,1501,1001,1,index_1
2014-01-01 00:00,1501,1001,2,index_2
2014-01-02 00:00,1001,500,1,index_1
2014-01-02 00:00,1001,500,2,index_2

readDataFromFile

Read data from file.

d.readDataFromFile('./input.csv')

writeDataToFile

Write Data to file.

d.writeDataToFile('./output.csv')

getData

d.getData()

setData

d.setData([])

License

ISC