diff --git a/docs/is.md b/docs/is.md index 4107bf721..a9d4dbbe8 100644 --- a/docs/is.md +++ b/docs/is.md @@ -3,6 +3,7 @@ Type checking utilities - [isBN](#isbn) Tests for a `BN` object instance. +- [isBoolean](#isboolean) Tests for a boolean value. - [isBuffer](#isbuffer) Tests for a `Buffer` object instance. - [isError](#iserror) Tests for a `Error` object instance. - [isFunction](#isfunction) Tests for a `function`. @@ -34,6 +35,23 @@ import { isBN } from '@polkadot/util'; console.log('isBN', isBN(new BN(1))); // => true ``` +## isBoolean + +Tests for a boolean value. + +```js +isBoolean (value: any): boolean +``` + + +Checks to see if the input value is a JavaScript boolean. + +```js +import { isBoolean } from '@polkadot/util'; + +isBoolean(false); // => true +``` + ## isBuffer Tests for a `Buffer` object instance. diff --git a/package.json b/package.json index a3747d73a..67e2f650c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@polkadot/util", - "version": "0.9.3", + "version": "0.10.0", "description": "A collection of useful utilities for @polkadot", "main": "index.js", "keywords": [ @@ -29,8 +29,8 @@ "test": "jest --coverage" }, "devDependencies": { - "@polkadot/api-jsonrpc": "^0.6.5", - "@polkadot/dev": "^0.13.4" + "@polkadot/api-jsonrpc": "^0.6.7", + "@polkadot/dev": "^0.13.5" }, "dependencies": { "babel-runtime": "^6.26.0", diff --git a/src/is/boolean.js b/src/is/boolean.js new file mode 100644 index 000000000..2394895c9 --- /dev/null +++ b/src/is/boolean.js @@ -0,0 +1,17 @@ +// ISC, Copyright 2017 Jaco Greeff +// @flow + +/** + @name isBoolean + @signature isBoolean (value: any): boolean + @summary Tests for a boolean value. + @description + Checks to see if the input value is a JavaScript boolean. + @example + import { isBoolean } from '@polkadot/util'; + + isBoolean(false); // => true +*/ +module.exports = function isBoolean (value: any): boolean { + return typeof value === 'boolean'; +}; diff --git a/src/is/boolean.spec.js b/src/is/boolean.spec.js new file mode 100644 index 000000000..b2098ba23 --- /dev/null +++ b/src/is/boolean.spec.js @@ -0,0 +1,23 @@ +// ISC, Copyright 2017 Jaco Greeff + +const { isBoolean } = require('./index'); + +describe('isBoolean', () => { + it('returns true on false', () => { + expect( + isBoolean(false) + ).toEqual(true); + }); + + it('returns true on true', () => { + expect( + isBoolean(true) + ).toEqual(true); + }); + + it('returns false on invalid booleans', () => { + expect( + isBoolean('notABool') + ).toEqual(false); + }); +}); diff --git a/src/is/index.js b/src/is/index.js index bf3ce7a62..f55359ec1 100644 --- a/src/is/index.js +++ b/src/is/index.js @@ -3,6 +3,7 @@ const isBN = require('./bn'); const isBuffer = require('./buffer'); +const isBoolean = require('./boolean'); const isError = require('./error'); const isFunction = require('./function'); const isHex = require('./hex'); @@ -20,6 +21,7 @@ const isUndefined = require('./undefined'); */ module.exports = { isBN, + isBoolean, isBuffer, isError, isFunction, diff --git a/yarn.lock b/yarn.lock index 6277cc14f..981a3f086 100644 --- a/yarn.lock +++ b/yarn.lock @@ -54,15 +54,15 @@ lodash "^4.2.0" to-fast-properties "^2.0.0" -"@polkadot/api-jsonrpc@^0.6.5": - version "0.6.5" - resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.6.5.tgz#fa78923847e17e0c50c431b1935478e226284e1d" +"@polkadot/api-jsonrpc@^0.6.7": + version "0.6.7" + resolved "https://registry.yarnpkg.com/@polkadot/api-jsonrpc/-/api-jsonrpc-0.6.7.tgz#5be45086d4c1d5f396bbd5cbcc17dcb8663f709b" dependencies: babel-runtime "^6.26.0" -"@polkadot/dev@^0.13.4": - version "0.13.4" - resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.13.4.tgz#beaa45da1655f8335b4a8294db3803f95cd3cc4e" +"@polkadot/dev@^0.13.5": + version "0.13.5" + resolved "https://registry.yarnpkg.com/@polkadot/dev/-/dev-0.13.5.tgz#01dc2e720d5f9a4133a944fb42ae44623cd02880" dependencies: babel-cli "^6.26.0" babel-core "^6.26.0"