Skip to content

jrideout/melt.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Melt.js

Javascript library inspired by the R reshape package by Hadley Wickham.

Melt provides two functions melt and cast. How do they work?

First, they presume you have your data in the form of a list of objects. That looks like this:

var data = [
  {key1: 1, key2: 2},
  {key1: 2, key2: 3},
  {key1: 3, key2: 5},
];

But if you need the keys to be represented as a value, then melt can come to the rescue. Let's take a look at some examples:

Examples

Melt: jsfiddle

Cast: jsfiddle

API

melt(data, keep, varName, valName, noAddId)

  • data list of objects - data to melt
  • keep array of strings - names of object keys to keep
  • varName string - name of the key to use in the molten objects for the former keys (those not in keep)
  • valName string - name of the key to use in the molten objects for the former values
  • noAddId bool - if truthy, don't add the _id value to the resulting object

cast(data, keep, fun, funArgs ...)

  • data list of objects - data to cast
  • keep array of strings - names of object keys to keep (the "GROUP BY" keys)
  • fun function - a function used to aggregate values accross grouped objects
  • funArgs mixed - arguments to passed to fun

cast.sum(name, cols) - convience function to summarize data with cast

  • name string name of resulting object key with sum results
  • cols string or array - names of keys to totaled in the sum. Key values should respond to +.

cast.sum(name) - convience function to sum data with cast

  • name string - special case of cast.sum(name, cols) name is treated as both name and cols.

cast.count(name) - convience function to count data with cast

  • name string - name of resulting object key with which to count objects with common keep values

License

Apache 2

githalytics.com alpha

About

Javascript library inspired by the R reshape package

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published