Skip to content

Commit

Permalink
a:b syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Winterstein committed Jun 13, 2018
1 parent dc1cbfc commit 09ed063
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "data-pivot",
"version": "0.3.2",
"version": "1.0.0",
"description": "A tool for re-arranging data.",
"main": "./bin/pivot.js",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions src/pivot.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const isArray = function(obj) {

const parseSchema = (schemaString) => {
let path = [];
// HACK a:b is the same as a.b
schemaString = schemaString.replace(/:/g,'.');
parseSchema2(schemaString, path, 0);
return path;
}
Expand Down
7 changes: 7 additions & 0 deletions test/test.pivot.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ describe('pivot', function() {
assert.equal(output['Luke'], 'light saber');
});

it('should handle a:b syntax', function() {
var input = {jedi:{name:'Luke', weapon:'light saber'}, smuggler:{name:'Hans'}};
var output = pivot(input, "$role.{name:$n, weapon:$w}", "$n: $w");
console.log(output);
assert.equal(output['Luke'], 'light saber');
});

it('should handle {a, b} shorthand', function() {
var input = {jedi:{name:'Luke', weapon:'light saber'}, smuggler:{name:'Hans'}};
var output = pivot(input, "$role.{name, weapon}", "$name.$weapon");
Expand Down

0 comments on commit 09ed063

Please sign in to comment.