Skip to content
Javascript library inspired by the R reshape package
JavaScript
Find file
Latest commit 46453e3 @jrideout add bower
Failed to load latest commit information.
test Get ready for npm
.gitignore Initial commit
.travis.yml Get ready for npm
LICENSE Initial commit
README.md fix typo
bower.json add bower
melt.js jshint fix
package.json update version for docs

README.md

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

Something went wrong with that request. Please try again.