Truthy test (#37)

* Truthy test

* Update dev
This commit is contained in:
Jaco Greeff
2017-12-02 10:31:51 +01:00
committed by GitHub
parent ecf29b56bb
commit d1eafd084c
3 changed files with 15 additions and 15 deletions
+2 -2
View File
@@ -29,8 +29,8 @@
"test": "jest --coverage src"
},
"devDependencies": {
"@polkadot/api-jsonrpc": "^0.5.5",
"@polkadot/dev": "^0.12.4"
"@polkadot/api-jsonrpc": "^0.5.9",
"@polkadot/dev": "^0.12.5"
},
"dependencies": {
"babel-runtime": "^6.26.0",
+7 -7
View File
@@ -8,17 +8,17 @@ const ExtError = require('./ext/error');
@signature assert (test: boolean, message: string, code: number = ExtError.CODES.ASSERT, data: any): void
@summary Checks for a valid test, if not ExtError is thrown.
@description
Checks that `test` is a true value. If value is `false` (or `false-ish`), it throws an ExtError with the supplied `message` and an optional `code` and `data`. When `test` passes, `true` is returned.
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.
@example
const assert = require('@polkadot/util/assert');
assert(true === true, 'True should be true'); // true returned
assert(false === true, 'False should not be true'); // ExtError thrown
assert(true, 'True should be true'); // true returned
assert(false, 'False should not be true'); // ExtError thrown
*/
module.exports = function assert (test: boolean, message: string, code: number = ExtError.CODES.ASSERT, data: any): boolean {
if (!test) {
throw new ExtError(message, code, data);
module.exports = function assert (test: any, message: string, code: number = ExtError.CODES.ASSERT, data: any): boolean {
if (test) {
return true;
}
return true;
throw new ExtError(message, code, data);
};
+6 -6
View File
@@ -54,15 +54,15 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"
"@polkadot/api-jsonrpc@^0.5.5":
version "0.5.5"
resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.5.5.tgz#004ed19c2c5585230c8ec77caee78b5f6d61e62a"
"@polkadot/api-jsonrpc@^0.5.9":
version "0.5.9"
resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.5.9.tgz#615311c4f7c73b95cb52e910250ecc712f695732"
dependencies:
babel-runtime "^6.26.0"
"@polkadot/dev@^0.12.4":
version "0.12.4"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.12.4.tgz#5ce16c17bc29cf92793900a4096c7cc76cf2a0ac"
"@polkadot/dev@^0.12.5":
version "0.12.5"
resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.12.5.tgz#695238baf1f7fb6368b2191ca7bfa432d3e779ae"
dependencies:
babel-cli "^6.26.0"
babel-core "^6.26.0"