-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implement randomBool() * test: add tests for randomBool() * chore: export boolean functions * docs: add random-bool page * docs: add boolean page directory * fix: add file extension to import for ESM support Co-authored-by: Alireza Safaierad <[email protected]> * fix: add file extension to import for ESM support Co-authored-by: Alireza Safaierad <[email protected]> * fix wrong import path to randomInt --------- Co-authored-by: Alireza Safaierad <[email protected]>
- Loading branch information
1 parent
c98a343
commit 0c6a933
Showing
8 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Boolean | ||
|
||
import meta from './boolean/_meta.json'; | ||
import { TOC } from '../components/TOC.tsx'; | ||
|
||
<TOC base="/boolean" meta={meta} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"random-bool": "randomBool" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# randomBool | ||
|
||
Generate a random boolean. (true or false) | ||
|
||
### Import | ||
|
||
```typescript copy | ||
import { randomBool } from '@fullstacksjs/toolbox'; | ||
``` | ||
|
||
### Signature | ||
|
||
```typescript copy | ||
function randomBool(): boolean {} | ||
``` | ||
|
||
### Examples | ||
|
||
```typescript copy | ||
randomBool() // true | false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { randomBool } from './randomBool.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { randomBool } from './randomBool'; | ||
|
||
describe('randomBool', () => { | ||
it('should return an boolean', () => { | ||
for (let i = 0; i < 100; i++) { | ||
const boolean = randomBool(); | ||
|
||
expect(boolean).toBeTypeOf('boolean'); | ||
} | ||
}); | ||
|
||
it('should select the first item', () => { | ||
let i = 0; | ||
|
||
// eslint-disable-next-line jest/no-conditional-in-test | ||
for (; i < 100; i++) if (randomBool()) break; | ||
|
||
expect(i).toBeLessThan(100); | ||
}); | ||
|
||
it('should select the last item', () => { | ||
let i = 0; | ||
|
||
// eslint-disable-next-line jest/no-conditional-in-test | ||
for (; i < 100; i++) if (!randomBool()) break; | ||
|
||
expect(i).toBeLessThan(100); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { randomInt } from '../number/randomInt.ts'; | ||
|
||
/** | ||
* Generate a random boolean. | ||
* | ||
* @returns {boolean} random boolean | ||
* | ||
* @example | ||
* | ||
* randomBool() // Returns true or false | ||
*/ | ||
export function randomBool(): boolean { | ||
return !!randomInt(0, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters