Skip to content

Commit cbd7a12

Browse files
committed
update docs for utils
1 parent fadf0cc commit cbd7a12

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

docs/documentation/utilities/is-&-isnot.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const [status, setStatus] = state('pending')
1616
html`${when(is(status, 'pending'), html`<p>loading...</p>`, html`<p>done</p>`)}`
1717
```
1818

19-
Both the `is` and `isNot` take two arguments, a state or some data, and a value or a checker. They will always return a boolean as the result.
19+
Both the `is` and `isNot` take two arguments, a state or some data, and a value or a checker. They will always return a boolean as the result. The second argument is optional and when not provided, it will check if the value is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) or [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy)
2020

2121
### RegExp
2222

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@beforesemicolon/markup",
3-
"version": "1.17.4",
3+
"version": "1.18.0",
44
"description": "Reactive HTML Templating System",
55
"engines": {
66
"node": ">=18.16.0"

src/helpers/is-not.helper.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import {isNot} from "./is-not.helper.ts";
33
describe('isNot', () => { // @ts-ignore
44

55
it('should handle isNot', () => {
6+
expect(isNot(12)()).toBe(false)
7+
expect(isNot(0)()).toBe(true)
8+
expect(isNot(() => true)()).toBe(false)
69
expect(isNot(() => true, true)()).toBe(false)
710
expect(isNot(() => true, false)()).toBe(true)
811
expect(isNot(() => true, () => false)()).toBe(true)

src/helpers/is-not.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { is } from './is.helper.ts'
1313
export const isNot =
1414
<T>(
1515
st: T | StateGetter<T>,
16-
dataOrCheckerFn: HelperValueChecker<T> | AnythingButAFunction<T>
16+
dataOrCheckerFn?: HelperValueChecker<T> | AnythingButAFunction<T>
1717
) =>
1818
() =>
1919
!is(st, dataOrCheckerFn)()

src/helpers/is.helper.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import {is} from "./is.helper.ts";
33
describe('is', () => { // @ts-ignore
44

55
it('should handle is', () => {
6+
expect(is(12)()).toBe(true)
7+
expect(is(0)()).toBe(false)
8+
expect(is(() => true)()).toBe(true)
69
expect(is(() => true, true)()).toBe(true)
710
expect(is(() => true, false)()).toBe(false)
811
expect(is(() => true, () => false)()).toBe(false)

src/helpers/is.helper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { val } from './val.ts'
1313
export const is =
1414
<T>(
1515
st: T | StateGetter<T>,
16-
dataOrCheckerFn: HelperValueChecker<T> | AnythingButAFunction<T>
16+
dataOrCheckerFn?: HelperValueChecker<T> | AnythingButAFunction<T>
1717
) =>
1818
() => {
1919
const value = val<T>(st)
@@ -26,5 +26,9 @@ export const is =
2626
return dataOrCheckerFn.test(String(value))
2727
}
2828

29+
if (dataOrCheckerFn === undefined) {
30+
return Boolean(value)
31+
}
32+
2933
return value === dataOrCheckerFn
3034
}

0 commit comments

Comments
 (0)