-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df3d063
commit 3e9f0b4
Showing
7 changed files
with
118 additions
and
30 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,7 @@ | ||
# logicNot | ||
|
||
## 0.0.1 | ||
|
||
### Patch Changes | ||
|
||
- [`24bff3d`](https://github.com/changeelog/react-hooks/commit/24bff3d24011de5955505c33d973989cc5786879#diff-df7ad740052307aebbbdde0d86acbb03b4a98ae5518d68b8620cc2a0796f4a54)- Introduced logicNot |
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,19 @@ | ||
# logicNot | ||
|
||
`NOT` conditions for refs | ||
|
||
Please refer to the [documentation](#) for more information. | ||
|
||
## Installation | ||
|
||
```bash | ||
npx changeelog/reactuse@latest add logicNot | ||
``` | ||
|
||
## Contribution | ||
|
||
Yes please! See the [contributing guidelines](#) for more details! | ||
|
||
## License | ||
|
||
This project is licensed under the terms of the [MIT License](/LICENSE) |
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,42 @@ | ||
import { logicNot } from '../logicNot' | ||
|
||
describe('logicNot', () => { | ||
test('should return false when input is true', () => { | ||
expect(logicNot(true)).toBe(false) | ||
}) | ||
|
||
test('should return true when input is false', () => { | ||
expect(logicNot(false)).toBe(true) | ||
}) | ||
|
||
test('should return false when getter returns true', () => { | ||
const getter = () => true | ||
expect(logicNot(getter)).toBe(false) | ||
}) | ||
|
||
test('should return true when getter returns false', () => { | ||
const getter = () => false | ||
expect(logicNot(getter)).toBe(true) | ||
}) | ||
|
||
test('should throw an error for non-boolean and non-function input', () => { | ||
const invalidInput = 123 | ||
expect(() => logicNot(invalidInput as any)).toThrow( | ||
'logicNot: Expected a boolean or a function that returns a boolean.' | ||
) | ||
}) | ||
|
||
test('should throw an error when function does not return a boolean', () => { | ||
const invalidGetter = () => 'hello' | ||
expect(() => logicNot(invalidGetter as any)).toThrow( | ||
'logicNot: Expected a boolean or a function that returns a boolean.' | ||
) | ||
}) | ||
|
||
test('should preserve the boolean type', () => { | ||
const result1: boolean = logicNot(true) | ||
const result2: boolean = logicNot(() => false) | ||
expect(result1).toBe(false) | ||
expect(result2).toBe(true) | ||
}) | ||
}) |
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 * from './logicNot' |
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,40 @@ | ||
import React, { useState } from 'react' | ||
import { logicNot } from './logicNot' | ||
|
||
const LogicNotDemo = () => { | ||
const [value, setValue] = useState(true) | ||
const [getterValue, setGetterValue] = useState(true) | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setValue(event.target.checked) | ||
} | ||
|
||
const handleGetterChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setGetterValue(event.target.checked) | ||
} | ||
|
||
const notValue = logicNot(value) | ||
const notGetterValue = logicNot(() => getterValue) | ||
|
||
return ( | ||
<div> | ||
<h1>Logic Not Demo</h1> | ||
<label> | ||
Input: | ||
<input type="checkbox" checked={value} onChange={handleChange} /> | ||
</label> | ||
<p>NOT: {notValue.toString()}</p> | ||
<label> | ||
Getter Input: | ||
<input | ||
type="checkbox" | ||
checked={getterValue} | ||
onChange={handleGetterChange} | ||
/> | ||
</label> | ||
<p>NOT Getter: {notGetterValue.toString()}</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default LogicNotDemo |
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 was deleted.
Oops, something went wrong.