Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/v1/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ class Record {
}
}

/**
* Generates an object out of the current Record
*
* @returns {Object}
*/
toObject() {
const object = {};
this.forEach((value, key) => {
object[key] = value
});

return object;
}

/**
* Get a value from this record, either by index or by field key.
*
Expand Down
13 changes: 13 additions & 0 deletions test/v1/record.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ describe('Record', function() {
expect(record.has(1)).toEqual(false);
});

it('should transform Record into Object', function() {
// Given
var record = new Record( ["name", "age", "nested"], ["Bob", 20.5, {test: true}] );

// When
var obj = record.toObject();

// Then
expect(obj.name).toEqual("Bob");
expect(obj.age).toEqual(20.5);
expect(obj.nested.test).toEqual(true);
});

it('should give helpful error on no such key', function() {
// Given
var record = new Record( ["name"], ["Bob"] );
Expand Down