Skip to content

Commit df760e7

Browse files
Merge pull request #67 from sandstreamdev/add_isBoolean_method
Add is/boolean function
2 parents 0081fc8 + dee7285 commit df760e7

File tree

9 files changed

+131
-0
lines changed

9 files changed

+131
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,6 +2651,34 @@ array({ a: 1 });
26512651

26522652
- How to check if a given value is an array?
26532653

2654+
#### boolean
2655+
2656+
Checks if the given value is a boolean.
2657+
2658+
##### Type signature
2659+
2660+
<!-- prettier-ignore-start -->
2661+
```typescript
2662+
(x?: any) => boolean
2663+
```
2664+
<!-- prettier-ignore-end -->
2665+
2666+
##### Examples
2667+
2668+
<!-- prettier-ignore-start -->
2669+
```javascript
2670+
boolean(false); // ⇒ true
2671+
```
2672+
2673+
```javascript
2674+
boolean(1); // ⇒ false
2675+
```
2676+
<!-- prettier-ignore-end -->
2677+
2678+
##### Questions
2679+
2680+
- How to check if a given value is a boolean?
2681+
26542682
#### byte
26552683

26562684
Checks if the given value is a byte.

is/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ array({ a: 1 });
2828

2929
- How to check if a given value is an array?
3030

31+
# boolean
32+
33+
Checks if the given value is a boolean.
34+
35+
## Type signature
36+
37+
<!-- prettier-ignore-start -->
38+
```typescript
39+
(x?: any) => boolean
40+
```
41+
<!-- prettier-ignore-end -->
42+
43+
## Examples
44+
45+
<!-- prettier-ignore-start -->
46+
```javascript
47+
boolean(false); // ⇒ true
48+
```
49+
50+
```javascript
51+
boolean(1); // ⇒ false
52+
```
53+
<!-- prettier-ignore-end -->
54+
55+
## Questions
56+
57+
- How to check if a given value is a boolean?
58+
3159
# byte
3260

3361
Checks if the given value is a byte.

is/boolean.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default x => typeof x === "boolean";

is/boolean.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "boolean",
3+
"description": "Checks if the given value is a boolean.",
4+
"signature": "(x?: any) => boolean",
5+
"examples": [
6+
{
7+
"language": "javascript",
8+
"content": "boolean(false); // ⇒ true"
9+
},
10+
{
11+
"language": "javascript",
12+
"content": "boolean(1); // ⇒ false"
13+
}
14+
],
15+
"questions": ["How to check if a given value is a boolean?"]
16+
}

is/boolean.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# boolean
2+
3+
Checks if the given value is a boolean.
4+
5+
## Type signature
6+
7+
<!-- prettier-ignore-start -->
8+
```typescript
9+
(x?: any) => boolean
10+
```
11+
<!-- prettier-ignore-end -->
12+
13+
## Examples
14+
15+
<!-- prettier-ignore-start -->
16+
```javascript
17+
boolean(false); // ⇒ true
18+
```
19+
20+
```javascript
21+
boolean(1); // ⇒ false
22+
```
23+
<!-- prettier-ignore-end -->
24+
25+
## Questions
26+
27+
- How to check if a given value is a boolean?

is/boolean.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-env jest */
2+
// @ts-ignore ambiguous import
3+
import boolean from "./boolean";
4+
5+
describe("boolean", () => {
6+
it("checks if the given value is a boolean", () => {
7+
expect(boolean(true)).toBe(true);
8+
expect(boolean(false)).toBe(true);
9+
10+
expect(boolean("true")).toBe(false);
11+
expect(boolean("")).toBe(false);
12+
expect(boolean(undefined)).toBe(false);
13+
expect(boolean(null)).toBe(false);
14+
expect(boolean(0)).toBe(false);
15+
expect(boolean({})).toBe(false);
16+
expect(boolean([])).toBe(false);
17+
expect(boolean(NaN)).toBe(false);
18+
expect(boolean(() => {})).toBe(false);
19+
expect(boolean([1, 2, 3])).toBe(false);
20+
expect(boolean({ a: 1, b: 2, c: 3 })).toBe(false);
21+
expect(boolean(17.6)).toBe(false);
22+
expect(boolean(Math.min)).toBe(false);
23+
});
24+
});

is/boolean.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default (x?: any) => typeof x === "boolean";

is/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import array from "./array.js";
2+
import boolean from "./boolean.js";
23
import byte from "./byte.js";
34
import date from "./date.js";
45
import defined from "./defined.js";
@@ -12,6 +13,7 @@ import string from "./string.js";
1213

1314
export {
1415
array,
16+
boolean,
1517
byte,
1618
date,
1719
defined,
@@ -26,6 +28,7 @@ export {
2628

2729
export default {
2830
array,
31+
boolean,
2932
byte,
3033
date,
3134
defined,

is/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import array from "./array";
2+
import boolean from "./boolean";
23
import byte from "./byte";
34
import date from "./date";
45
import defined from "./defined";
@@ -12,6 +13,7 @@ import string from "./string";
1213

1314
export {
1415
array,
16+
boolean,
1517
byte,
1618
date,
1719
defined,
@@ -26,6 +28,7 @@ export {
2628

2729
export default {
2830
array,
31+
boolean,
2932
byte,
3033
date,
3134
defined,

0 commit comments

Comments
 (0)