Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,34 @@ array({ a: 1 });

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

#### boolean

Checks if the given value is a boolean.

##### Type signature

<!-- prettier-ignore-start -->
```typescript
(x?: any) => boolean
```
<!-- prettier-ignore-end -->

##### Examples

<!-- prettier-ignore-start -->
```javascript
boolean(false); // ⇒ true
```

```javascript
boolean(1); // ⇒ false
```
<!-- prettier-ignore-end -->

##### Questions

- How to check if a given value is a boolean?

#### byte

Checks if the given value is a byte.
Expand Down
28 changes: 28 additions & 0 deletions is/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,34 @@ array({ a: 1 });

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

# boolean

Checks if the given value is a boolean.

## Type signature

<!-- prettier-ignore-start -->
```typescript
(x?: any) => boolean
```
<!-- prettier-ignore-end -->

## Examples

<!-- prettier-ignore-start -->
```javascript
boolean(false); // ⇒ true
```

```javascript
boolean(1); // ⇒ false
```
<!-- prettier-ignore-end -->

## Questions

- How to check if a given value is a boolean?

# byte

Checks if the given value is a byte.
Expand Down
1 change: 1 addition & 0 deletions is/boolean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default x => typeof x === "boolean";
16 changes: 16 additions & 0 deletions is/boolean.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "boolean",
"description": "Checks if the given value is a boolean.",
"signature": "(x?: any) => boolean",
"examples": [
{
"language": "javascript",
"content": "boolean(false); // ⇒ true"
},
{
"language": "javascript",
"content": "boolean(1); // ⇒ false"
}
],
"questions": ["How to check if a given value is a boolean?"]
}
27 changes: 27 additions & 0 deletions is/boolean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# boolean

Checks if the given value is a boolean.

## Type signature

<!-- prettier-ignore-start -->
```typescript
(x?: any) => boolean
```
<!-- prettier-ignore-end -->

## Examples

<!-- prettier-ignore-start -->
```javascript
boolean(false); // ⇒ true
```

```javascript
boolean(1); // ⇒ false
```
<!-- prettier-ignore-end -->

## Questions

- How to check if a given value is a boolean?
24 changes: 24 additions & 0 deletions is/boolean.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* eslint-env jest */
// @ts-ignore ambiguous import
import boolean from "./boolean";

describe("boolean", () => {
it("checks if the given value is a boolean", () => {
expect(boolean(true)).toBe(true);
expect(boolean(false)).toBe(true);

expect(boolean("true")).toBe(false);
expect(boolean("")).toBe(false);
expect(boolean(undefined)).toBe(false);
expect(boolean(null)).toBe(false);
expect(boolean(0)).toBe(false);
expect(boolean({})).toBe(false);
expect(boolean([])).toBe(false);
expect(boolean(NaN)).toBe(false);
expect(boolean(() => {})).toBe(false);
expect(boolean([1, 2, 3])).toBe(false);
expect(boolean({ a: 1, b: 2, c: 3 })).toBe(false);
expect(boolean(17.6)).toBe(false);
expect(boolean(Math.min)).toBe(false);
});
});
1 change: 1 addition & 0 deletions is/boolean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default (x?: any) => typeof x === "boolean";
3 changes: 3 additions & 0 deletions is/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import array from "./array.js";
import boolean from "./boolean.js";
import byte from "./byte.js";
import date from "./date.js";
import defined from "./defined.js";
Expand All @@ -12,6 +13,7 @@ import string from "./string.js";

export {
array,
boolean,
byte,
date,
defined,
Expand All @@ -26,6 +28,7 @@ export {

export default {
array,
boolean,
byte,
date,
defined,
Expand Down
3 changes: 3 additions & 0 deletions is/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import array from "./array";
import boolean from "./boolean";
import byte from "./byte";
import date from "./date";
import defined from "./defined";
Expand All @@ -12,6 +13,7 @@ import string from "./string";

export {
array,
boolean,
byte,
date,
defined,
Expand All @@ -26,6 +28,7 @@ export {

export default {
array,
boolean,
byte,
date,
defined,
Expand Down