karmadata-utils
v1.0.4
Published
Javascript utilities for working with kd API
Downloads
2
Readme
karmadata-utils.js
Javascript utilities for working with KarmaData API
Purpose
This NPM package provides some commonly used utilities to work with KarmaData API
Functions
pivot(rows, options)
rows
- array of rows, each row being an array of columns (i.e. rows[][] -> value)options
- default is keyColumn: 0, pivotColumn: 1, valueColumn: 2- returns { pivotedRows, pivotedColumns }
Returns pivoted data
Usage Example
const kdutil = require('karmadata-utils');
let rows = [
['A', 'x', 1],
['B', 'x', 2],
['B', 'y', 4],
['B', 'z', 7],
['C', 'y', 2],
['D', 'z', 3],
['A', 'z', 3]
]
let options = {keyColumn: 0, pivotColumn: 1, valueColumn: 2}
let result = kdutil.pivot(rows) // or kdutil.pivot(rows, options)
console.log(result)
// should return
/*
{ rows:
[ [ 'A', 1, null, 3 ],
[ 'B', 2, 4, 7 ],
[ 'C', null, 2, null ],
[ 'D', null, null, 3 ] ],
columns: [ '_key', 'x', 'y', 'z' ] }
*/