URI/Unit: Added toObject method and changed toJSON to return a string
This commit is contained in:
parent
c0bbf96dc1
commit
cddd55afc4
|
@ -175,17 +175,21 @@ Unit.prototype.toString = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will return a the JSON object representation of the unit
|
* Will return a plain object representation of the Unit
|
||||||
*
|
*
|
||||||
* @returns {Object} An object with the keys: amount and code
|
* @returns {Object} An object with the keys: amount and code
|
||||||
*/
|
*/
|
||||||
Unit.prototype.toJSON = function toJSON(){
|
Unit.prototype.toObject = function toObject() {
|
||||||
return {
|
return {
|
||||||
amount: this._amount,
|
amount: this._amount,
|
||||||
code: this._code
|
code: this._code
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Unit.prototype.toJSON = function toJSON() {
|
||||||
|
return this.toObject();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will return a string formatted for the console
|
* Will return a string formatted for the console
|
||||||
*
|
*
|
||||||
|
|
|
@ -163,7 +163,7 @@ URI.prototype._parseAmount = function(amount) {
|
||||||
return Unit.fromBTC(amount).toSatoshis();
|
return Unit.fromBTC(amount).toSatoshis();
|
||||||
};
|
};
|
||||||
|
|
||||||
URI.prototype.toJSON = function() {
|
URI.prototype.toObject = function toObject() {
|
||||||
var json = {};
|
var json = {};
|
||||||
for (var i = 0; i < URI.Members.length; i++) {
|
for (var i = 0; i < URI.Members.length; i++) {
|
||||||
var m = URI.Members[i];
|
var m = URI.Members[i];
|
||||||
|
@ -179,6 +179,10 @@ URI.prototype.toJSON = function() {
|
||||||
return json;
|
return json;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
URI.prototype.toJSON = function toJSON() {
|
||||||
|
return JSON.stringify(this.toObject());
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will return a the string representation of the URI
|
* Will return a the string representation of the URI
|
||||||
*
|
*
|
||||||
|
|
|
@ -146,12 +146,12 @@ describe('URI', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should input/output JSON', function() {
|
it('should input/output JSON', function() {
|
||||||
var json = {
|
var json = JSON.stringify({
|
||||||
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
|
address: '1DP69gMMvSuYhbnxsi4EJEFufUAbDrEQfj',
|
||||||
message: 'Donation for project xyz',
|
message: 'Donation for project xyz',
|
||||||
label: 'myLabel',
|
label: 'myLabel',
|
||||||
other: 'xD'
|
other: 'xD'
|
||||||
};
|
});
|
||||||
URI.fromJSON(json).toJSON().should.deep.equal(json);
|
URI.fromJSON(json).toJSON().should.deep.equal(json);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue