# datalib

> JavaScript utilites for loading, summarizing and working with data.

Latest version **1.9.3** (published 2020-08-31) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install datalib
pnpm add datalib
yarn add datalib
bun add datalib
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.9.3 |
| Published | 2020-08-31 |
| First published | 2015-04-19 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 706.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 734 |
| Author | Jeffrey Heer |
| Maintainers | jheer |
| Keywords | data, table, statistics, parse, csv, tsv, json, utility |

## Links

- npm: https://www.npmjs.com/package/datalib
- Repository: https://github.com/vega/datalib
- Homepage: https://github.com/vega/datalib#readme
- Issues: https://github.com/vega/datalib/issues
- npm.io page: https://npm.io/package/datalib

## Dependencies (7)

- [d3-dsv](https://npm.io/package/d3-dsv.md) 0.1
- [d3-time](https://npm.io/package/d3-time.md) 0.1
- [request](https://npm.io/package/request.md) ^2.67.0
- [d3-format](https://npm.io/package/d3-format.md) 0.4
- [sync-request](https://npm.io/package/sync-request.md) ^6.0.0
- [d3-time-format](https://npm.io/package/d3-time-format.md) 0.2
- [topojson-client](https://npm.io/package/topojson-client.md) ^3.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.9.3 (latest) — 2020-08-31
- 1.9.2 — 2018-11-14
- 1.9.1 — 2018-07-03
- 1.9.0 — 2018-07-03
- 1.8.0 — 2017-07-12
- 1.7.3 — 2016-10-13
- 1.7.2 — 2016-07-19
- 1.7.1 — 2016-06-19
- 1.7.0 — 2016-05-18
- 1.6.3 — 2016-03-01
- 1.6.2 — 2016-03-01
- 1.6.1 — 2016-02-18
- 1.6.0 — 2016-02-18
- 1.5.9 — 2016-01-08
- 1.5.8 — 2015-12-16
- … 59 more at https://npm.io/package/datalib/versions

## README

# datalib

[![Build Status](https://travis-ci.org/vega/datalib.svg?branch=master)](https://travis-ci.org/vega/datalib)
[![npm version](https://img.shields.io/npm/v/datalib.svg)](https://www.npmjs.com/package/datalib)

Datalib is a JavaScript data utility library. It provides facilities for data loading, type inference, common statistics, and string templates. While datalib was created to power [Vega](http://vega.github.io) and related projects, it is also a standalone library useful for data-driven JavaScript applications on both the client (web browser) and server (e.g., node.js).

For documentation, see the datalib [API Reference](../../wiki/API-Reference).

## Use

Datalib provides a set of utilities for working with data. These include:

- Loading and parsing data files (JSON, TopoJSON, CSV, TSV).
- Summary statistics (mean, deviation, median, correlation, histograms, etc).
- Group-by aggregation queries, including streaming data support.
- Data-driven string templates with expressive formatting filters.
- Utilities for working with JavaScript functions, objects and arrays.

Datalib can be used both server-side and client-side. For use in node.js,
simply `npm install datalib` or include datalib as a dependency in your package.json file. For use on the client, install datalib via `bower install datalib` or include datalib.min.js on your web page. The minified JS file is built using rollup (see below for details).

### Example

```javascript
// Load datalib.
var dl = require('datalib');

// Load and parse a CSV file. Datalib does type inference for you.
// The result is an array of JavaScript objects with named values.
// Parsed dates are stored as UNIX timestamp values.
var data = dl.csv('https://vega.github.io/datalib/data/stocks.csv');

// Show summary statistics for each column of the data table.
console.log(dl.format.summary(data));

// Compute mean and standard deviation by ticker symbol.
var rollup = dl.groupby('symbol')
  .summarize({'price': ['mean', 'stdev']})
  .execute(data);
console.log(dl.format.table(rollup));

// Compute correlation measures between price and date.
console.log(
  dl.cor(data, 'price', 'date'),      // Pearson product-moment correlation
  dl.cor.rank(data, 'price', 'date'), // Spearman rank correlation
  dl.cor.dist(data, 'price', 'date')  // Distance correlation
);

// Compute mutual information distance between years and binned price.
var bin_price = dl.$bin(data, 'price'); // returns binned price values
var year_date = dl.$year('date');       // returns year from date field
var counts = dl.groupby(year_date, bin_price).count().execute(data);
console.log(dl.mutual.dist(counts, 'bin_price', 'year_date', 'count'));
```

## Build Process

To use datalib in the browser, you need to build the datalib.js and datalib.min.js files. We assume that you have [npm](https://www.npmjs.com/) installed.

1. Run `npm install` in the datalib folder to install dependencies.
2. Run `npm run build`. This will invoke [rollup](https://rollupjs.org) to bundle the source files into datalib.js, and then [uglify-js](http://lisperator.net/uglifyjs/) to create the minified datalib.min.js.


### Webpack 1

If you are using Webpack 1, you need to enable a JSON-loader. To do so, first `npm install --save json-loader`, then add the loader to your webpack config:

```js
{
  module: {
    loaders: [{
      test: /\.json$/,
      loader: 'json-loader'
    }]
  }
}
```

---
_Source: https://npm.io/package/datalib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
