From f6c7ec5d22bba7ea376462513e026d49139dde68 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Fri, 12 Dec 2014 19:25:14 -0500 Subject: [PATCH] Contributing: Added G7 "Standard Methods" --- CONTRIBUTING.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3ebcc68..5e6d15b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. @@ -233,7 +246,7 @@ the change the branch introduces. Some examples for such branches are: ```sh git checkout -b test/some-module git checkout -b feature/some-new-stuff -git checkout -b fix/some-bug +git checkout -b fix/some-bug git checkout -b remove/some-file ``` @@ -244,7 +257,7 @@ git pull --rebase bitpay master ``` Note that we require rebasing your branch instead of mergeing it, for commit -readability reasons. +readability reasons. After that, you can push the changes to your fork, by doing: ```sh