Contributing: Added G7 "Standard Methods"

This commit is contained in:
Braydon Fuller 2014-12-12 19:25:14 -05:00
parent e4cf84519d
commit f6c7ec5d22
1 changed files with 15 additions and 2 deletions

View File

@ -105,6 +105,19 @@ DON'T:
var bufferUtil = require('./util/buffer');
```
### G7 - General: Standard Methods
When possible, bitcore objects should have standard methods on an instance prototype:
* `toObject` - A plain JavaScript object that can be JSON stringified
* `toJSON` - A JSON stringified object of the instance
* `toString` - A string representation of the instance
* `toBuffer` - A hex Buffer
These should have a matching static method that can be used for instantiation:
* `fromJSON` - Should handle both JSON from `toJSON` and plain JavaScript object from `toObject`
* `fromString` - Should be able to instantiate with output from `toString`
* `fromBuffer` - Should likewise be able to instantiate from output from `toBuffer`
### E1 - Errors: Use bitcore.Errors
We've designed a structure for Errors to follow and are slowly migrating to it.