Add isBoolean (#53)

This commit is contained in:
Jaco Greeff
2017-12-17 20:16:15 +01:00
committed by GitHub
parent 9b4070401a
commit e77d536edd
6 changed files with 69 additions and 9 deletions
+18
View File
@@ -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.
+3 -3
View File
@@ -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",
+17
View File
@@ -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';
};
+23
View File
@@ -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);
});
});
+2
View File
@@ -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,
+6 -6
View File
@@ -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"