tktk

The TK toolkit. Utilities for dealing with data in Node.js.

The TK Toolkit

A work-in-progress collection of utilities to help with reading, transforming and writing data.

Installation

npm install tktk

Usage

Examples TK.

Current functions

Uses the indian-ocean module. Reads a variety of data file formats in as json.

Reads in a data file given a path ending in the file format. Callback structure is function(err, data).

Supported formats:

  • .json
  • .csv Comma-separated
  • .tsv Tab-separated
  • .psv Pipe-separated

Pass in a delimiter as the second argument to read in another format.

Syncronous version of .readData()

Read in a json file. Callback structure is function(err, data).

Read json syncronously.

Read in a comma-separated value file. Callback structure is function(err, data).

Read csv syncronously.

Read in a tab-separated value file. Callback structure is function(err, data).

Read tsv syncronously.

Read in a pipe-separated value file. Callback structure is function(err, data).

Read psv syncronously.

Read in a .dbf file. Callback structure is function(err, data).

Uses the indian-ocean module. Writes json objects to the specified format.

Write out the data object, inferring the file format from the file ending specified in filepath. Callback structure is function(err, data).

Supported formats:

  • .json
  • .csv Comma-separated
  • .tsv Tab-separated
  • .psv Pipe-separated

Syncronous version of .writeData. Callback structure is function(err).

Reads in a dbf file with .readDbf and write to file using .writeData. Callback structure is function(err).

Uses the joiner module. All methods return an object with the following structure:

data: [data object],
report: {
    diff: {
        a: [data in A],
        b: [data in A],
        a_and_b: [data in A and B],
        a_not_in_b: [data in A not in B],
        b_not_in_a: [data in B not in A]
    }:
    prose: {
        summary: [summary description of join result, number of matches in A and B, A not in B, B not in A.]
        full:    [full list of which rows were joined in each of the above categories]
    }
}

Perform a left join on the two array-of-object json datasets. Optionally, you can pass in a key name in case the left data's attribute dictionary is nested, such as in GeoJson where the attributes are under a properties object.

Does the same thing as .left but navigates to the features array and passes in properties as the nested key name.

Uses the tablespoon module. Check out the wiki for the full documention. All tablespoon methods are accessible under the tk.db namespace, e.g.

tk.db.createTableSync(data);

Uses the simple-statistics module. All simple-statistics methods are accessible under the tk.stats namespace, e.g.

var mean = tk.stats.mean([1, 4, 19, 55]);

Given a filepath return its file extension. Used internally by .discernPaser and .discernFileFormatter.

E.g. tk.discernFormat('path/to/data.csv') returns 'csv'

Given a filepath, optionally a delimiter, return a parser that can read that file as json. Used internally by .readData and .readDataSync.

E.g.

var csvParser = tk.discernParser('path/to/data.csv');
 
var json = parser('path/to/data.csv');

Returns a formatter that will format json data to file type specified by the extension in filepath. Used internally by .writeData and .writeDataSync.

E.g.

var formatter = tk.discernFileFormatter('path/to/data.tsv');
var csv = formatter(json);

Exposes the native File System module for convenience.

What's the name mean?

In news writing, TK is used as a placeholder for facts or sections you don't have yet. For example:

Mrs. Williamson arrived at the office at TK EXACT TIME to speak with the board members.

Depending on whom you ask, it either stands for TO COME if you like your acronyms phonetic or TO KNOW if you don't mind the silent 'K'.

This library is a work in progress so it's largely TO COME. You could also say you can use it TO KNOW things since it's a collection of data utilities. Or you could say it's a (T)ool(K)it of toolkits: a TK TK.