Files
common/docs
..
2017-12-01 20:34:51 +01:00
2017-12-01 20:34:51 +01:00
2017-12-01 20:34:51 +01:00
2017-12-07 21:27:58 +01:00
2017-12-01 20:34:51 +01:00
2017-12-01 20:34:51 +01:00
2017-12-01 20:34:51 +01:00
2017-12-03 09:57:18 +00:00
2017-12-03 09:57:18 +00:00
2017-12-01 20:34:51 +01:00

Available interfaces

Utility methods for this package are split into groups

  • bn Utility methods to convert to and from BN objects
  • buffer Utility methods to convert to and from Buffer objects
  • ext Extensions to basic classes
  • hex Internal utilities to create and test for hex values
  • is Type checking utilities
  • jsonrpc Convenience functions for values from @polkadot/api-jsonrpc
  • keccak Create Keccak256 values as hex, string & buffer output
  • number Utility methods to convert to and from number values
  • u8a Utility methods to convert to and from Uint8Array objects

Available methods

assert

Checks for a valid test, if not ExtError is thrown.

assert (test: any, message: string | () => string, code: number = ExtError.CODES.ASSERT, data: any): void

Checks that test is a truthy value. If value is falsy (null, undefined, false, ...), it throws an ExtError with the supplied message and an optional code and data. When test passes, true is returned.

const assert = require('@polkadot/util/assert');

assert(true, 'True should be true'); // true returned
assert(false, 'False should not be true'); // ExtError thrown
assert(false, () => 'message'); // ExtError with 'message'

Logger

Creates a consistent log interface for messages

logger (type: string): Logger

Returns a Logger that has .log, .error and .warn methods. Loggins is done with a consistent prefix (type of logger, date) followed by the actual message uning the underlying console.

const l = require('@polkadot/util/logger')('test');

l.log('blah'); // <date>     TEST: blah